Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Show how to check if a file exists and if it does ...
Author:
Jacques
E-mail:
Click to e-mail author
Submitted:
5/18/2001
Version:
VB6
Compatibility:
VB6
Category:
File Manipulation
Views:
13075
Show how to check if a file exists and if it does open the file into a standard text box.
Declarations:
Create a form with a command button named cmdOpen, a commondialog control name it dlgOpen a textbox named txtFile multiline = true 'Although the commondialog control can check if a file exists here is an alternative to the commondialog
Code:
Private Sub cmdOpen_Click() Dim strTemp As String, strRead As String On Error Resume Next dlgOpen.ShowOpen 'Although the commondialog control 'can check if a file exists here is 'an alternative to the commondialog FileLen (dlgOpen.FileName) If Err.Number <> 0 Then MsgBox "File does not exist" Exit Sub End If Open dlgOpen.FileName For Input As #1 Do While Not EOF(1) Input #1, strRead If strTemp = "" Then 'First entry don't 'include vbCrLf strTemp = strRead Else strTemp = strTemp & vbCrLf & strRead End If Loop txtFile.Text = strTemp Close #1 End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement