forums

TNT Basic Forums > Programming Q&A
Having trouble using ascii to char.
< Last Thread     Next Thread >
Author
Thread        Post A Reply

10-21-2006 10:56

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

for i=0 to String Length(scenariofile) 'counting number of lines
if mid str(scenariofile,i,1)=Ascii to char (13)
h=h+1
end if
next i


In this code, I am trying to count the number of lines by measuring how many carriage returns there are... but it never finds any... I am pretty sure carriage returns ascii code is 13.

10-21-2006 11:20

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

It works for other letters, however , eg. "e" and ";"...

But it gets messy if I try to use ";" to denote the end of a line, however....

10-21-2006 12:42

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Don't convert it...

You don't need to try and cast it to a char. Just check the ASCII:

if mid str(scenariofile,i,1)=13

should do the trick.

Danny (nods)

10-21-2006 22:20

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

>>Should do the trick.

It didnt... :(

10-22-2006 00:35

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

OK, try this...

Try

tempString=Get Char(scenariofile, i) 'to get the character you're looking at...
tempASCII=Char to Asc(tempString)

if tempASCII=13 then h=h+1


No idea why the other way doesn't work. this one is more long winded but should give you the right results...

Danny (nods)

10-22-2006 05:53

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

:( That doesn't work either...

It can't recognise chr (13) s.... I have no idea why.

10-22-2006 05:56

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

101 (the character e) works, but 13(carriage return) or 10 (linefeed) both fail.

10-22-2006 05:58

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

After tweaking a little, I found out that "File read string" stopped reading after the first line....

Thats the problem we are looking at.

10-22-2006 15:57

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

"After tweaking a little, I found out that "File read string" stopped reading after the first line...."

i believe it's normal.. i think the comand read the file line by line

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.