• Log in or sign up for an account here: https://www.sythe.org/login

Common Dialog Help..

  • Thread starter Thread starter Teizhcial
  • Start date Start date
T

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.
 
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
 
Common Dialog Help..
Thanks it worked. And I only go to PSC when I'm completely stumped.
 
Runescape Gamblingrunescape gambling
Back
Top