Why does the MsgBox get hung up?

vharrig
vharrig used Ask the Experts™
on
Every time I try and run my program, the MsgBox will appear at the correct time, but it get's hung up and won't go away when I click "Ok". Also, I have to go the Task manager to stop the program, it won't even let me stop it from the VB project. Here is my code.
Private Sub Command2_Click()
a = 0
Dim x As Integer
Dim makea(4, 1000)
Dim lista(1000)
'Open "C:\My Documents\sitepcm1.txt" For Input As #1 ' This is for my computer!!!!
Open "S:\CODenver\Denver Network - DO NOT MOVE THIS FOLDER!!!!\Denver Network - DO NOT MOVE\Denver Switch - DO NOT REMOVE\Tellabs\External_Data_Retrieval\sitepcm.txt" For Input As #1
    Input #1, Info(a)
        Do Until EOF(1)
    Input #1, Info(a)
        a = a + 1
    Loop
Close #1

    For x = 0 To a - 1

    List1.Text = InStr(1, LCase(Info(x)), LCase(txtFind.Text), vbTextCompare)
    If InStr(1, Info(x), txtFind.Text, vbTextCompare) <> 0 Then
    makea(1, x) = Mid(Info(x), 1, 2)
    makea(2, x) = Mid(Info(x), 11, 4)
    makea(3, x) = Mid(Info(x), 24, 3)
    makea(4, x) = Mid(Info(x), 36, 50)
    lista(x) = makea(1, x) & "|" & makea(2, x) & "|" & makea(3, x) & "|" & makea(4, x)
    lista(x) = Replace(lista(x), " ", "")
    List1.AddItem lista(x)
Else
MsgBox "No Data found,Please try again", vbRetryCancel
End If

Next
End Sub

Thank you,
Vaughn
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT Engineer
Distinguished Expert 2017
Commented:
Hi again Vaughn,

Where did I see that code b4? ;-))

Try to put an Exit Sub after the MsgBox line.
Like:

  MsgBox "No Data found,Please try again", vbRetryCancel
  Exit Sub
End If

Good luck,

Vitor Montalvao

Author

Commented:
:-)
Yea, it does look familar doesn't it.
That worked, thank you very much. Don't worry you will see my name again. I'm extremely interested in programming and hopefully, one day I can answer questions and help others out also.
Thanks again.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Good!

I hope that you understood why you need to place there the Exit Sub statement!

Response: Because you need to get out of the For...Next statement. (Yes, an Exit For statement will be good too - maybe better because is not so radical)!

Best regards,

Vitor Montalvao

Commented:
I just like the filename...

"S:\CODenver\Denver Network - DO NOT MOVE THIS FOLDER!!!!\Denver Network - DO NOT MOVE\Denver Switch - DO NOT REMOVE\Tellabs\External_Data_Retrieval\sitepcm.txt"

Author

Commented:
Thanks, yea we need to stop people form deleting our network folders. Funny how that works.
You've been a big help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial