Results 1 to 4 of 4

Thread: [RESOLVED] Combo and arrays of txt controls - prob with saving to a txt file

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Resolved [RESOLVED] Combo and arrays of txt controls - prob with saving to a txt file

    Welcome
    I have something like this
    First the code it's to saving the txt file - how see I used CommonDialog control, and second code it's to a reading - I used also CommonDialog control.
    Code:
    Option Explicit
    Dim IntLic     As Long
    Dim iCount     As Long
    Dim intNumPlik As Long
    Dim strBufor   As String
    Dim strKatalog As String
    Dim data()     As String
    Dim i          As Long
    Dim lgCoKas    As Long
    
    '''''''''''''''''''''''''''''''''  ZAPIS (eng: save of data) danych do pliku txt '''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Private Sub cmdZapis_Click()
       
    Dim strPlikZapisz   As String
        
        With cdlMyDialog
            .CancelError = True
             On Error GoTo BladPoCancel        ' << rozmyślił się User i klik na Cancel
            .InitDir = strKatalog
            .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
            .FileName = ""
            .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
            .ShowSave
            On Error GoTo CapBlad              ' << a to gdy inny błąd
            strPlikZapisz = .FileName
        End With
        
        intNumPlik = FreeFile
        Open strPlikZapisz For Output As #intNumPlik
        
          For IntLic = 0 To 6                  ' << tablica txt siup do pliku
            Print #intNumPlik, txtRaz(IntLic)
          Next
                 
         
               If Combo1.ListCount > 0 Then
                  For i = 0 To Combo1.ListCount - 1 ' << zawartość Combo siup do pliku
                    Print #intNumPlik, Combo1.List(i)
                  Next
               End If
        
        Close #intNumPlik
        Exit Sub
    
    CapBlad:
        MsgBox "Nieoczekiwany błąd:" & vbNewLine _
             & "Err # " & Err.Number & " - " & Err.Description, _
               vbCritical, _
               "Błędne działanie"
    BladPoCancel:
     End Sub
        
    ''''''''' eng: READ and LOAD data to a objects (the array txt and ComboBox)''''''''
    '''''''''''''''''''''' ODCZYT  i  ZAŁADOWANIE danych do obiektów '''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private Sub cmdOdczyt_Click()
     
        Dim strOtworzPlik   As String
    
        With cdlMyDialog
            .CancelError = True
             On Error GoTo CancelError ' << user wcisnął Cancel
            .InitDir = strKatalog
            .Flags = cdlOFNHideReadOnly
            .FileName = ""
            .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
            .ShowOpen
            On Error GoTo TrapError    ' << inny błąd
            strOtworzPlik = .FileName
        End With
          
        intNumPlik = FreeFile
        Open strOtworzPlik For Input As #intNumPlik
        strBufor = Input$(LOF(intNumPlik), intNumPlik)
        Close #intNumPlik
        
        
    
                data = Split(strBufor, vbNewLine)       '<<< strBufor - teraz podziel dane na oddzielne linie
                        
                   For IntLic = 0 To 6
                     txtRaz(IntLic) = data(IntLic)      '<<< przekaż część do tablicy kontrolek txt
                   Next
    
                                     
                   For IntLic = 7 To UBound(data)       '<<< resztę - do końca - dodaj do Combo1
                     Combo1.AddItem data(IntLic)        '<<<  I TUTAJ jest coś źle
                   Next                                 '<<< bo dodaje pustą linię na końcu
                 
                lgCoKas = 4                             '<<< licznik, jego wartość steruje blokiem kasowania
    
           Combo1.ListIndex = 0                         '<<< ustaw w Combo 1 pozycję
        
        ''''''''''''ustaw w belce okna informację jaki plik otworzyłeś''''''''''''''
        Me.Caption = vbNullString: Me.Caption = "Otwarto plik" & " " & strOtworzPlik
    
      Exit Sub
    TrapError:
        MsgBox "Nieoczekiwany błąd:" & vbNewLine _
             & "Err # " & Err.Number & " - " & Err.Description, _
               vbCritical, _
               "Błędne działanie"
               
    
    CancelError:
    End Sub
    I note, my code to saving has a some the error, because it write in addition for me a blank line on the end of this file. What is wrong in my code? Someone it know?

    Thanks in advance
    Last edited by Tamgovb; Nov 24th, 2008 at 03:09 PM.
    I know, I know, my English is bad, sorry .....

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