Adblock breaks this site

Common Dialog Help..

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

  1. Teizhcial

    Teizhcial Guest

    Referrals:
    0
    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.
     
  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    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
     
  3. Teizhcial

    Teizhcial Guest

    Referrals:
    0
    Common Dialog Help..

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


 
 
Adblock breaks this site