Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Parsing

Status
Not open for further replies.

MikeSel

Programmer
Nov 15, 2001
8
GB
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
 
Look up the SubStr( ) command

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
 
Thanks Dave for your reply..

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..

 
Hi Mike,

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~
 
IF you are able to use:
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:Download the CrownBase source code !!
 
*** ActiveX Control Event ***
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
 
If it can be done in VB, it can probably be done easier in VFP! Of course, that's only my opinion. :)

Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top