reading inividual letters

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

reading inividual letters

Post by sid6.7 »

a data(text) file was made like this

Code: Select all

gggggggggggggggggggg
gtgegvgZgggggggggggg
gggggggggggggggggggg
gagAgbgYgggggggggggg
gggggggggggggggggggg
gBgUgLgVggDggggggggg
gggggggggggggggggggg
gggggggggggggggggggg
for example i want to read each
letter and then count it on a counter...

but for some reason using plain INPUT nor GET
with TYPE/END TYPE doesnt read anything
what am i forgetting to read each individual letter?..
User avatar
Skyler
Coder
Posts: 16
Joined: Wed Jun 07, 2006 4:15 pm
Location: Delta Quadrant

Post by Skyler »

input a line, then:

Code: Select all

for x = 1 to len(line$)
   y$ = mid(line$, x, 1)
   'add y$ to counter here
next x
I think thats how to make mid select one char. if not, reverse x and 1 in mid$().
For God so loved the world he gave His only begotten Son that whosoever believeth on Him shall have everlasting life.
John 3:16
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

Reading one char at time from file like that might be a hard way. (correct me if im wrong).
I would first read one line at time to StringVariable.
Then DIM Array(LEN(StringVariable))

For Counter = 1 TO LEN(VariableA)
ArrayA(Counter) = MID$(VariableA,Counter,1)
Next Counter

If line, readed from file is IE "My line what i wana read", each cell from Array() gets one character from StringVariable.

Array(1) = "M"
Array(2) = "y"
Array(3) = " "
Array(4) = "l"
.
.
.
and so on.

Hopefully i understund your question correctly. Fix if i was wrong :wink:
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

Ok, skyler was bit faster on this one :lol:
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 »

thanks guys...i totally forgot mid$

DOH!
User avatar
Stoves
Veteran
Posts: 101
Joined: Fri Feb 10, 2006 12:24 am
Location: Nashville, TN

This might work.

Post by Stoves »

Code: Select all

DIM f AS INTEGER
DIM letter AS STRING * 1

f = FREEFILE

OPEN file$ FOR BINARY AS #f

  DO UNTIL EOF(f)

    GET #f, , letter

    'Count the letter

  LOOP

CLOSE #f
Post Reply