Guess can't do this in Visual Basic

Started by
6 comments, last by Topgoro 23 years, 9 months ago
Hi all. Instead of doing a huge if "if object1 is object2" etc, do (this or something to this effect): select object1 case is object2 etc... Please, correct me if wrong, thank you. Topgoro
We emphasize "gotoless" programming in this company, so constructs like "goto hell" are strictly forbidden.
Advertisement
quote:Original post by Topgoro

Hi all.

Instead of doing a huge if "if object1 is object2" etc,

do (this or something to this effect):

select object1
case is object2
etc...

Please, correct me if wrong, thank you.

Topgoro


There shouldn''t be any problems. I''ve done Select Case lots of times. Mainly for grouped radio buttons. Look in the VB Help files under "Select" keyword.


B e S
It's Da BOMB Baby!!!
BeSIt's Da BOMB Baby!!!. o O ~ A little nonsense now and then,is relished by the wisest men~ O o .-- Willy Wonka
Select Case Object1
Case Is = Object2
etc..
End Case


I think that''s how you do it.
(I''m using VB6, you might be different?)
Online RPGs.. Almost like another life! Except for whenswitching back to real life, sometimes I forget there isn'ta profanity filter..
Woah...you learn something new every day!

I ran into this problem a few times before and had to work around it. I guess Select Case it is then.

------------------------
Captured Reality
From what I know, it''s:

Select Case Object1

Case Object2: (Do something)

End Select
What exactally does it check though? Does it check if they are both the same type of object or if they are the same exact object?

------------------------
Captured Reality
I use VB5 and it''s probably not a good idea to do:

Select Case Object1
Case Object2: ...
Case Object3: ...
End Select

for the reason that I don''t believe it is comparing objects, but the default property (if you have set one).

Rather, you can do something like:

Select Case ObjPtr(Object1)
Case ObjPtr(Object2): ...
Case ObjPtr(Object3): ...
End Select

Where ObjPtr is a hidden function in VB. There is also StrPtr and VarPtr. Open the Object Browser, right click for the popup menu and select "Show Hidden Members". Sadly there''s nothing else of much interest that''s hidden...

I suspect if the Select works for VB6 then it is comparing the object, not the class of object.
quote:Original post by TPH

I use VB5 and it''s probably not a good idea to do:

Select Case Object1
Case Object2: ...
Case Object3: ...
End Select

for the reason that I don''t believe it is comparing objects, but the default property (if you have set one).

Rather, you can do something like:

Select Case ObjPtr(Object1)
Case ObjPtr(Object2): ...
Case ObjPtr(Object3): ...
End Select

Where ObjPtr is a hidden function in VB. There is also StrPtr and VarPtr. Open the Object Browser, right click for the popup menu and select "Show Hidden Members". Sadly there''s nothing else of much interest that''s hidden...

I suspect if the Select works for VB6 then it is comparing the object, not the class of object.


Hi all.

Thank you very much for your response

I tried the first case in VB 6 SP3 and it did not work. How ever, I tried using the ObjPtr function and it worked as expected. Too bad I still can''t use it in Sax BASIC.

Topgoro

This topic is closed to new replies.

Advertisement