Results 1 to 10 of 10

Thread: Save (again)

  1. #1

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Question

    How do I do that when I click on a button (Command1) it will save the data on a ListBox (List1) and another button (Command2) will load it back? (On a TXT)

    And also I got 100 Checkboxes in the same form (not in array).
    How do I make it that Command1 saves this too on another TXT and Command2 loads it?
    let's say I got 72 Checked so when I load it it will have 72 checked?

    ThanX for any posts.
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  2. #2
    Guest
    To Save the ListBox contents
    Code:
    Open "MyListFile.txt" For Append As #1
        For I = 0 To List1.ListCount - 1
            List1.Selected(I) = True
            Print #1, List1.Text
        Next I
    Close #1
    To Load the ListBox contents
    Code:
    Open "MyListFile1.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, tmp
            List2.AddItem tmp
        Loop
    Close #1

  3. #3
    Guest
    Regarding your CheckBox situation:

    To save the CheckBoxes
    Code:
    Dim chk As Control
    
    Open "MyCheckFile.txt" For Append As #1
        For Each chk In Controls
            If TypeOf chk Is CheckBox Then
                If chk = Checked Then Print #1, chk.Name
            End If
        Next chk
    Close #1
    To load the CheckBoxes
    Code:
    Dim chk As Control
    
    Open "MyCheckFile.txt" For Input As #1
        Do While Not EOF(1)
        Line Input #1, tmp
            For Each chk In Controls
                If TypeOf chk Is CheckBox Then
                    If tmp = chk.Name Then chk = Checked
                End If
                
            Next chk
        Loop
    Close #1

  4. #4
    Guest
    here is something that records all of it, in one file


    Code:
    Option Explicit
    Option Base 1
    
    
    Private Sub Command1_Click()
    
    Dim TextFile As String
    Dim InStrText1 As Long
    Dim InStrText2 As Long
    Dim TheText1 As String
    Dim TheText2 As String
    Dim InStrCheck As Long
    Dim InStrCheckNum(2) As Long
    Dim TheValCheck(2) As String
    Dim FF As Integer
    
      FF = FreeFile
    
      Open "c:\windows\desktop\setting.txt" For Input As FF
        TextFile = Input(LOF(FF), FF)
      Close FF
    
      InStrText1 = InStr(1, TextFile, "[Text1]") + 9
      InStrText2 = InStr(InStrText1, TextFile, "[Text2]") + 9
    
      InStrCheck = InStr(InStrText2, TextFile, "[check]") + 9
    
      InStrCheckNum(1) = InStr(InStrCheck, TextFile, "1") + 2
      InStrCheckNum(2) = InStr(InStrCheck, TextFile, "2") + 2
    
      TheText1 = Mid$(TextFile, InStrText1, InStrText2 - InStrText1 - 11)
      TheText2 = Mid$(TextFile, InStrText2, InStrCheck - InStrText2 - 11)
    
      TheValCheck(1) = Mid$(TextFile, InStrCheckNum(1), 1)
      TheValCheck(2) = Mid$(TextFile, InStrCheckNum(2), 1)
    
      Select Case "y"
        Case TheValCheck(1)
          Check1.Value = vbChecked
        Case TheValCheck(2)
          Check1.Value = vbChecked
      End Select
    
      Text1 = TheText1
      Text2 = TheText2
    
    End Sub
    
    Private Sub Command2_Click()
    
    Dim FF As Integer
    Dim Text1Thing As String
    Dim Text2Thing As String
    Dim CheckThing As String
    Dim IsChecked(2) As String
    
      If Check1.Value = vbChecked Then
        IsChecked(1) = "y"
      Else: IsChecked(1) = "n"
      End If
    
      If Check2.Value = vbChecked Then
        IsChecked(2) = "y"
      Else: IsChecked(2) = "n"
      End If
    
      Text1Thing = "[Text1]"
      Text2Thing = "[Text2]"
      CheckThing = "[check]"
    
      FF = FreeFile
    
      Open "c:\windows\desktop\setting.txt" For Output As FF
      Print #FF, Text1Thing & vbCrLf & Text1.Text _
        & vbCrLf & Text2Thing & vbCrLf & Text2.Text _
        & vbCrLf & CheckThing & vbCrLf & "1=" & _
        IsChecked(1) & vbCrLf & "2=" & IsChecked(2)
      Close FF
    
    End Sub

    this is how the file is formatted

    Code:
    [Text1]
    hello dude!
    [Text2]
    hello again!
    [check]
    1=n
    2=y
    add more "1=n" etc for more check boxes, and you will need to modify my code a little.

  5. #5

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Talking

    I hope it will work... ThanX Megatron/Dennis Wrenn for your time.
    By the way Dennis, I am not trying to do it in one file, remember?

    I'll let you know if it works.
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  6. #6

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Thumbs up Bug

    ThanX Megatron.
    It all works, but there is a bug.
    Now let's pretend that I got 2 checkboxes in my form.
    I checked one and saved the status.
    I checked the other one, dechecked the first one.
    Now when I load it back, the first becomes checked but the second is still checked.

    Can you please give me a code to replace with the old code that you gave me?

    ThanX again. Very much!
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  7. #7
    Guest
    It should work now:

    Code:
    Dim chk As Control
    
    'Delete the previous record
    Kill "MyCheckFile.txt"
    
    Open "MyCheckFile.txt" For Append As #1
        For Each chk In Controls
            If TypeOf chk Is CheckBox Then
                If chk = Checked Then Print #1, chk.Name
            End If
        Next chk
    Close #1

  8. #8

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    I don't think you got me right...
    That's what I saved:
    The first checkbox is checked, and the second isn't.
    After I saved it, I dechecked the first and checked the second, which wasn't checked in the save.

    When I load it, the first gets checked like in the save, but the second isn't dechecking.
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  9. #9
    Guest
    Sorry about that.
    Code:
    Dim chk As Control
    
    'Uncheck all CheckBoxes
    For Each chk In Controls
        chk = Unchecked
    Next chk
    
    Open "MyCheckFile.txt" For Input As #1
        Do While Not EOF(1)
        Line Input #1, tmp
            For Each chk In Controls
                If TypeOf chk Is CheckBox Then
                    If tmp = chk.Name Then chk = Checked
                End If
                
            Next chk
        Loop
    Close #1

  10. #10

    Thread Starter
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335

    Talking WOOHOO!!!

    ThanX Megatron!
    IT WORKS!!!

    There were some bugs abou the
    app.path &
    you didn't add them for the first time, but it was fixed!

    HOORAY!
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

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