🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Ross Hedvicek Fri, 29 Nov 1996 00:00
HELP!
#668
Author: Ross Hedvicek
Date: Fri, 29 Nov 1996 00:00
109 lines
3319 bytes
I have a BIG problem, I have to make a chat program that will display
the last 
*ten* quotes said by somebody, and erase the ones before that. It also
gives 
the user the ability to input a line of his own. I know how to do this
but my 
program keeps screwing up every time I run it. The first time I run
it, it 
displays the contents of CHAT.ATX but then along the way if the user
inputs a 
line of his own, the whole CHAT.ATX file is erased, how??? can anybody
figure 
this out?? HELP ME!!!!!!!!!!!!!

Ross Hedvicek Jr.

The messed up code:


start:
CLS
COLOR 7
LOCATE 6, 5: PRINT "C - Chat"
LOCATE 9, 5: PRINT "Q - Quit"
LOCATE 11, 4: PRINT "Your Choice?"
DO
do$ = INKEY$
LOOP WHILE do$ = ""
IF do$ = "C" OR do$ = "c" THEN GOTO startchat
IF do$ = "Q" OR do$ = "q" THEN END
GOTO start
'
'
'
startchat:
OPEN "CHAT.ATX" FOR INPUT AS #1
CLS : COLOR 4
FOR x = 1 TO EOF(1)
INPUT #1, name$, saywhat$
COLOR 7: PRINT name$; " babbled this:"
COLOR 4: PRINT saywhat$
IF EOF(1) THEN EXIT FOR
NEXT x
CLOSE #1
COLOR 7
PRINT
PRINT "Add anything? [Y/N]"
startq:
DO
IN$ = INKEY$
LOOP UNTIL NOT IN$ = ""
IF IN$ = "Y" OR IN$ = "y" THEN GOTO addchat
IF IN$ = "N" OR IN$ = "n" THEN GOTO start
GOTO startq
'
'
'
addchat:
PRINT "What do you want to add? (Max. length 70 characters)"
INPUT ; "", add$
add2chat$ = LEFT$(add$, 70)
COLOR 4: PRINT : PRINT "Are you sure you want to say:": PRINT
add2chat$
PRINT : PRINT "[Y/N]"
startdo:
DO
yn$ = INKEY$
LOOP WHILE yn$ = ""
IF yn$ = "Y" OR yn$ = "y" THEN GOTO add2chaty
IF yn$ = "N" OR yn$ = "n" THEN GOTO startchat
GOTO startdo
'
'
'
add2chaty:
RESET
OPEN "chat.atx" FOR INPUT AS #1
lines# = 0
DO
LINE INPUT #1, line$
lines# = lines# + 1
LOOP UNTIL EOF(1)
CLOSE #1
OPEN "CHAT.ATX" FOR INPUT AS #1
OPEN "CHAT.1" FOR OUTPUT AS #2
left# = lines# - 9
FOR x = 1 TO left#
LINE INPUT #1, skip$
NEXT x
FOR x = 1 TO EOF(1)
LINE INPUT #1, line$
WRITE #2, line$
NEXT x
WRITE #2, yourname$, add2chat$
CLOSE #1, #2
'
'
OPEN "CHAT.1" FOR INPUT AS #1
OPEN "CHAT.ATX" FOR OUTPUT AS #2
FOR x = 1 TO 10
LINE INPUT #1, line$
WRITE #2, line$
IF EOF(1) THEN EXIT FOR
NEXT x
CLOSE #2, #1
KILL "CHAT.1"
'
GOTO start
Re: HELP!
#666
Author: Timm Korte
Date: Mon, 02 Dec 1996 00:00
143 lines
4536 bytes


