Common Dialog Help..

Discussion in 'Programming General' started by Teizhcial, Jan 1, 2008.

Common Dialog Help..
  1. Unread #1 - Jan 1, 2008 at 6:58 PM
  2. Teizhcial
    Referrals:
    0

    Teizhcial Guest

    Common Dialog Help..

    Ok so I want to open a .txt file and when it opens the text in it appears in text1.text

    Heres what I have...

    Code:
    Private Sub Command1_Click()
    On Error Resume Next
    Dim Ofile As String
    With Form1.commonDialog1
        .DialogTitle = "Open Variable List"
        .Filter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*"
        .CancelError = False
        .FileName = "*.txt"
        .ShowOpen
        Ofile = .FileName
    form2.Text1.Text = CommonDialog1.FileName.txt '??
    End With
    End Sub
    
    I know theres a simple solution to this but I can't get it from PSC because I can't DL anything right now.
     
  3. Unread #2 - Jan 1, 2008 at 10:46 PM
  4. Jazz00006
    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0

    Jazz00006 Apprentice
    Visual Basic Programmers

    Common Dialog Help..

    Don't rely on PSC.


    This may need a few names changes to fit in with your project, but it works.
    Code:
    Private Sub Command1_Click()
          On Error GoTo err:
          With CommonDialog1
              .DialogTitle = "Open Variable List"
              .Filter = "Text File (*.txt)|*.txt|All Files (*.*)|*.*"
              .CancelError = False
              .ShowOpen
                Text1.Text = Readfile(.FileName) 'Change this to your textbox
          End With
    err:
    If err.Number <> 52 Then
          Debug.Print err.Number
          Debug.Print err.Description
    End If
    End Sub
    
    Function Readfile(sPath As String) As String
          Dim sFileText As String
          Dim iFileNo As Integer
          iFileNo = FreeFile
          Open sPath For Input As #iFileNo
                Do While Not EOF(iFileNo)
                      Input #iFileNo, sFileText
                      Readfile = Readfile & sFileText & vbCrLf
                Loop
          Close #iFileNo
    End Function
     
  5. Unread #3 - Jan 2, 2008 at 6:54 PM
  6. Teizhcial
    Referrals:
    0

    Teizhcial Guest

    Common Dialog Help..

    Thanks it worked. And I only go to PSC when I'm completely stumped.
     
< Vb Portable Help | Help With Understanding This........... >

Users viewing this thread
1 guest


 
 
Adblock breaks this site