cNeeds = cNeeds + DoubleToStr(dNeeds[i]) * to cNeeds = cNeeds + DoubleToStr(dNeeds[i] * 1.0)to make sure that's double.
>'------------------------------------------------------------ >' This is in a module file: module1.bas >'------------------------------------------------------------ >Public Declare Function LScreateEnvLng _ >Lib "LINGD80.DLL" () As Long >Public Declare Function LSsetPointerLng _ >Lib "LINGD80.DLL" (ByVal pLINGO As Long, ByRef dObject As Double, _ >ByRef nPointersNow As Long) As Long > >'------------------------------------------------------------ >' The following codes are in a click event of a form that accepts the values of dNeeds >'------------------------------------------------------------ >' Create the LINGO environment object >' Assume that the environment will be created successfully > Dim pLINGO As Long > pLINGO = LScreateEnvLng() > >dim dNeeds(7) as double >' sample value of dNeeds; this is entered through textboxes >' dNeeds(1)=2 >' dNeeds(2)=3 >' dNeeds(3)=1 >' dNeeds(4)=1 >' dNeeds(5)=2 >' dNeeds(6)=2 >' dNeeds(7)=2 > >Dim dStart(7) As Double > >' nPointersNow is not even defined! >' @POINTER(1) this is the receiving entity of the API > nError = LSsetPointerLng(pLINGO, dNeeds(1), nPointersNow) > If nError <> 0 Then GoTo ErrorExit > >' @POINTER(2) this is the receiving entity of the API > nError = LSsetPointerLng(pLINGO, dStart(1), nPointersNow) > If nError <> 0 Then GoTo ErrorExit > >' there is a script here to run the LINGO model >' nError does not return <> 0 (meaning successfully ran the model). > >' assign returned values to textboxes >' clean up codes > >ErrorExit: > ' clean up codes > >>
>*------------------------------------------------ >* LINGO API >*------------------------------------------------ >declare integer LScreateEnvLng in "c:\lingo8\lingd80.dll" >declare long LSsetPointerLng in "c:\lingo8\lingd80.dll" long, string @, integer @ > >*------------------------------------------------ >* conversion APIs: >*------------------------------------------------ >* converts double to number >declare RtlMoveMemory in WIN32API as ConvDoubleToNum ; > double @DestNumeric, ; > string @pVoidSource, ; > integer nLength >* converts double to string >declare RtlMoveMemory in WIN32API as ConvDoubleToStr ; > string @DestString, ; > double @pVoidSource, ; > integer nLength > >*------------------------------------------------ >* conversion API implementation: >*------------------------------------------------ >* converts double to string >function DoubleToNum > lparameter cDoubleInString > local nNum > nNum = 0.000000000000000000 > =ConvDoubleToNum(@nNum, cDoubleInString, 8) > return nNum >endfunc >function DoubleToStr > lparameter nDoubleToCopy > local cString > cString = space(8) > =ConvDoubleToStr(@cString, nDoubleToCopy, 8) > return cString >endfunc > >*------------------------------------------------ >* click event of my test form >*------------------------------------------------ >with thisform >* create the LINGO environment > .pLINGO = LScreateEnvLng() > if .pLINGO = 0 > messagebox('Unable to create environment') > return .f. > endif > local nError as long > private nPointersNow > nPointersNow = 0 > > * pointer 1; dNeeds array is the values of the textboxes of my test form > * assume that these data are properly assigned. > private cNeeds > cNeeds = '' > for i = 1 to 7 > cNeeds = cNeeds + DoubleToStr(dNeeds[i]) > endfor > * pointer 1; array to be passed to API > nError = LSsetPointerLng(.pLINGO, @cNeeds, @nPointersNow) > if nError <> 0 > set step on > endif > * pointer 2; array to be updated with values from API > dimension dStart[7] as double > dStart = 0.0 > private cStart > cStart = '' > for i = 1 to 7 > cStart = cStart + DoubleToStr(0.0) > endfor > nError = LSsetPointerLng(.pLINGO, @cStart, @nPointersNow) > if nError <> 0 > set step on > endif > * run the LINGO script here, returns <> 0 which means successful > * these values are not the same as the values returned in the VB sample > * by this magnitude > * VB=1 vs VFP=0.38E-300!!! > .text8.value=DoubleToNum(substr(cStart,1,8)) > .text9.value=DoubleToNum(substr(cStart,9,8)) > .text10.value=DoubleToNum(substr(cStart,17,8)) > .text11.value=DoubleToNum(substr(cStart,25,8)) > .text12.value=DoubleToNum(substr(cStart,33,8)) > .text13.value=DoubleToNum(substr(cStart,41,8)) > .text14.value=DoubleToNum(substr(cStart,49,8)) > >