A simple chat programm

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

A simple chat programm

Post by mrminecrafttnt »

It's a simple chat for an windows share folder, have fun *g*

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
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: A simple chat programm

Post by Boromir »

mrminecrafttnt wrote:It's a simple chat for an windows share folder, have fun *g*
Nice! I use this same net method in a lot of my communication programs. It's so simple as opposed to using socket programming. It's too slow for certain things though.
Post Reply