Checking if an object is loaded?

Hi,
I want to know how I can check if an object is loaded or not! The object I am using is a WinSock control. Is there any API or something else that I can check if it is loaded or not?
ismohamedAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
One solution would be to try to access the object and see if a error occurs. Like this

On Error Resume Next
Winsock.Left = 0   'whatever you want to do..
If Err Then
   '(Edited by Computer101) Errors have happened (i think 'object does not exist' is error code 324)
End If


or..


On Error Goto ObjectDoesNotExist
Winsock.Left = 0   'whatever you want to do..
..
..
..
ObjectDoesNotExist:
  '(Edited by Computer101) Error have happened, object might not exist (Error code 324 i think)

0
ismohamedAuthor Commented:
Hmm, I want to avoid using the error handler! I have seen a function that can do this! It is because that I am in a for loop! And I have an array of these WinSockets! The next element in my array may be loaded!

0
amebaCommented:
' add control array of 3 buttons to your form
' set button indices to 0, 1, 5
Option Explicit

Private Sub Form_Click()
    Dim i As Integer
    For i = 0 To 5
        Dim x As Variant
        Set x = Command1(i)
        If VarType(x) = vbBoolean Then
            Print i & " OK"
        ElseIf VarType(x) = vbObject Then
            Print i & " does not exist"
        End If
    Next
End Sub
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ismohamedAuthor Commented:
Did not work with a winsocket control.
0
ismohamedAuthor Commented:
Get your points vbmaster!!!
I used your first eg and it works as I would like it to work
0
amebaCommented:
I tested this with winsock control (small modification was needed):

' add control array of 3 winsock controls to your form
' set winsock indices to 0, 1, 5
Option Explicit

Private Sub Form_Click()
    Dim i As Integer
    For i = 0 To 5
        Dim x As Variant
        Set x = Winsock1(i)
        If VarType(x) = vbObject Then
            Print i & " does not exist"
        Else
            Print i & " OK"
        End If
    Next
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ismohamedAuthor Commented:
Exactly what I was lloking for Thanx
0
amebaCommented:
Thanks. You can also skip declaration for x and use:
If VarType(Winsock1(i)) = vbObject Then
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.