Code: Select all
ON ERROR GOTO ERRORHANDLER
locate ,,0
width 80,20
sub write_message(message as string)
open "simplechat.msg" for output as #2
print #2,message
close #2
end sub
function read_message as string
dim as string message
if open ("simplechat.msg" for input as #1) = 2 then write_message "No message here." : exit function
input #1,message
close #1
return message
end function
sub threaded_message_reader
dim as string omsg
dim as string msg
dim as integer old_csrlin = csrlin,old_pos = pos,nline
locate ,,0
do
omsg = msg
do
msg = read_message
sleep 15
loop until msg <> omsg
if msg <> omsg then
old_csrlin = csrlin
old_pos = pos
nline+=1
nline = nline mod 5
locate nline+3,1
print msg & space (80-len(msg))
locate old_csrlin,old_pos
end if
sleep 1
loop
end sub
threadcall threaded_message_reader
dim as string username
locate 1
input "USERNAME :";username
do
dim as string umsg
locate 1
print "(enter !exit to left the programm)"
input "YOUR MESSAGE :";umsg
locate 2
print space(80)
select case umsg
case "!exit"
exit do
end select
if umsg <> "" then write_message(username & ": " & umsg)
loop
end
errorhandler:
print "ERROR ";ERR;ERL
sleep
end