?
Solved

Easy:  Need to call class module...

Posted on 2003-03-17
9
Medium Priority
?
197 Views
Last Modified: 2010-05-01
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
Comment
Question by:nouellette
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 200 total points
ID: 8154361
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8154366
and in Class1 is:

Public blnButtonState As Boolean
0
 
LVL 3

Author Comment

by:nouellette
ID: 8154610
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
Independent Software Vendors: 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!

 
LVL 3

Author Comment

by:nouellette
ID: 8154625
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
 

Expert Comment

by:DroopyA
ID: 8154629
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8154637
oh, instead of message box:

Command1.Caption = CStr(modC1.blnButtonState)
0
 
LVL 3

Author Comment

by:nouellette
ID: 8154832
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
 
LVL 18

Expert Comment

by:bobbit31
ID: 8154869
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
 
LVL 11

Expert Comment

by:supunr
ID: 8155722
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question