Results 1 to 3 of 3

Thread: [RESOLVED] Prob with saving the data from more controls - CommonDialog

  1. #1

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

    Resolved [RESOLVED] Prob with saving the data from more controls - CommonDialog

    Hi All

    I have something like this – how see, I use CommonDialog control. I don’t know how I fix it.
    How I would it to make?

    This is a sub to read – here's OK, need only procedure of handling any errors

    Code:
    Option Explicit
        Dim strBufor       As String
        Dim strKatalog     As String
        Dim strPlikZapis   As String
        Dim strPlikOdczyt  As String
        Dim intNumPlik     As Integer
        Dim IntLic         As Integer
    
    
    Private Sub cmdOdczyt_Click()
    
        Dim data()         As String
    
        With cdlMyDialog
            .CancelError = True
            .InitDir = strKatalog
            .Flags = cdlOFNHideReadOnly
            .fileName = ""
            .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
            .ShowOpen
            strPlikOdczyt = .fileName
        End With
          
        intNumPlik = FreeFile               
    
        Open strPlikOdczyt For Binary Access Read As #intNumPlik   '<<< open the file
        strBufor = Input$(LOF(intNumPlik), intNumPlik)
        Close #intNumPlik
    
    data = Split(strBufor, vbNewLine)       '<<< get the data
         
         For IntLic = 0 To 6
           txtRaz(IntLic) = data(IntLic)    '<<< entry to determine of objects
         Next
         Combo1.Text = data(7)
    Following is a sub to write – here's a wrong. I don't know, what?

    Code:
    Private Sub cmdZapis_Click()
    
        With cdlMyDialog
            .CancelError = True
            .InitDir = strKatalog
            .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
            .fileName = ""
            .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
            .ShowSave
            strPlikZapis = .fileName
        End With
        
        intNumPlik = FreeFile
        Open strPlikZapis For Binary Access Write As #intNumPlik
        
        For IntLic = 0 To 6          '<<< And here it's this prob 
          Put #intNumPlik, , CStr(txtRaz(IntLic)) '<<< try it so, unfortunately it to give a one the line, 
                                                              ' <<< still  is a wrongly
        Next                         '<<< What is a wrong ???? How to make?
        
        Put #intNumPlik, , strBufor           
        Close #intNumPlik
    Please help me, thanks in advance
    Last edited by Tamgovb; Nov 12th, 2008 at 05:26 PM.
    I know, I know, my English is bad, sorry .....

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Prob with saving the data from more controls - CommonDialog

    What is the error? Or what is wrong? Can you be specific

    Oh, I see now. When you read the lines from the text file, you used Split() on vbNewLine. That stripped the vbNewLine out of the data, you have to put it back:

    Code:
        For IntLic = 0 To 6          
          Put #intNumPlik, , CStr(txtRaz(IntLic) & vbNewLine)
        Next
    However, I'd recommend the following and not using For Binary
    Code:
    Open strPlikZapis For OutPut As #intNumPlik
       For IntLic = 0 To 6
          Print #intNumPlik, txtRaz(IntLic)
       Next
       Print #intNumPlik, strBufor
    ...
    This way, the file is guaranteed to be overwritten without any 'garabage' at the end of the file. For example, if txtRaz(0) thru txtRaz(6) had 500 characters when you read the file, and later you made those textboxes just have 1 character each, you would think your file should be 493 characters smaller, no? Well, it will be the same size with 493 junk characters at the end of the file. But when you open a file For Output, you are completely overwriting the file.
    Last edited by LaVolpe; Nov 12th, 2008 at 06:42 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

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

    Re: Prob with saving the data from more controls - CommonDialog

    Hi
    Yeah, I was not idle in this time and at the same time I found on a different forums the same of information. Those information tell me the same, exactly like you me tell - I should change the mode of writes to files. Ok, thanks a lot, I will to do it

    I greet
    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