-
I have this:
Code:
Private Sub mnuLoad_Click()
lstDeck.Clear
Open App.Path & "\Decks\" & txtTitle.Text & ".dck" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
lstDeck.AddItem tmp
Loop
Close #1
stbStatus.Panels(2).Text = "Cards In Deck: " & lstDeck.ListCount
End Sub
I want to do that whenever the app detects that the file written on txtTitle does not exist, it will show me a message box and not terminate the app.
Could you please modify this code and not using Text1. etc. because I get confused.
Every help will be appriciated.
-
Private Sub mnuLoad_Click()
on error goto 1000
lstDeck.Clear
Open App.Path & "\Decks\" & txtTitle.Text & ".dck" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
lstDeck.AddItem tmp
Loop
Close #1
stbStatus.Panels(2).Text = "Cards In Deck: " & lstDeck.ListCount
exit sub
1000 msgbox "HEY THAT FILE DOES NOT EXIST"
close #1
End Sub
-----------------------
or
Private Sub mnuLoad_Click()
lstDeck.Clear
if dir(App.Path & "\Decks\" & txtTitle.Text & ".dck")="" then msgbox "hey that does not exist!":exit sub
Open App.Path & "\Decks\" & txtTitle.Text & ".dck" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
lstDeck.AddItem tmp
Loop
Close #1
stbStatus.Panels(2).Text = "Cards In Deck: " & lstDeck.ListCount
End Sub
-
<?>
Code:
Private Sub command1_Click()
Dim sFile$
'sFile = "Name And Path Of Your File"
sFile = App.Path & "\Decks\" & txtTitle.Text & ".dck"
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(sFile$) = True Then
lstDeck.Clear
Open App.Path & "\Decks\" & txtTitle.Text & ".dck" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
lstDeck.AddItem tmp
Loop
Close #1
stbStatus.Panels(2).Text = "Cards In Deck: " & lstDeck.ListCount
Else
MsgBox "Does Not Exist...Your code here!"
End If
Set fs = Nothing
End Sub
-
ThanX for your help, it works just fine!