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.
Re: Chess game- Referancing variables in place of objects
Welcome to VBForums :wave:
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:
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.
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.