#Region "Header"
Imports System
Imports Microsoft.VisualBasic
Imports AmosEngineLib
Imports AmosEngineLib.AmosEngine
Imports AmosEngineLib.AmosEngine.TMatrixID
#End Region
Public Class CUserValue : Implements IUserValue
	
	' This example estimates a "dummy" estimand that is always equal to zero.
	' Estimating this dummy estimand has the side effect of writing the values of the "A" parameter and the "B" parameter together with their product
	' to a text file called bootstrapsamplevalues.txt in the My Documents folder.
	
	Dim file As IO.StreamWriter

	Function Value( groupNumber As Integer, bootstrapSampleNumber As Integer, v As CValue) As Object Implements IUserValue.Value
		If bootstrapSampleNumber > 0 Then
			' Do not write bootstrap sample values when bootstrapSampleNumber=0 because
			' bootstrapSampleNumber=0 for the original sample, not for a bootstrap sample.
			Dim a As Double = v.ParameterValue("A")
			Dim b As Double = v.ParameterValue("B")
			file.Write(bootstrapsamplenumber)
			file.Write(vbTab)
			file.Write(a)
			file.Write(vbTab)
			file.Write(b)
			file.Write(vbTab)
			file.WriteLine(a * b)
		End If
		Return 0		' Return an arbitrary value, because a value must be returned.
	End Function

#Region "Advanced"
	Function Label( groupNumber As Integer) As Object Implements IUserValue.Label
		' You can replace the following line.
		Return Nothing
	End Function

	Public Sub Initialize() Implements IUserValue.Initialize
		Dim filePath As String
		filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "bootstrapsamplevalues.txt")
		file = New IO.StreamWriter(filePath)
	End Sub

	Sub CleanUp() Implements IUserValue.CleanUp
		file.Close
	End Sub
#End Region
End Class
