Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Case Module

Status
Not open for further replies.

cbruckman2006

Programmer
Joined
Feb 16, 2007
Messages
1
Location
US
I am trying to give a user the choice of adding, subtracting, multiplying or dividing 2 numbers using Select Case. I have the main code figured out but cannot figure out how I can let the user choose to do the function that hey want. It is kinda of like a calculator.
 
Select Case is for evaluating something - you wouldn't use it to allow the user to choose something. You would more likely use it to figure out what the user has chosen (through whatever user interface you've given the user to enter that data).

I was beginning to write out some example code, but the question sounds suspiciously like homework.

 
How are ya cbruckman2006 . . .

Hmmmm . . . you can write a Select Case statement but don't know how to get user input . . .

Well the field is wide open. Inputbox function, Combobox, Listbox, option group, direct reading of textboxes . . .

Calvin.gif
See Ya! . . . . . .
 
well, "kind of like a calculater" would imply,
a command button for each function (add,sub,div, mult).

Thus, in each click event of your buttons, call your Sub()
with the appropriate argument.

Private Sub cmdAdd_Click()
Call Calculate(1)
End Sub

Private Sub cmdSubtract_Click()
Call Calculate(2)
Ens Sub

Private Sub cmdMultpily_Click()
Call Calculate(3)
Ens Sub

Sub Calculate(intFunction As Integer)

Select Case intFunction
Case 1
Me.txtTotal = Me.txtFirst + Me.txtSecond
Case 2
Me.txtTotal = Me.txtFirst - Me.txtSecond
Case 3
Me.txtTotal = Me.txtFirst * Me.txtSecond


...a little primitive but, it addresses your question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top