Valhalla Legends Forums Archive | Visual Basic Programming | [VB]Problem with "Select Case e(0)"

AuthorMessageTime
Learn
Well, I've just started programming with VB and I'm working on a simple and easy chat bot. But I keep getting an error when I Play then Connect it. I was hoping someone can help.

Heres there error I get:

Run-time error '9':

Subscript out of range.

Then I click debug and it highlights " Select Case e(0) "

Please help.
May 2, 2004, 6:12 PM
CodeMaster
Perhaps a little bit of code would make it easier for us people who I might remind you are not psychics.

Edit: Usually when you receive Subscript out of range when using an array, you are referring to an array variable that hasn't been declared as anything. This usually happens when using Split().
May 2, 2004, 6:17 PM
Learn
Sorry. Heres some of the code:

Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long)
Dim i&
Dim a
Dim e
Dim p
sckBNET.GetData s, vbString
a = Split(s, Chr(13))
For i = LBound(a) To UBound(a)
If Left(a(i), 1) = Chr(10) Then a(i) = Right(a(i), Len(a(i)) - 1)
e = Split(a(i), Chr(32), 1)
Select Case e(0)
Case "1001"
p = Split(a(i), Chr(32), 5)
p(4) = Mid(p(4), 2, Len(p(4)) - 2)
AddChat vbYellow, p(2) & " is in the channel."
Case "1002"
p = Split(a(i), Chr(32), 5)
p(4) = Mid(p(4), 2, Len(p(4)) - 2)
AddChat vbGreen, p(2) & " joined the channel."
Case "1003"
p = Split(a(i), Chr(32), 3)
AddChat vbRed, p(2) & " left the channel."
Case "1004"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<From: " & p(2) & "> ", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
Case "1005"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & "> ", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
Case "1007"
p = Split(a(i), Chr(32), 2)
'Mid(p(2), 2, Len(p(2)) - 2) Channel
Case "1009"
p = Split(a(i), Chr(32), 3)
'p(2) Flags
Case "1010"
p = Split(a(i), Chr(32), 4)
AddChat vbCyan, "<To: " & p(2) & "> ", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
Case "1018"
p = Split(a(i), Chr(32), 2)
AddChat vbYellow, Mid(p(2), 2, Len(p(2)) - 2)
Case "1019"
p = Split(a(i), Chr(32), 2)
AddChat vbRed, "Error: " & Mid(p(2), 2, Len(p(2)) - 2)
Case "1023"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
Case "2000"
'
Case "2010"
p = Split(a(i), Chr(32), 2)
'p(2) Logon
Case Else
'
End Select
Next i
End Sub
May 2, 2004, 6:18 PM
CodeMaster
On first look I can see that e is not declared as an array
Dim e() As String or w/e would work, same would apply to a and p

Edit: Is that the problem???
May 2, 2004, 6:21 PM
Learn
Ok, well i fixed the Dim a(and e and p as well) As String, but now im getting:

Compile Error:

Expected Array.

bah ><

Edit: Yea the Dim a+e+p As String worked but now im getting the above error.
May 2, 2004, 6:26 PM
CodeMaster
Does it point to any specific point of your code?
May 2, 2004, 6:27 PM
Learn
Yea sorry, forgot that:

Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long)


Edit: Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long) is highlighted in yellow

and

For i = LBound(a) To UBound(a)
the LBound is highlighted in blue
May 2, 2004, 6:28 PM
LoRd
It most likely means that e(0) does not contain any and/or enough information required to finish the process.
May 2, 2004, 8:26 PM
Grok
[quote author=Learn link=board=31;threadid=6622;start=0#msg58118 date=1083522506]
Yea sorry, forgot that:

Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long)


Edit: Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long) is highlighted in yellow

and

For i = LBound(a) To UBound(a)
the LBound is highlighted in blue
[/quote]

Your variable a is not an array. Declare it as an array.
Dim a() As (appropriate datatype here)
May 2, 2004, 10:09 PM
Learn
Ok, this issue has been resolved.

I used the InStr command to solve it.

But now once i connect my bot using VB the Chattering in the channel doesn't show up on my screen, I can't join channels either. But i CAN whisper people. Also, when i try to type any of the commands you'd normally use on a Client, i hear a beep and nothing happens.

Would you need to see the code to see what is wrong? If so i'll edit this and put it in.

(this is just a Chat Bot, I know that it cant join private channels so that isnt my problem with the joining channels.)

Edit: I can also enter text to B.net through the bot, but again the text doesn't show up on the screen.

Code:

