Hey guys, i'm having a real problem with ping, for some reason it doesn't wanna work. I have tried using Search but I couldn't find anything on it. Here is the function and command:
Function TPing(ByVal Username As String) As Long
Dim strChannel As ListItem, Ping As Long
Dim intListEnd As Integer, strCompare As String, intChecked As Integer
intListEnd = UserCount + 1
intChecked = 1
For intChecked = 1 To intListEnd
Dim l As Boolean
On Error Resume Next
strCompare = lvChannel.ListItems.Item(intChecked)
Call PrepareCheck(strCompare)
Dim UserCheck As String
UserCheck = LCase(Username)
Call PrepareCheck(UserCheck)
l = LCase(strCompare) Like UserCheck
If l = True Then
Ping = lbPing.List(intChecked - 1)
TPing = Ping
Exit Function
End If
End Function
And Command:
ElseIf intAccess >= 60 And Left((LCase(Message)), 6) = Form2.txttrigger.Text & "ping " Then
r = Right(Message, (Len(Message) - 6))
Dim ThePing As Long
ThePing = TPing(r)
If ThePing = 0 Then
Send = "I can't see " & r & " in the channel, or their ping is 0ms."
ElseIf ThePing > 0 Then
Send = r & "'s last reported ping was " & ThePing & "ms"
End If
GoTo Meh
So what m I doin wrong? :/
I got the ping to work when someone joins the channel tho, just can't get the bot to tell me one that I ask for.
Some help plz.
Quote from: Hidden on January 11, 2005, 06:58 AM
So what m I doin wrong? :/
Three things:
1) You're using VB.
2) You're using "On Error Resume Next" - this tends to hide mistakes in VB, iirc.
3) You didn't format your code, so it's a nuisance to read.
Quote from: Kp on January 11, 2005, 10:14 AM
3) You didn't format your code, so it's a nuisance to read.
Thats the worst mistake I ever made. When I began programming I didnt format and now at college I have to and its a pain as it isnt natural :P FOrmat you code and it will save a heap of time :D
Quote from: Hidden on January 11, 2005, 06:58 AM
Hey guys, i'm having a real problem with ping, for some reason it doesn't wanna work. I have tried using Search but I couldn't find anything on it. Here is the function and command:
...
So what m I doin wrong? :/
I got the ping to work when someone joins the channel tho, just can't get the bot to tell me one that I ask for.
Some help plz.
I'd also point out that you are using ElseIf-Blocks for commands, as opposed to a Select Case, and you're using a listview for storing the ping (directly on your channel list) as opposed to a separate, more manageable array (or better yet, an array of types, one index for each user storing all their information).
Why store everything twice? What if he wants to have alll the info displayed in the channellist, putting it into an array would just use more space & take him more time to do.
BUT, I do acknowledge you can put more useful stuff into an array that you wouldn't want to sit there in a channellist (ie join time, last talk time, database flags, etc.)
Because a list box is not a storage device. The list box should be an 'observer' - it should display data that is stored internally in some other form. Ideally, that data would only be resident in memory once, but if that is not possible, the sacrifice is worth it for the sake of organisation. What if you decide at some point down the linke that you'd like to store other about users? What if you decide to create a user database and would like to keep all user data centralised?
Display elements should be used for displaying things, and storage devices should be used for storing things.
Makes sense, but would you be reloading the data from the array into the list everytime it was restored from the task bar & remove it when the list isn't showing?...is that really efficent?
You don't have to clear and reload the listview every time the bot is sent and returns from the system tray, Visual BASIC automatically does this for you.
VB doesn't, Windows does. /quibble
Quote from: Kp3) You didn't format your code, so it's a nuisance to read.
Can u plz explain that concept to me? I've never done it before.
You just indent it.
Quote from: Meh on January 11, 2005, 06:05 PM
You just indent it.
Once again ur explenation crosses my Programming boundaries. Can u plz go into some detail with that?
Quote from: Hidden on January 11, 2005, 07:34 PM
Quote from: Meh on January 11, 2005, 06:05 PM
You just indent it.
Once again ur explenation crosses my Programming boundaries. Can u plz go into some detail with that?
Example (notice the comment near the bottom):
Function TPing(ByVal Username As String) As Long
Dim strChannel As ListItem, Ping As Long
Dim intListEnd As Integer, strCompare As String, intChecked As Integer
intListEnd = UserCount + 1
intChecked = 1
For intChecked = 1 To intListEnd
Dim l As Boolean
On Error Resume Next
strCompare = lvChannel.ListItems.Item(intChecked)
Call PrepareCheck(strCompare)
Dim UserCheck As String
UserCheck = LCase(Username)
Call PrepareCheck(UserCheck)
l = LCase(strCompare) Like UserCheck
If l = True Then
Ping = lbPing.List(intChecked - 1)
TPing = Ping
Exit Function
End If
Next intChecked 'AHH! No next in the code so this was a compile-time error. See how indenting allowed me to catch that?
End Function
Public Sub AddC(ParamArray saElements() As Variant)
On Error Resume Next
With rtbChat
Dim H As Integer
.SelStart = Len(.Text)
.SelColor = vbWhite
.SelText = GetTimeStamp '"[" & Time & "] "
For H = LBound(saElements) To UBound(saElements) Step 2
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(H)
.SelText = saElements(H + 1) & Left$(vbCrLf, -2 * CLng((H + 1) = UBound(saElements)))
.SelStart = Len(.Text)
Next H
End With
End Sub
VS.
Public Sub AddC(ParamArray saElements() As Variant)
On Error Resume Next
With rtbChat
Dim H As Integer
.SelStart = Len(.Text)
.SelColor = vbWhite
.SelText = GetTimeStamp '"[" & Time & "] "
For H = LBound(saElements) To UBound(saElements) Step 2
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(H)
.SelText = saElements(H + 1) & Left$(vbCrLf, -2 * CLng((H + 1) = UBound(saElements)))
.SelStart = Len(.Text)
Next H
End With
End Sub
Witch is easiyer to read AND understand the syntax?
~-~(HDX)~-~
Dang you Dxoigmn post while i was typing >.<
Even better:
Public Sub AddC(ParamArray saElements() As Variant)
On Error GoTo Handle_Err
Dim H As Integer
With rtbChat
.SelStart = Len(.Text)
.SelColor = vbWhite
.SelText = GetTimeStamp '"[" & Time & "] "
For H = LBound(saElements) To UBound(saElements) Step 2
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(H)
.SelText = saElements(H + 1) & Left$(vbCrLf, -2 * CLng((H + 1) = UBound(saElements)))
.SelStart = Len(.Text)
Next H
End With
On Error GoTo 0
Exit Sub
Handle_Err:
MsgBox "Error #" & Err.Number & vbNewLine & _
Err.Description & vbNewLine & Err.Source & _
vbNewLine & Err.Scode & vbNewLine& Err.HelpFile & _
vbNewLine & Err.HelpContext, _
vbCritical + vbOKOnly, "Error!"
End Sub
vs.
Public Sub AddC(ParamArray saElements() As Variant)
On Error Resume Next
With rtbChat
Dim H As Integer
.SelStart = Len(.Text)
.SelColor = vbWhite
.SelText = GetTimeStamp '"[" & Time & "] "
For H = LBound(saElements) To UBound(saElements) Step 2
.SelStart = Len(.Text)
.SelLength = 0
.SelColor = saElements(H)
.SelText = saElements(H + 1) & Left$(vbCrLf, -2 * CLng((H + 1) = UBound(saElements)))
.SelStart = Len(.Text)
Next H
End With
End Sub
On Error Resume Next and no error handler...eww.
I've added a handle error, i did all i could understand from what u guys said. Can someone plz gimme a similar function that would make me realise my mistake or should I just give up and ask for it? :/
I tried, and still not working :(
Hm, well you can get it to give ping for when a user joins right?
Now all you have to do is swap some things around and make it say it when you talk, i would have it like this
Dim Username as String
Username = PublicModule.KillNull(Mid(Data, 29))
If Username = EviL_MarinE And Mid(strtext,1 ,5) = frmConfig.trigger.text & "ping " then
If you dont see how i got Mid(Strtext,1, 5) then msg me
Maybe your bot isnt agreeing with whar you have said for your username or "ping" bit. go over and check it
ElseIf intAccess >= 60 And Left((LCase(Message)), 6) = Form2.txttrigger.Text & "ping " Then
That part
Make sure its telling the right thing for the bot to see
The bot agrees since i don't get an error, i just get told that my ping is 0. which it isn't. I've tried to get around using the normal Ping function to get it, but i was unsuccessful. Now what u did marine, was redo my condition a bit differently.
Quote from: CrAz3D on January 11, 2005, 12:42 PM
Makes sense, but would you be reloading the data from the array into the list everytime it was restored from the task bar & remove it when the list isn't showing?...is that really efficent?
I doubt it very much - not unless VB sucks even more than I think it does. You shouldn't ever have to entirely reload the list, unless you're clearing and repopulating it - like you would if you were moving channels. Normally, you'd just be reloading a single element, which would happen when a user joined your channel.
Making assumptions like that is unwise.
Besides which, it's using it for a purpose for which it was not designed. While it may work in specific instances, as a principle that is not a good idea.
And throughout the 21 posts I have yet to get my answer or bot working :/
Quote from: CrAz3D on January 12, 2005, 08:42 AM
So why wouldn't it be acceptable (if storing JUST ping & username) to use the channellist as a sotrage device? This is assuming that you will not add things later on.
It's much slower to access than any other list. If you make a loop through the users, checking their names against some kind of pattern match, that loop will be slower if the list is stored in a listbox than if it's in a collection or an array.
Quote from: S-1-5-<[email protected]>-501 on January 13, 2005, 10:30 AM
I just "/w *USERNAME* Ping!" to find out their ping, that way it can be done in other channels also. The ping is returned to you after whispering someone, it's so PIMP like that.
The ping is also sent to you when you join, or they join a channel. It would save a message if you just stored it into an array then.
Quote from: S-1-5-<[email protected]>-501 on January 13, 2005, 04:42 PM
That is why I mentioned the whole thing about other channels, that way I didn't look dumb like someone who doesn't read my whole post.
If they don't join your channel, or visa versa, then you don't know their ping...therefore "/w " them.
The utility of such a function is questionable, though. If you have a bot specifically for pinging other users, then great; however, if you have one bot that's responsible for maintaining order in a channel, you can pretty quickly overload its queue by having a dozen users "ping" someone all at once.
The same can happen when using the "say" command.
BTW, where did my post go to & why is it where ever it is?
Problem is that Ping cannot specify! Thats why u need the Tping. I can get the ping but I can't get who evers ping i want. So the bot doesn't read the username that i type like it does when someone joins a channel when i used the command.
This is my ping command
Case "ping"
'SendW pA(1) & "'s last reported ping was " & Form1.RoomList.FindItem(pA(1)).ListSubItems(2).text, strAccount
Queue.AddQueue "/w " & pA(1) & " Ping!"
Pinging = True
This is my WhisperTo event codePrivate Sub OnWhisperTo(ByVal Username As String, ByVal Flags As Long, ByVal Message As String, ByVal Ping As Integer)
Chat True, True, WhispNLn, "«To: " & Username & "» "
Chat False, False, WhispLn, Message
If Pinging = True Then
SendW Username & "'s ping is " & Ping, CommandName
Pinging = False
End If
Form1.VBScript.Run "OnWhisperTo", Username, Flags, Message, Ping
PL.PlugEvent "whisperto", Username, Message, Flags, Ping
End Sub
Pinging is a Public Boolean I have declared, CommandName is just something I use so I can have a whisperback command....instead of the SendW Username &...
You could just do SEND Username & "'s ping is " & ping
(Send would change depending upon how you send chat to bnet)
I really REALLy hope this helps. This way lets you see other people's ping that are in other channels, & it will give you the correct ping for whomever. Just make sure that you use the boolean thing too.
Perhaps this is an obvious question, but why're you trying so hard to incorporate a remotely queryable feature into the bot? Just modify your client to display the info natively, save you lots of trouble.
Crazed: assuming your posts were the ones screwing up the tables, that's why they vanished. People were complaining about the table mislayout you caused.
Word, that's why I changed it...started to bug me too. Now my name has spaces so it isn't a continuous name.