Page 1 of 1

INPUT and 255

Posted: Wed Aug 22, 2007 11:57 am
by worky
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

Posted: Wed Aug 22, 2007 1:05 pm
by Sinuvoid
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

Re: INPUT and 255

Posted: Wed Aug 22, 2007 5:40 pm
by moneo
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

Posted: Wed Aug 22, 2007 5:45 pm
by Anonymous
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)

Posted: Wed Aug 22, 2007 7:52 pm
by worky
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.

Re: INPUT and 255

Posted: Thu Aug 23, 2007 9:08 am
by Mac
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

Posted: Thu Aug 23, 2007 9:06 pm
by moneo
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

Posted: Sun Aug 26, 2007 4:51 pm
by worky
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.