Send ascii string as parameter?
T Chap
Posts: 4,223
If there a way short of using dat to send a string as parameter?
Example is:
PUB X
OpenFile("myfile20")
PUB OpenFile(filename)
ser.str(filename)
The filename may change, so some ability to construct it from scratch is the idea, otherwise fixed dat values as strings would work.
MY guess is that you'd convert the ascii values to hex values, plug them in an array, let the routine find delimiter and send the array:
Array[noparse][[/noparse] 0] := 'ascii m
Array[noparse][[/noparse] 1] := 'ascii y
Array[noparse][[/noparse] 2] := 'ascii f
Array[noparse][[/noparse] 3] := 'ascii i
Array[noparse][[/noparse] 4] := 'ascii l
Array[noparse][[/noparse] 5] := 'ascii e
Array[noparse][[/noparse] 6] := 'ascii 2
Array[noparse][[/noparse] 7] := 'ascii 0
Array[noparse][[/noparse] 8] := 'ascii CR
PUB X
OpenFile(@array)
Thanks for any tips.
Post Edited (TChapman) : 11/27/2008 9:25:41 PM GMT
Example is:
PUB X
OpenFile("myfile20")
PUB OpenFile(filename)
ser.str(filename)
The filename may change, so some ability to construct it from scratch is the idea, otherwise fixed dat values as strings would work.
MY guess is that you'd convert the ascii values to hex values, plug them in an array, let the routine find delimiter and send the array:
Array[noparse][[/noparse] 0] := 'ascii m
Array[noparse][[/noparse] 1] := 'ascii y
Array[noparse][[/noparse] 2] := 'ascii f
Array[noparse][[/noparse] 3] := 'ascii i
Array[noparse][[/noparse] 4] := 'ascii l
Array[noparse][[/noparse] 5] := 'ascii e
Array[noparse][[/noparse] 6] := 'ascii 2
Array[noparse][[/noparse] 7] := 'ascii 0
Array[noparse][[/noparse] 8] := 'ascii CR
PUB X
OpenFile(@array)
Thanks for any tips.
Post Edited (TChapman) : 11/27/2008 9:25:41 PM GMT
Comments
If you want the string to be in a VAR area, you'd declare 'var byte name[noparse][[/noparse]9]' and use 'OpenFile(@name)'
If you want the string to be in a DAT area and be initialized to some value, you'd have
and then you'd write 'OpenFile(@name)'
If you want to initialize a VAR area to some constant value, you could use 'bytemove(@name,string("myfile20"),9)'
Note that the length is one greater than the number of characters in the string to include the terminating zero byte.
Maybe I was tired, but I spent two hours last night trying to send a variable array as a parameter.
It is easy to just use the variable on the ther end itself, but in cases of reusing the method, it would be great to know how to do this:
Not using objects, all within one program(cog).
This was not working to send array as parameter:
What am I missing here?
Edit:
Scanning the manual, I see one possible solution, but I suspect there is a simpler way.
Use bytemove to copy the variable you want to "send", but in this case you don't send anything, just park a temp variable in the receiver, and move the contents to that variable when needed.
Or write to to DAT location as an alternative:
Update2:
OK, this solves it:
I see that you must pass a reference to the var.
Post Edited (TChapman) : 11/28/2008 10:00:22 PM GMT