Results 1 to 4 of 4

Thread: Referencing a Command Button from a module

  1. #1
    Guest

    Question

    Hi People,

    I am currently writing a Nought's and Crosses game.

    I have 9 command button's for the different parts of the board. When you click a button the program calls a procedure in another module.

    This Module will then place an X or a O in the Caption property of the button that called it.

    I can't find out how to reference the calling button's caption. I have tried passing into the module a string with the command button's name and then saying string.caption = "X", but this does not work.

    Any Idea's, Cheers ?

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    A couple of ideas actually.

    Pass a reference of the command button to the module
    Code:
    'in module
    
    private sub mySub (cmdButton as commandButton)
      'do all your stuff
      cmdButton.Caption = ? 'O or X
    End Sub
    
    
    'in button click
    Private Sub cmdButton1_Click()
      mySub cmdButton1
    End Sub
    Or return a string.
    Code:
    'in module
    
    private function myFunction () as string
      'do all you stuff
      myFunction = ? 'O or X
    End Function
    
    
    'in button click
    private sub cmdButton1_Click()
      cmdButton.Caption = myFunction
    end sub
    Hope this helps.
    Iain, thats with an i by the way!

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Commandbuttons are objects and you pass the object reference, which could either be a commandbutton or an object, not a string.

    IE:
    Code:
    Dim cbref as commandbutton
    set cbref = yourform.yourcommandbutton
    cbref.caption="X"
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Guest

    Cool

    Cheers, It think that should help me out

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