[code]Private Sub sckBNET_DataArrival(ByVal bytesTotal As Long)
Dim i&
Dim a() As String
Dim e() As String
Dim p() As String
sckBNET.GetData s, vbString
a = Split(s, Chr(13))
For i = LBound(a) To UBound(a)
If Left(a(i), 1) = Chr(10) Then a(i) = Right(a(i), Len(a(i)) - 1)
If InStr(1, a(i), Chr(32)) > 0 Then
e = Split(a(i), Chr(32), 1)
Else
ReDim e(0)
e(0) = a(i)
End If
Select Case e(0)
Case "1001"
p = Split(a(i), Chr(32), 5)
p(4) = Mid(p(4), 2, Len(p(4)) - 2)
AddChat vbYellow, p(2) & " is in the channel."
Case "1002"
p = Split(a(i), Chr(32), 5)
p(4) = Mid(p(4), 2, Len(p(4)) - 2)
AddChat vbGreen, p(2) & " joined the channel."
Case "1003"
p = Split(a(i), Chr(32), 3)
AddChat vbRed, p(2) & " left the channel."
Case "1004"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
Case "1005"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
Case "1007"
p = Split(a(i), Chr(32), 2)
'Mid(p(2), 2, Len(p(2)) - 2) Channel
Case "1009"
p = Split(a(i), Chr(32), 3)
'p(2) Flags
Case "1010"
p = Split(a(i), Chr(32), 4)
AddChat vbCyan, "<To:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
Case "1018"
p = Split(a(i), Chr(32), 2)
AddChat vbYellow, Mid(p(2), 2, Len(p(2)) - 2)
Case "1019"
p = Split(a(i), Chr(32), 2)
AddChat vbRed, "Error: " & Mid(p(2), 2, Len(p(2)) - 2)
Case "1023"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
Case "2000"
'
Case "2010"
p = Split(a(i), Chr(32), 2)
'p(2) Logon
Case Else
'
End Select
Next i
End Sub[/code]
May 2, 2004, 11:30 PM
hismajesty
For not seeing messages: Post your parse code.
For the beep: (assuming) you're hearing it when you press enter you have to do this:

[code]If Keyascii = 13 Then
Keyascii = 0 'Stop beep
'The rest of the stuff[/code]
May 2, 2004, 11:33 PM
Learn
Uhh your code is slightly different then mine:

heres mine:

[code]Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = ""
End If[/code]

and i'll edit the above post with the code
May 2, 2004, 11:40 PM
Eli_1
'Stop beep is a comment, it is simply explaining what that line of code does.
To stop the beep you put
[code]KeyAscii = 0[/code]
after your if statement.

[Edit] On a side note, try to get into the habit of putting [ code ] [ /code ] tags around code you post.

[Edit again!] Your variable names are horrible, try to use less cryptic variable names. For instance, you used s as one of your strings. Using something like MessageBuffer would be much better and easier to understand.
May 2, 2004, 11:48 PM
Learn
::)Thanks Eli_1

And why do i put [code] [/code] around the code i post?

Can't i just click the little box that says "Check this if you'll be adding code (or don't like smilies).

Edit: OOOH I see. I'll do that now.

Edit to Eli_1's edit: I don't understand. Whats MessageBuffer?

:-[ :'( ::)
May 2, 2004, 11:51 PM
hismajesty
I was just posting the relevant code.

[code]
Private Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = vbNullString
End If
End Sub
[/code]

using the [ code] and [ /code] tags just makes the code easier to read.

He was just mentioning that you need to use more meaningful variable names.

Use vbNullString instead of "" so it doesn't take up space in the memory.
May 3, 2004, 1:42 AM
Learn
Thanks, but can anyone help me with my problem?
May 3, 2004, 3:30 AM
hismajesty
[quote author=Learn link=board=31;threadid=6622;start=15#msg58213 date=1083555011]
Thanks, but can anyone help me with my problem?
[/quote]

You posted that it was resolved.
May 3, 2004, 9:06 PM
Learn
[quote]Ok, this issue has been resolved.

I used the InStr command to solve it.

But now once i connect my bot using VB the Chattering in the channel doesn't show up on my screen, I can't join channels either. But i CAN whisper people. Also, when i try to type any of the commands you'd normally use on a Client, i hear a beep and nothing happens.
[/quote]

That problem
May 4, 2004, 12:58 AM
Eli_1
Are you appending vbCrLf to the end of the text you send?
May 4, 2004, 1:42 AM
Learn
Please use an example of what you mean, because i really dont KNow what u mean.


p.s. : nice avatar ATHF rocks =]
May 4, 2004, 12:13 PM
Eli_1
[quote author=Learn link=board=31;threadid=6622;start=15#msg58405 date=1083672837]
Please use an example of what you mean, because i really dont KNow what u mean.


p.s. : nice avatar ATHF rocks =]
[/quote]

[code]
Const VK_RETURN = 13
If KeyAscii = VK_RETURN Then
WinSock.SendData txtInput.Text & vbCrLf
'/* Notice I'm putting vbCrLf on the end of the text :O */

DoEvents
'/* DoEvents isn't needed. I use it
'** because on one of my really old
'** computers it won't send if I leave DoEvents
'** out. Btw, these are all comments, learn. */

KeyAscii = 0 '// Don't beep -.-
End If
[/code]

P.S. LOL, finally someone recognizes the character. ATHF def. rocks. :)


May 4, 2004, 6:47 PM
Learn
Ok I know what a comment is I'm not THAT much of a newb with VB. but thanks for the vbCrLf tip i didn't know that.
May 4, 2004, 8:57 PM
Eli_1
[quote author=Learn link=board=31;threadid=6622;start=15#msg58470 date=1083704234]
Ok I know what a comment is I'm not THAT much of a newb with VB. but thanks for the vbCrLf tip i didn't know that.
[/quote]
Last post I read, someone thought the comment was code. I thought it might have been you, so I put that in there to make sure I didn't confuse you.
May 4, 2004, 9:23 PM

Search