Results 1 to 4 of 4

Thread: [RESOLVED] 'Is Not Nothing' problems

  1. #1

    Thread Starter
    Lively Member Tw1sted L0gic's Avatar
    Join Date
    Jan 2005
    Posts
    88

    Resolved [RESOLVED] 'Is Not Nothing' problems

    I'm trying to see if an element of a collection doesnt exist.

    If colBots.item(sckListenSock.RemoteHostIP) is not nothing then
    ' Do stuff
    end if

    This doesn't work! How can I make it work?

    thanks
    Naughty but Nice

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: 'Is Not Nothing' problems

    If a collection item doesn't exist, an error is thrown. This is how I used to check if variables were declared in my old Scripting Engine:
    VB Code:
    1. Function ItemExists(col As Collection, itemName As String) As Boolean
    2. On Error GoTo Err
    3. Dim test As String
    4. test = col.Item(itemName)
    5. ItemExists = True
    6. Exit Function
    7. Err:
    8. ItemExists = False
    9. End Function
    So you would use it like:
    VB Code:
    1. If ItemExists(colBots, CStr(sckListenSock.RemoteHostIP)) Then
    2. ' it exists!
    3. Else
    4. 'it doesnt!
    5. End If
    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: 'Is Not Nothing' problems

    Here is how to do the Is Not Nothing if statement

    VB Code:
    1. If Not colBots.item(sckListenSock.RemoteHostIP) Is Nothing then
    2.    ' Do stuff
    3. end if

  4. #4

    Thread Starter
    Lively Member Tw1sted L0gic's Avatar
    Join Date
    Jan 2005
    Posts
    88

    Re: 'Is Not Nothing' problems

    Excellent, I've gone with the first one.
    I thought I tried yours bruce but maybe i didnt. thanks!
    Naughty but Nice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width