Tips & Trix
Make a LAN Chat program

Home
PUBz
Grafx Pax
Tips & Trix
Neo-Linx
Neo-Talk
NeoDezign-Filez
Search NeoDezign
 
 
 

 


FileRead... FileWrite... 

By using these two simple commands you can create a chat client that will operate on any Local Area Network. 

However, if you happen to see blue smoke rolling out of the back of your fileserver... then you can pretty well bet this chat program probably will not work. You see, the smoke is the "magic blue smoke" that is in all our computers. It is the what keeps them working. Once you let loose the magic blue smoke, most often, things stop working. See? You learned something today!

This example is just that, an example. Your chat program might end up looking totally different than this example. That's great! Chances are, though, the concept will be the same. Hmm... unless, of course, someone comes up with an AddOn that does PPTP on the net... (hint-hint)

The chat client program you create will be used by two or more people on a network to write to and read from a text file that exists on the fileserver. A large text entry object displays the chat text. A smaller text entry object will be used to type in what you want to say and, beside it, a button that writes your chit-chat to the text file on the server. The chat proggy will, in turn, read the chat text file and display it's contents in the large text entry box. 

Something to keep in mind while you write your chat proggy is that sometimes network users in different departments have mappings to the same folder but the drive letter and path might be different. For example, George and Nancy both work for CompanyX and share the same fileserver. George in Sales might have a mapping of "F:\OfcApps\" but Nancy in Accounting might have "H:\CompX\OfcApps".  Keep your chat program "open-minded" and assume nothing will be the same for each chat user.

Again, keep in mind, this example is only intended to describe the concept of how to create a LAN chat program of your own. Although the example does in fact work, the actual coding is really up to you. Using your imagination and inginuity you'll come up with ways to add all sorts of bells and whistles!


 

Getting Started : Create the following pages
  • Intro
  • Start
  • Setup Paths
  • Login
  • Chat

First, your chat program will need to learn where to read and write from. In the Page Action of the "Intro" page FileRead a local data file that will reside in the same folder with your chat program. We'll call this data file chat.ini

INTRO Page
Enter the following commands into the "Intro" Page Actions

./// the 1st time the program is run chat.ini will not exist
./// so error trap this event and send the user to Setup
FileExists "[PubDir]chat.ini" "[iniexist]"
  If "[iniexist]" "=" "False" 
    AlertBox "Chat" "File not found : chat.ini |Please enter paths in setup"
    GotoPage "Setup Paths"
  Else
./// chat.ini found so read from it to learn the location of chat.dat
    FileRead "chat.ini" "1" "chat_dat"
./// check to see if chat.dat is located in the path specified
./// if chat.dat not found send user to Setup
    FileExists "[chat_dat]" "[datexist]"
      If "[datexist]" "=" "False"
        AlertBox "Chat" "File not found : chat.dat|Please enter paths in setup"
        GotoPage "Setup Paths"
      EndIf
  EndIf
GotoPage "Start"
 
 

START Page
The "Start" page gives the user the option to Login or Setup Paths.

  • Create two Option Buttons
    • Login
      • Variable: [go_there]
    • Setup Paths
      • Variable: [go_there]
  • Draw two buttons
    • Go
      • Button Action:GotoPage "[go_there]"
    • Exit
      • Button Action: Exit "" ""


SETUP PATHS Page
On the "Setup Paths" page create a dialog that asks the user for the path to the chat.dat file that will live in a folder on the fileserver. 

  • The text edit box is contained in a variable called [chat_dat]
  • The "..." button launches an AddOn program using a FileOpen dialog to allow the user to browse drives to locate chat.dat. Store the results in the variable name: [chat_dat]

  •  
      (use the correct syntax for your preffered AddOn)
      ExecuteAddOn "[PubDir]external.exe" "'FileOpenDialog' 'Find Chat.dat' 'Chat.dat|chat.dat'"
      SetVar "[chat_dat]" "[FileOpenDialog]"
  • The Savebutton writes the [chat_dat] variable to the chat.ini file.
    ./// write the full path and filename of chat.dat
    FileWrite "chat.ini" "1" "[chat_dat]"
    GotoPage "Start"
  • A Cancel button with the following action:
    •  
      GotoPage "Start"


Line #1 of chat.ini might look something like this:

F:\CompX\OfcApps\chat.dat

 
 





LOGIN Page
Open the Page Action of the "Login" page and use FileRead to learn the name they will use in chat. This is stored the a variable called [handle].

FileRead "chat.ini" "2" "handle"
Create a dialog on this page that resembles the one shown below. Use this to ask the user for the name they will use in chat.

  • The text edit box contains the variable [handle].
  • The Chat button executes the following commands:
      ./// write the handle to the ini file
      FileWrite "chat.ini" "2" "[handle]"
      ./// insert two blank lines at the top of chat.dat
      FileInsLine "[chat_dat]" "1"
      FileInsLine "[chat_dat]" "1"
      ./// write your entrance to chat
      FileWrite "[chat_dat]" "1" "[handle] enters Chat"
      FileWrite "[chat_dat]" "2" ""
      GotoNextPage
Our chat.ini now looks something like this:

F:\CompX\OfcApps\chat.dat
InoJack
 
 





CHAT Page
We're almost there now! On the "Chat" page place the following objects:

  • A large Text Entry Box to display chat text
    • Max number of characters : 9999
    • Check "Multi-Line"
    • Variable : [chatext]
  • A smaller Text Entry Box to type in
    • Max number of characters : 1000 (use whatever settings you prefer)
    • Variable : [saythis]
  • A Logout button with the following Actions
    • MessageBox "Logout of Chat?" "Do you want to Logout of Chat?" "Yes|No" "asklogout"

    • If "[asklogout]" "=" "1"
      ./// insert blank lines at the top
      FileInsLine "[chat_dat]" "1"
      FileInsLine "[chat_dat]" "1"
      ./// write that you've exited chat
      FileWrite "[chat_dat]" "1" "[handle] exits Chat"
      FileWrite "[chat_dat]" "1" ""
      ./// break the While loop
      SetVar "[doloop]" "0"
      GotoPage "Start"
      EndIf
  • A Say button with these Actions
    • FileInsLine "[chat_dat]" "1"

    • FileInsLine "[chat_dat]" "1"
      FileWrite "[chat_dat]" "1" "<[handle]> [saythis]"
      FileWrite "[chat_dat]" "2" ""
      SetVar "saythis" ""
  • And lastly, a Refresh button with these commands
    • FileRead "[chat_dat]" "ALL" "chatext"


It might end up looking something like my example...

Obviously, the "Chat" page does most of the work. There are other conditions that could be detected and used to initiate a FileRead action but for this example I'll just use a While loop to read the chat.dat file every so many seconds.

Enter the following commands into the "Chat" Page Actions

SetVar "doloop" "1"
FileRead "[chat_dat]" "ALL" "chatext"
While "[doloop]" "=" "1"
 Delay "5000"
 FileRead "[chat_dat]" "ALL" "chatext"
EndWhile
Okay! Go back to the Intro page and hit the Run button...