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
INPUT and 255
I dont understand you question that well but....
here might be the code you're looking for...
or
hope this helps
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
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
Re: INPUT and 255
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.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
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
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)
Re: INPUT and 255
Well, the INPUT idea of Nixon would work.worky wrote:type in 255 characters at the QBasic prompt.
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
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.
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.