INPUT and 255

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
worky
Newbie
Posts: 3
Joined: Wed Aug 22, 2007 11:39 am

INPUT and 255

Post by worky » Wed Aug 22, 2007 11:57 am

The following code works fine for getting text$ to equal what I want:

OPEN "text.txt" FOR INPUT AS #1
INPUT #1, text$
CLOSE #1

But, I don't want to edit TEXT.TXT with Notepad anymore. However, using:

INPUT text$

only allows me to type in 255 characters at the QBasic prompt. What am I doing wrong? Using QBX 7.1. Thanks

Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid » Wed Aug 22, 2007 1:05 pm

I dont understand you question that well but....

here might be the code you're looking for...

Code: Select all

CLS
OPEN "test.txt" FOR APPEND AS #1 ' this does it so it doesnt overwrite text already in it...
WRITE #1, test$  'this records the variable in the text file
CLOSE #1  'this closes it
or

Code: Select all


OPEN "text.txt" FOR APPEND AS #1 'still same as above
PRINT #1, "$$$"  'REMEMBER the " 's!" this acts like normal PRINT and will print the stuff in the sentence in the file
'or
INPUT #1, "I am god, are you?", variable$ 'acts like normal INPUT does same as above
CLOSE #1
hope this helps

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: INPUT and 255

Post by moneo » Wed Aug 22, 2007 5:40 pm

worky wrote:The following code works fine for getting text$ to equal what I want:

OPEN "text.txt" FOR INPUT AS #1
INPUT #1, text$
CLOSE #1

But, I don't want to edit TEXT.TXT with Notepad anymore. However, using:

INPUT text$

only allows me to type in 255 characters at the QBasic prompt. What am I doing wrong? Using QBX 7.1. Thanks
You're right, using QuickBasic 4.5 compiled or QBasic 4.5 interpreted, both the INPUT and LINE INPUT statements will restrict input from the keyboard to 255 characters.

I've been programming different versions of Basic for over 30 years, and have never needed to input more than 255 characters from the keyboard.

Why are you entering that many characters?

If you really have to, I suggest breaking the input string into smaller then 255 character parts, and entering it in pieces with multiple INPUT statements.

Good luck..... Moneo

Anonymous

Post by Anonymous » Wed Aug 22, 2007 5:45 pm

Are you trying to make your own editor? If so you probably will want to use inkey$ instead of input. Heres some sample code to look at, it should work. If this isn't what you mean please tell us exactly what you are trying to do, otherwise we can't really help you.

Code: Select all

width 80, 50

dim shared document$(255)

LineNum = 1

do
    if P$ = chr$(13) then
        locate LineNum,1
        color 7
        print document$(LineNum) + " " 
        LineNum = LineNum + 1
    elseif P$ = "+" and LineNum <49> 1 then
        locate LineNum,1
        color 7
        print document$(LineNum) + " " 
        LineNum = LineNum - 1
        
        locate LineNum,1
        color 15
        print document$(LineNum) + " " 
    elseif P$ = chr$(8) then
        document$(LineNum) = mid$(document$(LineNum),1,len(document$(LineNum))-1)
        locate LineNum,1
        color 15
        print document$(LineNum) + " "            
    else
        if len(document$(LineNum)) = 78 then
            locate LineNum,1
            color 7
            print document$(LineNum) + " " 
            LineNum = LineNum + 1
        end if
        document$(LineNum) = document$(LineNum) + P$
        locate LineNum,1
        color 15
        print document$(LineNum) + "_"
    end if
    P$ = inkey$
loop until P$ = chr$(27)

worky
Newbie
Posts: 3
Joined: Wed Aug 22, 2007 11:39 am

Post by worky » Wed Aug 22, 2007 7:52 pm

I was hoping there was some way to use INPUT or some other statement to enter more then 255 characters inside the Basic program. But I guess there isn't any simple way. I will just continue using Windows Notepad so I can go over the 255 limit. Thanks for the help.

Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Re: INPUT and 255

Post by Mac » Thu Aug 23, 2007 9:08 am

worky wrote:type in 255 characters at the QBasic prompt.
Well, the INPUT idea of Nixon would work.

But it would REALLY be nice of you to answer Moneo's question: Why do you need to enter so much? What kind of data are you entering?

a) It could be we could come up with a bright idea
b) It would satisfy our curiousity.

Mac

P.S. If you simply wanted to enter long lines, I guess you could do this:

Code: Select all

DECLARE FUNCTION InputLong$ ()
CLS
DO
  PRINT : PRINT "Enter a line of data (or just press Enter to stop)"
  k$ = InputLong
  PRINT : PRINT "Length of input:"; STR$(LEN(k$)), "Here is the line:"
  PRINT k$
LOOP WHILE k$ <> ""
SYSTEM

FUNCTION InputLong$
DIM w AS STRING
DO
  LINE INPUT ""; l$: w = w + l$
  IF LEN(l$) < 255 THEN InputLong$ = w: EXIT FUNCTION
LOOP
END FUNCTION

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Thu Aug 23, 2007 9:06 pm

Hey, Mac, your Inputlong$ function is pretty slick.

When it stops accepting input at 255 characters, you just hit enter, and then continue entering the rest of your long line.

Works fine.

Regards..... Moneo

worky
Newbie
Posts: 3
Joined: Wed Aug 22, 2007 11:39 am

Post by worky » Sun Aug 26, 2007 4:51 pm

Sorry everybody, I should have been more clear in my original message that entering data in 255 character chunks wouldn't work. This problem was brought to me from another dept. where I work at and all I know is the QBasic program is some quality control / maintenance program. They were getting by OK editing TEXT.TXT directly when the string was larger then 255 characters but then they would have to stop and start the program after the edit. They were using more long strings lately so the stopping and starting was getting annoying. What I did for them was get rid of the line:

LINE INPUT text$

And replaced it with:

SHELL "notepad text.txt"
OPEN "text.txt" FOR INPUT AS #1
LINE INPUT #1, text$
CLOSE #1

The QBasic program kindly pauses until Notepad is closed. They were happy with that and went on their way. It?s kind of a hokey fix, but easy. Why the ridiculously long strings? I didn?t ask and probably won?t.

Post Reply