• Welcome to Valhalla Legends Archive.
 

Ping

Started by Hidden, January 11, 2005, 06:58 AM

Previous topic - Next topic

Hidden

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.

Kp

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Meh

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

R.a.B.B.i.T

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).

CrAz3D

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.)
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Arta

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.

CrAz3D

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?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

R.a.B.B.i.T

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.

Zakath

VB doesn't, Windows does. /quibble
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

Hidden

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.

Meh

You just indent it.

Hidden

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?

dxoigmn

#12
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

Hdx

#13

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 >.<

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

R.a.B.B.i.T

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.