Ross Hedvicek <naafetee@cyberstreet.net> wrote in article
<329f48b5.747169@news.cyberstreet.com>...
> I have a BIG problem, I have to make a chat program that will display
> the last 
> *ten* quotes said by somebody, and erase the ones before that. It also
> gives 
> the user the ability to input a line of his own. I know how to do this
> but my 
> program keeps screwing up every time I run it. The first time I run
> it, it 
> displays the contents of CHAT.ATX but then along the way if the user
> inputs a 
> line of his own, the whole CHAT.ATX file is erased, how??? can anybody
> figure 
> this out?? HELP ME!!!!!!!!!!!!!
> 
> Ross Hedvicek Jr.
> 
> The messed up code:
> 
> 
> start:
> CLS
> COLOR 7
> LOCATE 6, 5: PRINT "C - Chat"
> LOCATE 9, 5: PRINT "Q - Quit"
> LOCATE 11, 4: PRINT "Your Choice?"
> DO
> do$ = INKEY$
> LOOP WHILE do$ = ""
> IF do$ = "C" OR do$ = "c" THEN GOTO startchat
> IF do$ = "Q" OR do$ = "q" THEN END
> GOTO start
> '
> '
> '
> startchat:
> OPEN "CHAT.ATX" FOR INPUT AS #1
> CLS : COLOR 4
---- I think, this is messed up:
> FOR x = 1 TO EOF(1)
INPUT #1, name$, saywhat$
> COLOR 7: PRINT name$; " babbled this:"
> COLOR 4: PRINT saywhat$
> IF EOF(1) THEN EXIT FOR
> NEXT x
------------- try this insted (didn't test it) ---------
DO
COLOR 7: PRINT name$; "..."
COLOR 4: PRINT saywhat$
LOOP UNTIL EOF(1)
---------------------------------------------------------------
> CLOSE #1
> COLOR 7
> PRINT
> PRINT "Add anything? [Y/N]"
> startq:
> DO
> IN$ = INKEY$
> LOOP UNTIL NOT IN$ = ""
> IF IN$ = "Y" OR IN$ = "y" THEN GOTO addchat
> IF IN$ = "N" OR IN$ = "n" THEN GOTO start
> GOTO startq
> '
> '
> '
> addchat:
> PRINT "What do you want to add? (Max. length 70 characters)"
> INPUT ; "", add$
> add2chat$ = LEFT$(add$, 70)
> COLOR 4: PRINT : PRINT "Are you sure you want to say:": PRINT
> add2chat$
> PRINT : PRINT "[Y/N]"
> startdo:
> DO
> yn$ = INKEY$
> LOOP WHILE yn$ = ""
> IF yn$ = "Y" OR yn$ = "y" THEN GOTO add2chaty
> IF yn$ = "N" OR yn$ = "n" THEN GOTO startchat
> GOTO startdo
> '
> '
> '
> add2chaty:
> RESET
> OPEN "chat.atx" FOR INPUT AS #1
> lines# = 0
> DO
> LINE INPUT #1, line$
> lines# = lines# + 1
> LOOP UNTIL EOF(1)
> CLOSE #1
> OPEN "CHAT.ATX" FOR INPUT AS #1
> OPEN "CHAT.1" FOR OUTPUT AS #2
> left# = lines# - 9
> FOR x = 1 TO left#
> LINE INPUT #1, skip$
> NEXT x
> FOR x = 1 TO EOF(1)
> LINE INPUT #1, line$
> WRITE #2, line$
> NEXT x
> WRITE #2, yourname$, add2chat$
> CLOSE #1, #2
> '
> '
> OPEN "CHAT.1" FOR INPUT AS #1
> OPEN "CHAT.ATX" FOR OUTPUT AS #2
> FOR x = 1 TO 10
> LINE INPUT #1, line$
> WRITE #2, line$
> IF EOF(1) THEN EXIT FOR
> NEXT x
> CLOSE #2, #1
> KILL "CHAT.1"
> '
> GOTO start
> 
> 
I didn't check the rest of your prog, but i think the marked section is
your problem.
Why?
Your first statement there is:
FOR x = 1 TO EOF(1)
              ^^^^^^^^^^^^^^^^
              When the compiler gets to this, he checks for EOF(1), which
is 0
              (you are at the beginning at your file)
That gives: 
FOR x = 1 TO 0
since there is nothing to count up from 1 to 0, the compiler skips the
whole
For - Next Loop - and doesn't print anything...
Just tyr the DO - LOOP loop that i wrote down... should work :)

