
18 Appendix A1 Extending Ox
• The first command changes the random number generator,which requires passing
a string, and gets a random number.
• The second passes the text of the first edit field (the random number) to
DLogGamma (the argument is automatically passed as a double here), and puts
the result in the second edit field.
• Button three is more complex. It creates a Basic array of doubles. Then allocates
an Ox MATRIX of which the address is stored in pmat. The Basic array is copied
to the 2 × 2 Ox matrix by row. This is inverted using the Ox function IInvert,
and the outcome put back into the Basic array. The Ox matrix is freed to prevent
a memory leak. In this way all Ox matrix functions can be used, but:
Care is required when using pointers. A mistake will not only crash
your program, but take VB down as well. So save your work before
testing your code.
• The last command shows that VB arrays of doubles are compatible with Ox
VECTORs. The array is passed by specifying the first element Vec(0),which
actually will pass a pointer to the array.
A1.6.2 The RanApp example in Visual Basic
The structure of the VB program is very similar to that in §A1.5:
.........................................ox/dev/windows/vb/RanApp.frm (part of)
Private Sub Form_Initialize()
Dim Res As Integer
Res = FOxGiveWinStart("RanApp", "RanApp", False)
Res = FOxLibAddFunction("ccc$GetRanAppSettings", _
AddressOf FnGetRanAppSettings, 0)
’ may need to set explicit path to ranapp.ox
giMainIP = OxMainCmd("-r- ranapp.ox")
Draw.Enabled = False
Variance.Enabled = False
If (Res = 0 Or giMainIP <= 0) Then
Generate.Enabled = False
Dimension.Enabled = False
End If
End Sub
Private Sub Form_Terminate()
Call OxGiveWinFinish(True)
End Sub
Private Sub Draw_Click()
Dim Res As Integer
Res = FOxRun(giMainIP, "OnDraw")
End Sub
Komentarze do niniejszej Instrukcji