Could someone please advise me on how to pass a structured variable to a function. It would seem that a structure can not be passed to a function directly. The documentation states that it cannot be passed to a procedure directly, unless I misunderstood. Most likely by a pointer?? I have tried several different ways which did not work.
Thanks
Ken
[/code]
*iError.w = 0
Structure Point2D
x.double
y.double
EndStructure
Dim StartLine.Point2D(1)
Dim EndLine.Point2D(1)
F64_Val(StartLine(0)\x,"0")
F64_Val(StartLine(0)\y,"0")
F64_Val(EndLine(0)\x,"100")
F64_Val(Endline(0)\y,"0")
;OpenConsole()
;PrintN(F64_Str(StartLine(0)\x, 15,#F64_Format_Decimal))
;PrintN(F64_Str(StartLine(0)\y, 15,#F64_Format_Decimal))
;PrintN(F64_Str(EndLine(0)\x, 15,#F64_Format_Decimal))
;PrintN(F64_Str(EndLine(0)\y, 15,#F64_Format_Decimal))
;Input()
;CloseConsole()
;How do I pass a structured type variable such as StartLine and Endline to
;the Function VCAddLineEntity.
OpenLibrary (0,"vcmain32.dll")
CallFunction (0,"VCAddLineEntity",@*iError,-1,StartLine,Endline)
CloseLibrary(0)
How to pass a structured variable to a function
Re: How to pass a structured variable to a function
If I'm not too tired (it's very early this morning
) I think your
problem lies somewhere else:
StartLine and EndLine are 0!
Instead, you'll want to pass your arrays:
or
problem lies somewhere else:
Code: Select all
Dim StartLine.Point2D(1)
Dim EndLine.Point2D(1)
CallFunction (0,"VCAddLineEntity",@*iError,-1,StartLine,Endline)
Instead, you'll want to pass your arrays:
Code: Select all
CallFunction (0,"VCAddLineEntity",@*iError,-1,StartLine(),Endline())
Code: Select all
CallFunction (0,"VCAddLineEntity",@*iError,-1,@StartLine(),@Endline())
Good programmers don't comment their code. It was hard to write, should be hard to read.
Re: How to pass a structured variable to a function
I don't know what documentation you are talking about but in PureBasic you can pass structures like this:CaddMan wrote:The documentation states that it cannot be passed to a procedure directly, unless I misunderstood.
Code: Select all
Structure MYSTRUC
x.f
y.f
EndStructure
Procedure YesYesBringItOn(*value.MYSTRUC)
Debug *value\x
Debug *value\y
EndProcedure
foo.MYSTRUC : foo\x = 0.521 : foo\y = 13.417
YesYesBringItOn(@foo)
Don't know if this helps...
Good programmers don't comment their code. It was hard to write, should be hard to read.
Thanks traumatic,
My problem is syntax. I am just learning how to program in PureBasic while trying to convert Visual Basic code into PureBasic code.
In VB I would have used Dim StartLine As Point2D then passed the array as StartLine. By using the function VCAddLineEntityBP (BP means By Pointer) and passing the arrays as @StartLine() for what its worth the code below works. Having to use the F64 Library to create double variables is also proving to be a challenge. There are several mouse functions that return info as a structured Point2D that I am trying to figure out how to assign to variables in PureBasic.
My problem is syntax. I am just learning how to program in PureBasic while trying to convert Visual Basic code into PureBasic code.
In VB I would have used Dim StartLine As Point2D then passed the array as StartLine. By using the function VCAddLineEntityBP (BP means By Pointer) and passing the arrays as @StartLine() for what its worth the code below works. Having to use the F64 Library to create double variables is also proving to be a challenge. There are several mouse functions that return info as a structured Point2D that I am trying to figure out how to assign to variables in PureBasic.
Code: Select all
iError.w = 0
GetState.w = 0
Toggle.w =0
lH.l=0
Structure Point2D
x.double
y.double
EndStructure
Dim StartLine.Point2D(1)
Dim EndLine.Point2D(1)
F64_Val(StartLine(0)\x,"0")
F64_Val(StartLine(0)\y,"0")
F64_Val(EndLine(0)\x,"10")
F64_Val(Endline(0)\y,"0")
OpenLibrary (0,"vcmain32.dll")
CallFunction (0,"VCAddLineEntityBP",@iError,-1,StartLine(),Endline())
CallFunction (0,"VCLastEntity",@iError,@lH)
CallFunction (0,"VCSetCurrentEntity", @iError,@lH)
CallFunction (0,"VCDrawCurrentEntity",@iError)
CloseLibrary(0)

