Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

openfiledialog in vb


  • Please log in to reply

#1
atlantica

atlantica

    Member

  • Member
  • PipPip
  • 39 posts
I have this code so far:

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

Dim MyFileOpen As New System.Windows.Forms.OpenFileDialog
Dim bExOccured As Boolean
Dim retVal As DialogResult
Dim sMyFile As String
Try
' does not add an extension to a file name if the user omits the extension
MyFileOpen.AddExtension = True

'dialog box does not allow multiple files to be selected
MyFileOpen.Multiselect = False

MyFileOpen.Filter = "ASCII files (*.txt;*.log)|*.txt;*.log"
'MyFileOpen.Filter = "Microsoft Word Documents (*.doc)|*.doc|Microsoft Word Documents (*.rtf)|*.rtf"
'MyFileOpen.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF"
'MyFileOpen.Filter = "Microsoft Word Documents (*.doc;*.rtf)|*.doc;*.rtf"

'MyFileOpen.Filter = "Microsoft Excel Workbooks (*.xls)|*.xls"
'MyFileOpen.Filter = "Microsoft Excel Addins (*.xla;*.xll)|*.xla;*.xll"
'MyFileOpen.Filter = "All files (*.*)|*.*"
'MyFileOpen.Filter = "Text files (*.txt)|*.txt"


retVal = MyFileOpen.ShowDialog()
If retVal = Windows.Forms.DialogResult.OK Then

If MyFileOpen.CheckFileExists = True And MyFileOpen.CheckPathExists = True Then

sMyFile = MyFileOpen.FileName
Me.RichTextBox1.Text = sMyFile
----------------------------------------------------------------------------------
Right here is where it makes the richtextbox show the text but it only shows me the file location. How can i modify this code to have it show me the text in the file, not the location of the file?
----------------------------------------------------------------------------------
End If
End If
Catch ex1 As AccessViolationException
MsgBox(ex1.StackTrace.ToString)
bExOccured = True
Catch ex As Exception
MsgBox(ex.StackTrace.ToString)
bExOccured = True
Finally
If bExOccured = True Then
MsgBox("Program executed with some errors!!!")
End If
End Try
End Sub
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP