String Parsing
String Parsing
(OP)
Hi All, I am a big Newbie both to Tek-Tips and FoxPro so be gentle!
Right, I have FoxPro 7.0, and I am reading a string of data consisting of both numbers and ascii charecter codes, from the COMM port.
I am reading the string using the MSCOMM controll. Then I am trying to split the string up like so.
The first number is the terminal ID which is easy to get:
RFTerminalID = Left(lnTermData,1)
But then the second is an ascii code. Which should be 2 charecters long.
But I don't know how to get both chars.
As obviously the above doesn't work.
I am a previous VB programmer and would use the MID() function. Which Fox doesn't seem to have.
Any help would be great!
Thanks
Right, I have FoxPro 7.0, and I am reading a string of data consisting of both numbers and ascii charecter codes, from the COMM port.
I am reading the string using the MSCOMM controll. Then I am trying to split the string up like so.
The first number is the terminal ID which is easy to get:
RFTerminalID = Left(lnTermData,1)
But then the second is an ascii code. Which should be 2 charecters long.
But I don't know how to get both chars.
As obviously the above doesn't work.
I am a previous VB programmer and would use the MID() function. Which Fox doesn't seem to have.
Any help would be great!
Thanks
RE: String Parsing
StartAt = 2
NumofChars = 2
lcPartOfString = SubStr(lnTermData , StartAt , NumOfChar)
or
lcPartOfString = SubStr(lnTermData , 4, 25)
for a substring starting at char 4 for a lenght of 25
David W. Grewe
Dave@internationalbid.com
RE: String Parsing
Unfortunatly I can't use substr as it isn't a string..
sorry if I was vague..
I just get 0 then three squares obviusly ascii codes..
RE: String Parsing
Can you post exactly what you're trying to parse? Is it just a 'string' of numbers or are characters mixed in? (maybe you're getting squares back because the font set you're using doesn't define those upper-ascii characters)? Do the ascii codes have a definite length or do they vary (ie- 100='d', does 99='c' or 099='c')? A couple functions to look at are
STR(); CHR(); VAL(); SUBSTR(); and maybe PADL().
I hope that helps, otherwise, come back for more!
-- michael~
RE: String Parsing
RFTerminalID = Left(lnTermData,1) then lnTermData must be a character string and you should be able to use all functions that manipulate character strings.
What error message do you get when you are using SUBSTR(), on your data ?
HTH,
Weedz (Wietze Veld)
My private project:www.crowncap.demon.nl\info\crwnbase
Download the CrownBase source code !!
RE: String Parsing
Local lnAsco, action, lnTermData, lnbitn ;
If This.inBufferCount > 0
lnTermData = This.input
IF ASC(RIGHT(lntermData,1)) = 13
lnasco = ASC(SUBSTR(lntermdata,2,1))
RFTerminalID = Left(lnTermData,1)
lnbitn = ASC(Substr(lnTermData,3,1))
thisform.text2.value = lntermdata
Use .\Data\dbfcomm
Select * From dbfcomm ;
WHERE rascii = lnAsco ;
INTO Cursor myquery
Select myquery
Thisform.text1.Value = Thisform.text1.Value + " " + myquery.Descriptio
action = myquery.Command
&action
Select dbfcomm
Use
Select myquery
USE
ENDIF
ENDIF
Seemz to work now....
Apart from the fact, I don't always recieve the full string. See it's a barcode reader. From Worthdata.com
Comes with some really good example VB apps. But boss wants it doing in stinky ol' foxpro
RE: String Parsing
Dave S.