Results 1 to 4 of 4

Thread: Chess game- Referancing variables in place of objects

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    3

    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.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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:
    1. Dim posobj as CommandButton
    2. '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:
    1. Set posobj = cmbA5  'note that we do not use quotes
    When you have completely finished you should clear the variable too, eg:
    vb Code:
    1. Set posobj = Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    3

    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.

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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
  •  



Click Here to Expand Forum to Full Width