• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Easy: Need to call class module...

For my example here...I'm working in a very simple form with one control, which is a command button for the purpose of my example.  I've created a class and gave it a name...inside the class module I need a boolean expression that will deal with the state of the command button of my form.  

When the user clicks on the command button....it should change that state to TRUE to FALSE or FALSE to TRUE.  If the value of the state is TRUE...the caption on the command button should read TRUE, if it's FALSE it should switch to FALSE.  

Not sure how the boolean should read inside the declaration of the class...also...is this a simple IF statement that calls the class, inside the click event of the Command button of my form?
0
nouellette
Asked:
nouellette
1 Solution
 
bobbit31Commented:
say your class module is named "Class1"

Private modC1 As New Class1

Private Sub Command1_Click()

modC1.blnButtonState = Not modC1.blnButtonState
MsgBox modC1.blnButtonState

End Sub

0
 
bobbit31Commented:
and in Class1 is:

Public blnButtonState As Boolean
0
 
nouelletteAuthor Commented:
Bobbit,

This doesn't really do what i need it to do...I need the state to change back and forth from TRUE to FALSE.  When I click on the command button "it's caption stars with TRUE", the caption on the command button turns to FALSE.  When I click it again, it changes back to TRUE.  I'm doing this instead of a message box so that the button is actually acting as a switch.  
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nouelletteAuthor Commented:
woops...disregard...just changed messagebox to command1.caption = modC1.buttonState.

Now...how would I apply text to the button instead of TRUE or FALSE.  Let's say the words "BLUE" and "YELLOW".  How can I toggle the caption to whatever I need it to say when the state is true or when the state is false?
0
 
DroopyACommented:
Does a command button have a True/False type value? It's either being clicked or not clicked right? But if you wanted an On/Off type of True/False wouldn't you need

Private Sub Command1_Click()
     If modC1.blnButtonState = False Then
          modC1.blnButtonState = True
          Command1.Caption = "True"
     Else
          modC1.blnButtonState = False
          Command1.Caption = "False"
     End If
End Sub

You're way is much easier bobbit, I just didn't know you could do that.

Peace
-N473
0
 
bobbit31Commented:
oh, instead of message box:

Command1.Caption = CStr(modC1.blnButtonState)
0
 
nouelletteAuthor Commented:
Thanks guys...one more question...what if I wanted one little property associated with the class such as the background color...and wanted the color to change to Red when my condition is TRUE or Orange when it's false?
0
 
bobbit31Commented:
add this to your class module:

Function getBackground() as long
   if blnButtonState then '' state is true
      getBackground = vbRed
   else
      getBackground = vbOrange
   end if
End Function

then you can do this in your form:

Command1.BackColor = modC1.getBackground
0
 
supunrCommented:
How about using a check box instead of a button.  Following is a code.

Private Sub Form_Load()
    Check1.Style = 1 'Graphical
    Check1.Caption = "FALSE"
End Sub

Private Sub Check1_Click()
    if (Check1.Value = vbChecked) then
        Check1.Caption = "TRUE"
        modModule.ButtonState = true
    else
        Check1.Caption = "FALSE"
        modModule.ButtonState = false
    end if
End Sub


' in your module called modModule...
Public ButtonState as Boolean


Good Luck!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now