944,084 Members | Top Members by Rank

Ad:
Nov 10th, 2009
0

Open file VB6

Expand Post »
I am using a MDI Form and several documents can be opened using
"CommonDialog1.ShowOpen"

If i open a file then go back to open another file but click cancel or the "x" then it will open the last file.

so i need to know how to clear the "#1"

my code it:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. FileName = ""
  2. Data = ""
  3. MDIForm1.CommonDialog1.Filter = "All Files(*.*)|*.*|Text Files(*.txt)|*.txt|Web Files(*.html;*.htm;*.shtml;*.shtm;*.xhtml;*.php;*.php3;*.phtml;*.css;*.js;)|*.html;*.htm;*.shtml;*.shtm;*.xhtml;*.php;*.php3;*.phtml;*.css;*.js;|Batch Files(*.bat;*.cmd;*.nt;)|*.bat;*.cmd;*.nt;|VB Files(*.vb;*.vbs;*.frm;*.vbp;)|*.vb;*.vbs;*.frm;*.vbp;"
  4. On Error GoTo error
  5. MDIForm1.CommonDialog1.ShowOpen
  6. Me.Caption = MDIForm1.CommonDialog1.FileTitle
  7. FileName = MDIForm1.CommonDialog1.FileName
  8. Open FileName For Input As #1
  9.  
  10. Do Until EOF(1)
  11.  
  12. Input #1, Data
  13. Me.Text1.Text = Me.Text1.Text + Data + vbCrLf
  14. EOF (1)
  15. Loop
  16. Close #1
  17. FileName = ""
  18. Data = ""
  19. GoTo endload

Any ideas

I have cleared the "FileName" and "Data" but it still does it so i need to find a way to stop it.
Last edited by drabsch; Nov 10th, 2009 at 1:25 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
drabsch is offline Offline
35 posts
since Aug 2009
Nov 10th, 2009
0
Re: Open file VB6
#1 refers to the file and the Close event will close the file.
Reputation Points: 33
Solved Threads: 27
Posting Whiz
Jupiter 2 is offline Offline
372 posts
since May 2009
Nov 10th, 2009
1
Re: Open file VB6
two different ways are shown in the following...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Private Sub Command1_Click()
  4. OpenShowFile
  5. End Sub
  6.  
  7. Private Sub OpenShowFile()
  8.  
  9. On Error GoTo OpenShowFileError
  10.  
  11. Dim FName As String, FNumb As Integer
  12. Dim FileContents As String
  13.  
  14. CD.CancelError = True
  15. CD.Filter = "Text Files *.txt|*.txt"
  16. CD.FileName = vbNullString
  17. CD.ShowOpen
  18.  
  19. If CD.FileName = vbNullString Then Exit Sub
  20.  
  21. FName = CD.FileName
  22. FNumb = FreeFile
  23.  
  24. Open FName For Input As #FNumb
  25. FileContents = Input(FileLen(FName), #FNumb)
  26. Close #FNumb
  27.  
  28. Text1.Text = FileContents
  29.  
  30. Exit Sub
  31. OpenShowFileError:
  32.  
  33. If Err.Number = 32755 Then Exit Sub 'user pressed cancel
  34.  
  35. End Sub



Good Luck
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: get the databse table names
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB-Prime Numbers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC