June 02, 2024, 03:24:42 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


What's the difference

Started by RitchieF, September 30, 2013, 04:11:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RitchieF

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

LarryMc

this is what I get
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

September 30, 2013, 04:41:53 PM #2 Last Edit: September 30, 2013, 10:11:34 PM by billhsln
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
When all else fails, get a bigger hammer.

GWS

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



Tomorrow may be too late ..

RitchieF

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

billhsln

October 01, 2013, 04:56:10 AM #5 Last Edit: October 01, 2013, 04:58:10 AM by billhsln
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
When all else fails, get a bigger hammer.

RitchieF

QuoteDEF array[101]:FLOAT
changed to DEF array[101]:STRING

Quotearray[200-index]
changed to array[index-200]

and had success ;D

Thanks Bill

LarryMc

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


LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF

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


LarryMc

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.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library