Results 1 to 5 of 5

Thread: Save Textbox and Listbox in one file (VB3)

  1. #1

    Thread Starter
    Hyperactive Member Matt-D's Avatar
    Join Date
    Nov 1999
    Location
    Mettmann, Germany
    Posts
    305

    Save textbox and listbox in one file (VB3)

    In my programm there's listlox (List1), which I can save in
    a Text-File. Now I want to add a textbox, in which the user
    can write his name or something else. Now I want, that
    this textbox is the first line of the textfile and the following lines are from the listbox.

    1. How is the code for saving it ?
    2. How must I write the code, that the first line gets
    into a textbox and the rest into the listbox when I open the
    file ?


    For this programm I use VB 3.0 (but normally this isn't a problem)

    Thanks for some advice, Matt

    [Edited by Matt-D on 03-23-2000 at 10:45 AM]

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600
    Hi Matt-D.

    If I understand your questions correctly, this code should do the trick. To test it, create a new project with a textbox, listbox and a command button.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim iCounter As Integer
        Open "c:\windows\desktop\myfile.txt" For Output As #1
        Write #1, Text1
        
        For iCounter = 0 To List1.ListCount - 1
            Write #1, List1.List(iCounter)
        Next iCounter
        MsgBox "All Done"
    End Sub
    
    Private Sub Form_Load()
        List1.AddItem "one"
        List1.AddItem "two"
        List1.AddItem "three"
    End Sub
    If you need more help, just re-post.

    All the best.

  3. #3
    New Member
    Join Date
    Jan 2009
    Posts
    1

    Re: Save Textbox and Listbox in one file (VB3)

    first put the text file into the listbox
    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

    OpenFileDialog1.Filter = "Text Files (*.TXT)|*.TXT" 'looks for files ending in TXT
    OpenFileDialog1.ShowDialog() 'Common dialog
    If OpenFileDialog1.FileName <> "" Then 'Is there a real filename
    FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) 'if so open the file for input
    Call ReadFile() 'a subroutine to read the file
    End If
    On Error Resume Next
    FileClose()

    End Sub
    -------------------
    Sub ReadFile()

    While Not EOF(1)
    ListBox1.Items.Add(LineInput(1)) 'text items in file go into listbox
    End While

    End Sub

    --------------------------------
    hope this helps

  4. #4
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: Save textbox and listbox in one file (VB3)

    Quote Originally Posted by Matt-D
    In my programm there's listlox (List1), which I can save in
    a Text-File. Now I want to add a textbox, in which the user
    can write his name or something else. Now I want, that
    this textbox is the first line of the textfile and the following lines are from the listbox.

    1. How is the code for saving it ?
    2. How must I write the code, that the first line gets
    into a textbox and the rest into the listbox when I open the
    file ?


    For this programm I use VB 3.0 (but normally this isn't a problem)
    Well the procedure is the same whether is VB3/4/5 or 6. As explained by OneSource.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Save Textbox and Listbox in one file (VB3)

    It's almost 9 years later - I really hope he doesn't actually care about this any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width