-
Aug 5th, 2005, 10:21 AM
#1
Thread Starter
Lively Member
[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
-
Aug 5th, 2005, 10:24 AM
#2
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:
Function ItemExists(col As Collection, itemName As String) As Boolean
On Error GoTo Err
Dim test As String
test = col.Item(itemName)
ItemExists = True
Exit Function
Err:
ItemExists = False
End Function
So you would use it like:
VB Code:
If ItemExists(colBots, CStr(sckListenSock.RemoteHostIP)) Then
' it exists!
Else
'it doesnt!
End If
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Aug 5th, 2005, 10:49 AM
#3
Re: 'Is Not Nothing' problems
Here is how to do the Is Not Nothing if statement
VB Code:
If Not colBots.item(sckListenSock.RemoteHostIP) Is Nothing then
' Do stuff
end if
-
Aug 5th, 2005, 11:16 AM
#4
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|