Reading and writing lines from a text file...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Reading and writing lines from a text file...

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    53

    Reading and writing lines from a text file...

    Hi there...
    I am trying to make a winsock control send a line from a text file once every minite.

    so if the text file had 5 lines, it would send a line every minite then go and start from the top again...

    First of all, I want to make it so that when a form loads, the text box in it will say the same as the text in the text file.

    Then If the user wants to edit the text file, or add a line to it, it can be saved....

    Then I want the winsock to send each line from the text file individually at an interval of 1 minite.

    Do I can do it with textboxes and a timer, eg
    timerinerval being 60000,
    Code:
       TIMER1
        wsk.senddata text1.text
        timer1.enabled = false
        timer2.enabled = true
    
        TIMER2
       wsk.senddata text2.text
       timer2.enabled = false
        timer1.enabled = true
    that then just keeps sending the text in the text boxes over and over, (which is what i want) but That can't save the text in the textboxes and limits the amount of messages by the amount of text boxes you have....

    i would be grateful of any help

    Jenks
    Last edited by Jenks; 05-21-2005 at 08:45 AM.

  2. #2
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    Can you be more specific as to what part of this scenario you are having trouble with?
    Bob Rouse
    Dimension Data

  3. #3
    Join Date
    Apr 2005
    Posts
    53
    BAsically, I want a winsock control to send a line of data every minite.
    So If I had a text file with the data I want to send looking like this....

    Code:
    Welcome to my server
    I Hope you enjoy your stay
    Then I would want the winsock control to send the first line "Welcome....Server" then wait 1 minite and then send the second line "I hope....Stay", then repleat the cycle.

    Thanks

    Jenks

  4. #4
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    First, (if storing the values in a text file) you can read the text file into a "hidden" listbox control (set Visible = False). Then using a timer control (or the timer APIs - depending on how accurate that 1 minute needs to be), loop through the list:

    Code:
    Dim intPos as integer
    
    Sub Timer1_Timer()
    
        Dim strMsg as String
    
        ' Start over if at the end of the list
        If intPos = List1.ListCount then
            intPos = 0
        End If
    
        ' Get the message
        strMsg = List1.List(intPos)
    
        ' Send it...
    Bob Rouse
    Dimension Data

  5. #5
    Join Date
    Apr 2005
    Posts
    53
    ok thanks,
    would that code get the first line in the list box, if so which bit would I change to read the 2nd line etc...

  6. #6
    Join Date
    Apr 2005
    Posts
    53
    ok thanks,
    would that code get the first line in the list box, if so which bit would I change to read the 2nd line etc...

    and what code would I use to read the fiel into the list box

    Jenks

  7. #7
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    To get the file into the list box, I would recommend using the Microsoft Scripting Runtime library: http://msdn.microsoft.com/library/de...filesystem.asp

    Open the file using a "File" object to load it into a "TextStream" object, and loop through the file getting each line with the "ReadLine" method of the "TextStream" object and add it to the list box using the listbox's "AddItem" method.
    Bob Rouse
    Dimension Data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center