I've recently started programming with VB and I really don't understand everything yet. And this error is baffling me.
Heres the details. I can type on the bot and send it to Bnet (it shows up in channel and i can whisper people) but i cant join channels with the /join command and i cant see the people chatting in Public Chat 1 (this is just a chat bot, I haven't gotten to the complexities of hashes yet) Also, nothing shows up in the Rich Text Box except "Connecting..." and "Connected as 'username' " but thats not Bnet.
Anyway here's the relevant 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."
'p(2) in 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."
'Join // p(2) joined channel
Case "1003"
p = Split(a(i), Chr(32), 3)
AddChat vbRed, p(2) & " left the channel."
'Left // p(2) left Channel
Case "1004"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
'Whisper From
Case "1005"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
'User // p(2) Message
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)
'Whisper to
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)
'Error
Case "1023"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
'Emote
Case "2000"
'
Case "2010"
p = Split(a(i), Chr(32), 2)
'p(2) Logon
Case Else
'
End Select
Next i
End Sub
Also, I'm getting the error "Next without for" any suggestions?
And thanks for any help.
Quote from: Learn on May 03, 2004, 03:11 PM
I've recently started programming with VB and I really don't understand everything yet. And this error is baffling me.
Heres the details. I can type on the bot and send it to Bnet (it shows up in channel and i can whisper people) but i cant join channels with the /join command and i cant see the people chatting in Public Chat 1 (this is just a chat bot, I haven't gotten to the complexities of hashes yet) Also, nothing shows up in the Rich Text Box except "Connecting..." and "Connected as 'username' " but thats not Bnet.
Anyway here's the relevant code:
Also, I'm getting the error "Next without for" any suggestions?
And thanks for any help.
You're missing an End If
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."
'p(2) in 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."
'Join // p(2) joined channel
Case "1003"
p = Split(a(i), Chr(32), 3)
AddChat vbRed, p(2) & " left the channel."
'Left // p(2) left Channel
Case "1004"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
'Whisper From
Case "1005"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
'User // p(2) Message
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)
'Whisper to
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)
'Error
Case "1023"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
'Emote
Case "2000"
'
Case "2010"
p = Split(a(i), Chr(32), 2)
'p(2) Logon
Case Else
'
End Select
Next i
Should be
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."
'p(2) in 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."
'Join // p(2) joined channel
Case "1003"
p = Split(a(i), Chr(32), 3)
AddChat vbRed, p(2) & " left the channel."
'Left // p(2) left Channel
Case "1004"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<From:" & p(2) & ">", vbgray, Mid(p(4), 2, Len(p(4)) - 2)
'Whisper From
Case "1005"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & ">", vbWhite, Mid(p(4), 2, Len(p(4)) - 2)
'User // p(2) Message
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)
'Whisper to
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)
'Error
Case "1023"
p = Split(a(i), Chr(32), 4)
AddChat vbYellow, "<" & p(2) & " " & Mid(p(4), 2, Len(p(4)) - 2) & ">"
'Emote
Case "2000"
'
Case "2010"
p = Split(a(i), Chr(32), 2)
'p(2) Logon
Case Else
'
End Select
End If
Next i
I'm sure the tabbing isn't correct but, whatever.
Hope this helps you :)
Edit-> I think I made a mistake, yes I did. Fixed.
Edit-> Removed Code from his quote.
What about the first problem?
For the joining channels part, sending text and joining channels are two completely different events, so it makes sense you aren't joining channels when you send the command if all your sending is text (Note: This is AFAIK...).
I don't quite remember if you have to send something before this, but if you refer to BnetDocs, you see there is a packet labeled SID_JOINCHANNEL. It is sent from the client (you) to the server (bnet).
Quote(DWORD) Flags
(STRING) Channel
That's the structure of 0x0C, SID_JOINCHANNEL. To join channels, send that with the appropriate information.
Hope that helped, if only slightly.
Note: At the time I'm writing this I am assuming your simply sending 0x0E with just text, and further assuming that joining channels using /rejoin doesn't work that way. So far I've used JOINCHANNEL, it seemed common sense at the time.
Looks like a chat connection to me. Not a binary one.
Yea, It's a chat bot. I don't know binary.
To join a channel you would just do something like:
Socket.SendData "/join " & ChannelNameStoredHere vbCrLf
DoEvents '// DoEvents is optional...
Thanks Eli_1
ATHF owns =]
Here's the module code maybe this will help more:
Public Sub AddChat(ParamArray saElements() As Variant)
On Error Resume Next
Dim i As Integer
If Len(frmMain.rtbChannel) > 50000 Then
frmMain.rtbChannel.Text = ""
AddChat vbYellow, "Chat screen auto cleared!"
End If
With frmMain.rtbChannel
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = vbWhite
.SelText = "[" & Format(Time, "hh:mm:ss") & "] "
.SelStart = Len(.Text)
End With
For i = LBound(saElements) To UBound(saElements) Step 2
With frmMain.rtbChannel
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(i)
.SelText = saElements(i + 1) & Left$(vbCrLf, -2 * CLng((i + 1) = UBound(saElements)))
.SelStart = Len(.Text)
End With
Next i
End Sub
by the way the
sckBNET.SendData "/join & ChannelNameStoredHere & "
DoEvents '// DoEvents is optional...
End Sub
didnt work
Quote from: Learn on May 04, 2004, 03:39 PM
Thanks Eli_1
ATHF owns =]
Here's the module code maybe this will help more:
Public Sub AddChat(ParamArray saElements() As Variant)
. . . <code block>
End Sub
by the way the
sckBNET.SendData "/join & ChannelNameStoredHere & "
DoEvents '// DoEvents is optional...
End Sub
didnt work
That's because the code I gave you wasn't
sckBNET.SendData "/join & ChannelNameStoredHere & "
DoEvents '// DoEvents is optional...
End Sub
It's suppost to be
sckBNET.SendData "/join " & ChannelNameStoredHere & vbCrLf
Where 'ChannelNameStoredHere' is a String which has a channel name as it's value. You won't be able to join private channels, so make sure it's something like "Public chat ub3r hax0r".
And as for the AddChat code, I've never used .SelLength = 0 before. So try removing those. And try calling it like this once:
Dim blah(1)
blah(0) = RGB(0, 255, 0)
blah(1) = "This is a test."
AddChat blah
Edit: Also, eww@On Error Resume Next. Try to get into the habit of checking for errors and handling them as needed, as opposed to just ignoring them.
Eh, modify it so the quotes aren't around the variable name.
'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere
DoEvents
edit: /me = too slow :P
Quote from: Dyndrilliac on May 04, 2004, 04:00 PM
Eh, modify it so the quotes aren't around the variable name.
'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere
DoEvents
You have to make sure you append vbCrLF onto the end of it. If you don't, battle.net will assume you have more data to send to it. I believe this is so people can use telnet to log onto the server, because vbCrLf (carriage return -- \r\n?) won't be sent untill enter is pressed.
Telnet sends the data you input as you input it. Bnet needs to wait for the carriage return, or the output would look like this.
Quote
<Eli_1> /
<Eli_1> j
<Eli_1> o
<Eli_1> i
<Eli_1> n
<Eli_1>
ect...
'Pseudo Code
sckBnet.SendData "/join " & ChannelVariableNameHere & vbCrLF
'// bwahaha, I'm way too fast for you, Dynd. :P
DoEvents
Edit: What does CrLf stand for?
Carriage Return ________ ________
Carriage Return Line Feed??
Ok, I did:
Dim blah(1)
blah(0) = RGB(0, 255, 0)
blah(1) = "This is a test."
AddChat blah
And I got:
Compile Error:
Duplicate declaration in certain scope.
LoL, I think that would mean you have a variable named blah already. Use something other than blah(), it was just an example. blah2 perhaps?
Holyshit.. I just hit connect on my bot and the screen filled with the time thing( [HH:MM:SS] not the H,M,S things but the actual time), and VB froze. :o
Edit: If ChannelVariableNameHere is a string, shouldn't i dim it is a string?
Quote
Edit: If ChannelVariableNameHere is a string, shouldn't i dim it is a string?
Of course... ::)
Ok is this fine? :
Dim ChannelVariableNameHere As String
sckBNET.SendData "/join " & ChannelVariableNameHere & vbCrLf
DoEvents
No. The channelname string needs to contain some channel name. That right there would send:
"/join " & vbCrLf.
Before you send it you need to set ChannelVariableNameHere to something.
ChannelVariableNameHere = "Public Chat Drop"
Oh yea, forgot that.
Dim Channel As String
Channel = Public_Chat_John
sckBNET.SendData "/join " & Channel & vbCrLf
DoEvents
Is that ok?
No man. Public_Chat_John is undefined. You need to use quotes. Use "Public Chat Drop".
Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go?
And i keep getting "Next without for" error with this codPrivate Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 'No Beep
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = ""
Const VK_RETURN = 13
If KeyAscii = VK_RETURN Then
Winsock.SendData txtSend.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. */
End If
Next i
End Sub
Quote from: Learn on May 04, 2004, 04:53 PM
Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go?
And i keep getting "Next without for" error with this codPrivate Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 'No Beep
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = ""
Const VK_RETURN = 13
If KeyAscii = VK_RETURN Then
Winsock.SendData txtSend.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. */
End If
Next i
End Sub
1.) You have code that does the same thing twice.
2.) You have Next i, when there is no For loop starting it (delete Next i).
3.) You're missing an End If.
delete:
If KeyAscii = 13 Then
KeyAscii = 0 'No Beep
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = ""
You put the join channel code anywhere you want. I would put it in the sckBNET_Connect() event so that your bot joins a "home" channel when it logs on.
DAMMIT!!!!!!!! SO CONFUSED
Private Sub mnuFileConnect_Click()
sckBNET.Connect "useast.battle.net", 6112
AddChat vbYellow, "Connecting..."
Next i
Dim Channel As String
Channel = "Public Chat John"
sckBNET.SendData "/join " & Channel & vbCrLf
DoEvents
End Sub
"Next without for" error
Jesus christ, could you explain to me where/when i put "End If" and "Next i"
You only need an End If if you have an if statement.
Example:
If Username = "asdfasdf" Then
'do stuff
End if
You only need a Next i if you have a for loop that uses the variable i.
Example:
Dim i as integer
for i = 1 to 10
msgbox "MerF?!", vbOKOnly, "NerFFF?!"
next i
And you can't join a channel untill you log in. There should be a function called sckBNET_Connect(). That function is called when the socket connects to the server. Similar to how sckBNET_Close() and sckBNET_Error() will be called when you are disconnected.
In sckBNET_Connect() you would put your log in code and the join channel code.
Example:
Private Sub sckBNET_Connect()
With sckBNET
.SendData Chr(3) & Chr(4) & "John" & vbCrLf
'/* This will send the protocol byte 0x03 (CHAT)
'** It will also send 0x04 with it.
'** This will disable echo, so the server doesn't
'** echo back what you send it (for telnet). */
.SendData "ub3rleet" & vbCrLf
'/* This will send your password to the server.
'** which in this example is 'ub3rleet'. */
Dim HomeChannel as String '// Your home channel
HomeChannel = "Public Chat Drop" '// Set home channel
.SendData "/join " & HomeChannel & vbCrLf
'/* This will send the join command with
'** with the parameter 'Public Chat Drop' to
'** the server. You could accomplish the same
'** thing by simply doing:
'**
'** .SendData "/join Public Chat Drop" & vbCrLf
'*/
End With
'/* We need an End With because we used With at the
'** top. Similar to how we need End Sub, because we
'** have 'Private Sub ..." at the top. */
End Sub
All the comments might make it look intimidating to you, so I'll take them out so you can see what it looks like w/o them. At least read through them though, because they explain why the code works.
Exact same code without comments:
Private Sub sckBNET_Connect()
With sckBNET
.SendData Chr(3) & Chr(4) & "John" & vbCrLf
.SendData "ub3rleet" & vbCrLf
Dim HomeChannel as String
HomeChannel = "Public Chat Drop"
.SendData "/join " & HomeChannel & vbCrLf
End With
End Sub
Quote from: Learn on May 04, 2004, 04:53 PM
Ok, sorry if I'm annoying you, but where does the Dim ChannelNameVariable as String blah blah blah go?
And i keep getting "Next without for" error with this codPrivate Sub txtSend_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 'No Beep
sckBNET.SendData txtSend.Text & vbCrLf
txtSend.Text = ""
Const VK_RETURN = 13
If KeyAscii = VK_RETURN Then
Winsock.SendData txtSend.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. */
End If
Next i
End Sub
I would strongly suggest learning more about VB and how it works before you continue any further. Get a book or visit a few online tutorials.
Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good?
But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing?
sckBNET_Connect() is not a connect command, god damnit. It is an event winsock calls when it is connected to the server. If you try sending data before your connected, you'll get pretty errors.
I'm trying to be as helpful as I possibly can. But now I'm starting to think you never read anything I took the time to type for you, because if you did, you'd know you can't. And you'd also know before trying to join a channel you need to send the protocol byte for CHAT(3) and then log in.
Anyway, I'm done. Good luck to you.
Quote from: Learn on May 04, 2004, 05:43 PM
Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good?
But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing?
Yes it was and yes he does.
I also suggest you learn the language before writing a bot. Your skipping learning your ABC's to being an english professor at Harvard.
Thanks for all your help Eli_1.
Nice metaphor Dyndrilliac. How do you suggest learning the language? Do you know any good sites? A title to a good book, perhaps? If so any info would be much appreciated.
Also, I've searched for tutorials online, none of the free ones are good, that I've found.
Quote from: Learn on May 04, 2004, 05:43 PM
Hi, Stealth you make ownage bots.. wanna help me? =]] and Stealth do you know VB? Was Stealthbot programmed with VB? And if you do know VB how did you learn? Trial and Error? Book? Teacher? And do you suggest a book that you know is good?
But Eli_1 i already have a connect command, isnt there i way to join a home channel afer connecting with my mnuFile_Connect thing?
I took a class last year in school that taught VB. It was based on a book, exactly which one I forget. Grok has posted a link to Bruce McKinney's Hardcore Visual Basic, which looks like a very good source of information. Search the forums Bruce McKinney and see what you find.
I also took Introduction to Programming in 9th grade. The book we used was:
Visual Basic 6 How to Program
Deitel & Deitel T.R. Nieto
www.deitel.com
www.programmingtutorials.com
Anything for advanced programmers? I still don't know quite everything yet. But I definetly know 80% of it, I think possibly more.