So Long
   bye      
      VoYaGe (Timm)

--- bigbird@psln.com ----
Re: HELP!
#667
Author: Deekoo L.
Date: Mon, 02 Dec 1996 00:00
96 lines
3975 bytes
In article <329f48b5.747169@news.cyberstreet.com>, naafetee@cyberstreet.net
(Ross Hedvicek) wrote:

> I have a BIG problem, I have to make a chat program that will display
> the last 
> *ten* quotes said by somebody, and erase the ones before that. It also
> gives 
> the user the ability to input a line of his own. I know how to do this
> but my 
> program keeps screwing up every time I run it. The first time I run
> it, it 
> displays the contents of CHAT.ATX but then along the way if the user
> inputs a 
> line of his own, the whole CHAT.ATX file is erased, how??? can anybody
> figure 
> this out?? HELP ME!!!!!!!!!!!!!

--------------
Offending code:

> add2chaty:
> RESET
> OPEN "chat.atx" FOR INPUT AS #1
> lines# = 0
> DO
> LINE INPUT #1, line$
> lines# = lines# + 1
> LOOP UNTIL EOF(1)
> CLOSE #1
> OPEN "CHAT.ATX" FOR INPUT AS #1
> OPEN "CHAT.1" FOR OUTPUT AS #2
> left# = lines# - 9
> FOR x = 1 TO left#
> LINE INPUT #1, skip$
> NEXT x
> FOR x = 1 TO EOF(1)
> LINE INPUT #1, line$
> WRITE #2, line$
> NEXT x
> WRITE #2, yourname$, add2chat$
> CLOSE #1, #2
> '
> '
> OPEN "CHAT.1" FOR INPUT AS #1
> OPEN "CHAT.ATX" FOR OUTPUT AS #2
> FOR x = 1 TO 10
> LINE INPUT #1, line$
> WRITE #2, line$
> IF EOF(1) THEN EXIT FOR
> NEXT x
> CLOSE #2, #1
> KILL "CHAT.1"
> '
> GOTO start

Try renaming the "line$", "lines#", and "left#" variables.
LINE and LEFT are both reserved words - they do specific things in Basic.
(Line is used in the LINE INPUT statement, and LEFT is found in LEFT$().).
Every version of Basic I've used hiccups to some degree when one tries to use
reserved words in variablenames...  (The worst instance I ran into was
QuickBasic - I named an array Exits$, and Quickbasic refused to quit until
I
renamed the array.)

I was inspired (And bored), so I made a somewhat simpler chat core in APBasic:

OPEN "I",1,"CHAT.ATX"
DIM lin$(10)
FOR x%=1 TO 10
 LINE INPUT #1,lin$(x%)
 PRINT lin$(x%)
NEXT x%
PRINT "Do you want to say something? (y/N)"
WHILE INSTAT=0
WEND
ink$=UCASE$(INKEY$)
IF ink$="Y" THEN
 INPUT "What's your name? ",name$
 INPUT "Speak! ",speak$
 CLOSE 1
 OPEN "O",1,"CHAT.ATX"
 FOR x%= 2 TO 10
  PRINT #1,lin$(x%)
 NEXT x%
 PRINT #1,names$+": "+speak$
END IF

-- 
-------------------------------------++------------------------------
demi monde :: aka :: monde kontrolle || please suspend your disbelief
monde@sirius.com ::::::::::::::::::::|| :: at the door... :::::::::::
the compound eye BBS: 415.333.5665 ::|| :: violators will be violated
-------------------------------------++------------------------------
::::::::::: defenestration: http://www.sirius.com/~monde ::::::::::::
---------------------------------------------------------------------
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads