Tried the following code :
int counter
string c200,text$
c200 = "teststring"
messagebox 0,c200,"Correct"
counter = 200
text$ = "c"+ltrim$(str$(counter)) ' < why gives this line a different output than the next one ?? Though it creates 'c200' also
'text$ = c200 'this would be the correct output
messagebox 0,text$,"Wrong"
Thanks for any help
Richard
this is what I get
In one case you are moving "c"+ltrim$(str$(counter)) to variable text$, in the other you are moving the value that is in variable c200 to text$.
text$ = "c"+ltrim$(str$(counter)) gives: text$ = "c200"
text$ = c200 gives: text$ = "teststring", since variable c200 has a value of "teststring"
Bill
Yep, I agree ..
text$ = "c"+ltrim$(str$(counter))
is just a complicated way of writing:
text$ = "c200"
and it will print the string "c200"; not the contents of your variable c200.
There is another way .. ::)
def counter:int
def c200,text$:string
def pt:pointer
c200 = "teststring"
pt = c200 :' set a pointer to the variable c200
messagebox 0,c200,"Correct"
text$ = #pt :' load the contents of c200 into text$
messagebox 0,text$,"Another way"
Best wishes, :)
Graham
Thanks guys for the help !
For a better explanation :
I'm about writing a tool for my cnc work. I have a text file (CNC-code) with the cycle calls of the cnc control in the form Q#200 up to Q#300.
Parallel to this I have the string variables c200 up to c300 with the corresponding real text the control needs.
Now I'm parsing the pseudo cnc code and want to replace every Q#??? with the correspondiing c??? string.
So I used this complicated way of writing to get the c??? string :
For counter = 200 to 300
text$ = "c"+ltrim$(str$(counter))
next counter
But this does not work as I know by now.
Pointer seems to be the magic word !
For example the string c200 looks like this :
CYCL DEF 200 BOHREN:
Q200=2 ; SICHERHEITS-ABSTAND
Q201=-3,5 ; TIEFE
Q206=150 ; F TIEFENZUSTELLUNG
Q202=3,5 ; ZUSTELL-TIEFE
Q210=0 ; VERWEILZEIT OBEN
Q203=+0 ; KOORDINATE OBERFLAECHE
Q204=2 ; 2. SICHERHEITS-ABSTAND
Q211=0 ; VERWEILZEIT UNTEN
Thanks again
Richard
Maybe you should look into arrays. you only need 101, based on needing values from 200 to 300.
DEF array[101]:FLOAT
then reference the values as: array[200-index] where index is the xxx of Qxxx, if you want to use Q251 index would equal 251. Remember that arrays are zero based, so the first value is array[0], which would equal Q200 for you.
That would save you from having to create 101 Float variables individually.
Just a thought,
Bill
QuoteDEF array[101]:FLOAT
changed to DEF array[101]:STRING
Quotearray[200-index]
changed to array[index-200]
and had success ;D
Thanks Bill
Richard
I misread your original post which explains my non informative response.
IF the Qxxx are always at the start of the line then this will work without a counter and with only one pass through input file
FILE infile,outfile
STRING ln
int index
DEF array[101]:STRING
'load your array here before proceeding
IF(OPENFILE(outfile,"C:\\cnc.txt","W") = 0)
IF(OPENFILE(infile,"C:\\pseudo.txt","R") = 0)
WHILE EOF(infile) = 0
IF READ(infile, ln) = 0
If left$(ln)="Q"
index=val(mids$(ln,2,3))-200
ln=array(index)+mid$(ln,5)
endif
WRITE(outfile,ln)
ENDIF
ENDWHILE
CLOSEFILE infile
ENDIF
CLOSEFILE outfile
ENDIF
Thanks for the code, Larry.
But I need the replacement without open/save. The user would have to save and open his file after every adding or deleting a Q-definition in the cnc code.
If you'd like I could pm you my code which works in most parts when I'm back from work.
Richard
Quote from: RitchieF on October 02, 2013, 12:55:22 PM
Thanks for the code, Larry.
But I need the replacement without open/save. The user would have to save and open his file after every adding or deleting a Q-definition in the cnc code.
If you'd like I could pm you my code which works in most parts when I'm back from work.
Richard
Since I have some interest in cnc I'd be interested in seeing what you are doing. Email it to me.