Hi there,
I have a bit of code here that I can't seem to fix. There's gotta be something very simple that I'm doing wrong.
Essentially what's happening is that when I click on Cancel or No on my input and message boxes my script should end. But what it does is continue on to the next part of my code as if the buttons weren't pressed. Can someone take a look at this code and let me know what's going on? When the script is run and I enter everything correctly it runs perfectly, but when I need to cancel out of the program it continues. I should not be able to see the message "If you clicked No, you should not see this." It should stop right before that.
Oh and the code I use is much bigger than this, I've just simplified it for posting purposes.
Thanks!
Here's the code:
Sub NeedHelp()
With Session
Dim ISP As String
Dim ADDR As String
Dim CBM As String
Dim intCount As Integer
Dim lngAnswer As Long
Dim boExitLoop As Boolean
Dim ISPArray(0 To 3, 0 To 2) As String
'2IC SYSTEMS INC
ISPArray(0, 0) = "2IC"
ISPArray(0, 1) = "114 3855 henning dr burnaby bc v5c6n3"
ISPArray(0, 2) = "cbnktkcomab"
'3Men@Work
ISPArray(1, 0) = "3ME"
ISPArray(1, 1) = "600 1375 transcanadienne dorval qc h9p2w8"
ISPArray(1, 2) = "cbnthreemenab"
'ACCELERATED
ISPArray(2, 0) = "ACC"
ISPArray(2, 1) = "216 1600 w steeles av concord on l4k4m2"
ISPArray(2, 2) = "cbnaccelerated"
'Advanced Knowledge Networks Inc
ISPArray(3, 0) = "AKN"
ISPArray(3, 1) = "401 60 adelaide st e toronto on m5c3e4"
ISPArray(3, 2) = "cbeadvancedata"
Do
ISP = InputBox("Enter the first 3 letters of the ISP's name." & _
vbCrLf & "" & _
vbCrLf & "**PLEASE NOTE**" & _
vbCrLf & "" & _
vbCrLf & "For TELESAT and TELIPHONE use the first 4 letters", "WHAT ISP ARE WE DEALING WITH?", "")
If ISP <> vbNullString Then
Do
If Trim$(UCase(ISP)) = Trim$(UCase(ISPArray(intCount, 0))) Then
boExitLoop = True
Else
intCount = intCount + 1
End If
Loop Until boExitLoop Or intCount > UBound(ISPArray, 1)
If Not boExitLoop Then
lngAnswer = MsgBox("Hmmm... You know what?" & _
vbCrLf & "" & _
vbCrLf & "I don't recognize the ISP " & _
vbCrLf & "" & _
vbCrLf & "'" & ISP & "'" & _
vbCrLf & "" & _
vbCrLf & "Do you want to try again?", vbYesNo + vbExclamation, "WAIT, DON'T TELL ME... I KNOW THIS ONE!")
If lngAnswer = vbNo Then
boExitLoop = True
intCount = UBound(ISPArray, 1) + 1
Else
intCount = 0
End If
End If
Else
lngAnswer = MsgBox("Now hold on a minute!" & _
vbCrLf & "" & _
vbCrLf & "It looks like you just hit OK or CANCEL." & _
vbCrLf & "" & _
vbCrLf & "Do you want to try again?", vbYesNo + vbCritical, "WAS IT SOMETHING I SAID?")
If lngAnswer = vbNo Then
boExitLoop = True
intCount = UBound(ISPArray, 1) + 1
Else
intCount = 0
End If
End If
Loop Until boExitLoop
If intCount <= UBound(ISPArray, 1) Then
ADDR = ISPArray(intCount, 1)
CBN = ISPArray(intCount, 2)
End If
.MoveCursor 23, 47
.TransmitANSI "If you clicked No, you should not see this."
End With
End Sub
I have a bit of code here that I can't seem to fix. There's gotta be something very simple that I'm doing wrong.
Essentially what's happening is that when I click on Cancel or No on my input and message boxes my script should end. But what it does is continue on to the next part of my code as if the buttons weren't pressed. Can someone take a look at this code and let me know what's going on? When the script is run and I enter everything correctly it runs perfectly, but when I need to cancel out of the program it continues. I should not be able to see the message "If you clicked No, you should not see this." It should stop right before that.
Oh and the code I use is much bigger than this, I've just simplified it for posting purposes.
Thanks!
Here's the code:
Sub NeedHelp()
With Session
Dim ISP As String
Dim ADDR As String
Dim CBM As String
Dim intCount As Integer
Dim lngAnswer As Long
Dim boExitLoop As Boolean
Dim ISPArray(0 To 3, 0 To 2) As String
'2IC SYSTEMS INC
ISPArray(0, 0) = "2IC"
ISPArray(0, 1) = "114 3855 henning dr burnaby bc v5c6n3"
ISPArray(0, 2) = "cbnktkcomab"
'3Men@Work
ISPArray(1, 0) = "3ME"
ISPArray(1, 1) = "600 1375 transcanadienne dorval qc h9p2w8"
ISPArray(1, 2) = "cbnthreemenab"
'ACCELERATED
ISPArray(2, 0) = "ACC"
ISPArray(2, 1) = "216 1600 w steeles av concord on l4k4m2"
ISPArray(2, 2) = "cbnaccelerated"
'Advanced Knowledge Networks Inc
ISPArray(3, 0) = "AKN"
ISPArray(3, 1) = "401 60 adelaide st e toronto on m5c3e4"
ISPArray(3, 2) = "cbeadvancedata"
Do
ISP = InputBox("Enter the first 3 letters of the ISP's name." & _
vbCrLf & "" & _
vbCrLf & "**PLEASE NOTE**" & _
vbCrLf & "" & _
vbCrLf & "For TELESAT and TELIPHONE use the first 4 letters", "WHAT ISP ARE WE DEALING WITH?", "")
If ISP <> vbNullString Then
Do
If Trim$(UCase(ISP)) = Trim$(UCase(ISPArray(intCount, 0))) Then
boExitLoop = True
Else
intCount = intCount + 1
End If
Loop Until boExitLoop Or intCount > UBound(ISPArray, 1)
If Not boExitLoop Then
lngAnswer = MsgBox("Hmmm... You know what?" & _
vbCrLf & "" & _
vbCrLf & "I don't recognize the ISP " & _
vbCrLf & "" & _
vbCrLf & "'" & ISP & "'" & _
vbCrLf & "" & _
vbCrLf & "Do you want to try again?", vbYesNo + vbExclamation, "WAIT, DON'T TELL ME... I KNOW THIS ONE!")
If lngAnswer = vbNo Then
boExitLoop = True
intCount = UBound(ISPArray, 1) + 1
Else
intCount = 0
End If
End If
Else
lngAnswer = MsgBox("Now hold on a minute!" & _
vbCrLf & "" & _
vbCrLf & "It looks like you just hit OK or CANCEL." & _
vbCrLf & "" & _
vbCrLf & "Do you want to try again?", vbYesNo + vbCritical, "WAS IT SOMETHING I SAID?")
If lngAnswer = vbNo Then
boExitLoop = True
intCount = UBound(ISPArray, 1) + 1
Else
intCount = 0
End If
End If
Loop Until boExitLoop
If intCount <= UBound(ISPArray, 1) Then
ADDR = ISPArray(intCount, 1)
CBN = ISPArray(intCount, 2)
End If
.MoveCursor 23, 47
.TransmitANSI "If you clicked No, you should not see this."
End With
End Sub