FBChat

User projects written in or related to FreeBASIC.
mrminecrafttnt
Posts: 76
Joined: Feb 11, 2013 12:23

FBChat

Postby mrminecrafttnt » Oct 09, 2018 22:18

Hi there this is a very simple Chat programm for an shared folder.

Code: Select all

open "FBChat.dat" for binary as #1

sub write_msg(msg as string)
    dim as ushort length = len(msg)
    dim as ubyte buffer(length)
    for i as integer = 0 to length-1
        buffer(i)=msg[i]
    next
    put #1,1,length
    put #1,,buffer()
end sub

function read_msg as string
    dim as string msg
    dim as ushort length
    get #1,1,length
    dim as ubyte buffer(length)
    get #1,,buffer()
    msg = space(length)
    dim as integer count
    for i as integer = 0 to length-1
        msg[i]=buffer(i)
    next
    return msg
end function

sub msgprinter (msg as string)
    static as ubyte p,c
    c+=1
    c mod = 8
    p=18+c
    locate p,1
    print msg
end sub

sub writer
    dim as string username,Message
    do
        locate 2,1
        Input "Username : ",Username
    loop until Username <> ""
    do
        do
            locate 3,1
            sleep 10
        loop until csrlin = 3 and pos = 1
       
        Input "Message : ",Message
        Message = TIME +" "+ Username + " : "+ Message
        write_msg(Message)
        sleep 1,1
    loop
end sub

sub reader
    dim as string oldmessage,newmessage
    do
        newmessage = read_msg
        if newmessage <> oldmessage then
            oldmessage = newmessage
            msgprinter newmessage
        end if
        sleep 1,1
    loop
end sub


Print "FBChat 0.1"
threadcreate (@reader)
sleep 10
threadcreate (@writer)


do
    sleep 1
loop

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests