Results 1 to 4 of 4

Thread: ***----Writing To a File part 2----***

  1. #1

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92

    Exclamation

    thanks a lot...

    secodly what if i have two list boxes one with strings and the other with integers:

    lstname lstAge

    Sally 12
    Moe 26
    Shanel 23
    Hary 24

    how do add both to a file??
    so the text file looks like this

    Sally, 12
    Moe, 26
    Shanel, 23
    Hary, 24

    please help?!!1

  2. #2
    Guest
    You can use the Replace function to do this.

    Code:
    Private Sub Form_Load()
    
    Dim x(3) As String
    x(0) = "Sally 12"
    x(1) = "Moe 26"
    x(2) = "Shanel 23"
    x(3) = "Hary 24"
    
    For i = LBound(x) To UBound(x)
    List1.AddItem x(i)
    Next i
    
    End Sub
    
    
    Private Sub Command1_Click()
    
    For i = 0 To List1.ListCount - 1
    strTxt = Replace(List1.List(i), " ", Chr(44) & Chr(32))
    List2.AddItem strTxt
    Next i
    
    End Sub

  3. #3
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Code:
    Dim text As String
    text = lstname.Text & "," & lstage.Text & vbCrLf
    Open "C:\myfile.txt" For OutPut As #1
      Print #1, text
    Close #1
    Hope that helps,
    D!m
    Dim

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Assuming that the 2 listboxes are in synch with each other (i.e., they both have the same number of items and that the first item of the first box is associated with the first item of the second box, the second item of the first box is associated with the second item of the second box, etc.) you could use the following:
    Code:
    Dim intX       As Integer
    Dim intFileNbr As Integer
    
    intFileNbr = FreeFile
    Open "C:\Whatever\MyFile.Dat" For Output As #intFileNbr
    
    For intX = 0 to lstName.ListCount - 1
        Write #intFileNbr, lstName.List(intX), Val(lstAge.List(intX))
    Next
    "It's cold gin time again ..."

    Check out my website here.

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