Results 1 to 3 of 3

Thread: A Little problem with CommonDialog control, please help me.

  1. #1

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

    A Little problem with CommonDialog control, please help me.

    Hi All
    I have something like this
    Code:
    Private Sub cmdSave_Click()
        
        Dim strBuffer       As String
        Dim intDemoFileNbr  As Integer
        Dim strFileToSave   As String
        
        On Error GoTo cmdSave_Click_Exit
     
        With dlgDemo
            .CancelError = True
            .InitDir = mstrLastDir
            .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
            .FileName = ""
            .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
            .ShowSave
            strFileToSave = .FileName
        End With
      
        On Error GoTo cmdSave_Click_Error
        
        intDemoFileNbr = FreeFile
        Open strFileToSave For Binary Access Write As #intDemoFileNbr
        strBuffer = txtTestFile.Text
        Put #intDemoFileNbr, , strBuffer
        Close #intDemoFileNbr
     
        mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
     
        Exit Sub
        
    cmdSave_Click_Error:
        MsgBox "The following error has occurred:" & vbNewLine _
             & "Err # " & Err.Number & " - " & Err.Description, _
               vbCritical, _
               "Save Error"
               
    cmdSave_Click_Exit:
    End Sub
    Unfortunatelly, now I want to save into txt file my data that are in a 5 textboxes. How I should to do it? How to save and how I should to back read into this 5 textboxes. Someone know?

    Thanks in advance
    Tamgovb
    I know, I know, my English is bad, sorry .....

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: A Little problem with CommonDialog control, please help me.

    Try
    Code:
    Open strFileToSave For Append As #1
    Print #1, Text1.Text 
    Print #1, Text2.Text
    Print #1, Text3.Text
    Print #1, Text4.Text
    Print #1, Text5.Text
    Close #1

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: A Little problem with CommonDialog control, please help me.

    Choose the appropriate file mode depending on if you want to add data to an existing file or create a new file to save just that info to. Modes: Output or Append (append will require you to make sure the file doesnt already exist and use Kill to delete it if it does).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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