|
-
Apr 2nd, 2007, 04:43 PM
#1
Thread Starter
New Member
Chess game- Referancing variables in place of objects
Hey, I'm making a Chess game using VB6 using standerd modules. So that I can use standerd modules I've set a variable called posstr1 to contain whatever the name of the space you've just cliked on is (e.g. posstr1 = "cmbA5").
Then later on in the code I'm trying to use that in my standerd modules:
If posstr1.Caption = "WP" Then movewhitepawn
So I'm expecting the computer to think posstr1= "cmbA7" (for example) and go
If cmbA7.Caption = "WP" Then movewhitepawn
(fyi movewhitepawn is another standerd module).
However, VB doesn't like this, I get 'Compile error:Invalid qualifier' and this bit highlighted. Is there actually a way to do this (referance a variable in place of an object?
Fyi, nearly everything involving variables is in public subs for now, though a way to just pass the variables and keep everything in private subs would be helpful as well.
Thanks to anyone that helps.
-
Apr 2nd, 2007, 04:56 PM
#2
Re: Chess game- Referancing variables in place of objects
Welcome to VBForums 
Assuming that cmbA7 is a object (I'm guessing a button), simply create your variable as an object too, preferably of the correct data type, eg:
vb Code:
Dim posobj as CommandButton
'or if that doesnt work, use: Dim posobj as Object
To assign the object to the variable you need to use Set, eg:
vb Code:
Set posobj = cmbA5 'note that we do not use quotes
When you have completely finished you should clear the variable too, eg:
-
Apr 2nd, 2007, 05:23 PM
#3
Thread Starter
New Member
Re: Chess game- Referancing variables in place of objects
Thank you very much, if I finish it I'll post a link here and give you a credit.
-
Apr 3rd, 2007, 04:07 AM
#4
Re: Chess game- Referancing variables in place of objects
In Lisp it would be easier, you still very good heuristic to appraise each possible move.
"The dark side clouds everything. Impossible to see the future is."
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
|