|
-
Jun 10th, 2003, 03:46 PM
#1
Thread Starter
Addicted Member
Select case for option buttons
I have an array of 3 option buttons Option1(0), Option(1) and Option(2) and a textbox txtNum
Depending on which option button is chosen and what number is input into text box, I want to write a select case: (But I can't see where I'm going wrong! Any hints or tips folks?
Code:
Private Sub cmdSubmit_Click()
Dim Wholesale as String
Dim price As String
Dim Total As Integer
Select Case Wholesale ' Wholesale is the Caption of Option1(0)
Case "1"
If txtNumRequired <= 5 Then
price = 50
Total = txtNumRequired * price
End If
Case "2"
If txtNumRequired >= 6 And txtNumRequired <= 10 Then
price = 45
Total = txtNumRequired * price
End Select
lblDisplayType.Caption = Option1(0).Tag
lblDisplay.Caption = "You ordered " + txtNumRequired + " Items" '+ "The cost will be " + Total
lblDisplayPrice.Caption = Total
End Sub
appreciation for any comments
-
Jun 10th, 2003, 04:10 PM
#2
Hyperactive Member
Do you get any error? if yes, what it says?
Replace Wholesale with Option(0).Caption
-
Jun 10th, 2003, 04:18 PM
#3
Thread Starter
Addicted Member
I get a compile error:
End Select without select case
-
Jun 10th, 2003, 04:25 PM
#4
Hyperactive Member
Under Case "2", After the If sentence, add End If.
-
Jun 10th, 2003, 04:28 PM
#5
Thread Starter
Addicted Member
thanks for that - can't see the wood for the trees
Can u see why the total is not being displayed in the label?
-
Jun 10th, 2003, 04:31 PM
#6
Thread Starter
Addicted Member
just used step into and it is skipping the if statements - justs jumps from case 1 to case 2
-
Jun 10th, 2003, 04:34 PM
#7
Fanatic Member
I really don't understand what you are trying to do. But it will definatly skip the case statements.
You dim a variable "Wholesale" as a string. Wholesale is now an EMPTY string.
You then run select to check the contents of Wholesale to see if it is 1 or 2. It is neither. It is just an empty string.
Maybe if you explain a bit more what you are trying to do, we can help you with the code.
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Jun 10th, 2003, 04:44 PM
#8
Thread Starter
Addicted Member
2 option butts = wholesaler, retailer
1 checkbox = special customer
if option1(0) wholesaler then prices 4 item:
if buying 1 -5 item then 50.00 each
6-10 items then 45.00 each
11-20 items then 40.00
if option1(1) retailer
if buying 1 -3item then 60.00 each
4-8 items then 55.00 each
9 - 15 iems then 50.00 each
if check1 special customer then 10% discount on total
so far I have :
Code:
Option Explicit
Private Sub cmdSubmit_Click()
Dim Wholesale As String
Dim price As String
Dim Total As Integer
Select Case txtNumRequired.Text
Case Is <= 5
If txtNumRequired <= 5 Then
price = 50
Total = txtNumRequired * price
End If
Case Is > 5 ' need to say >5 and <=10 but it won't work!
If txtNumRequired >= 6 And txtNumRequired <= 10 Then
price = 45
Total = txtNumRequired * price
End If
End Select
lblDisplayType.Caption = Option1(0).Tag
lblDisplay.Caption = "You ordered " + txtNumRequired + " Items" '+ "The cost will be " + Total
lblDisplayPrice.Caption = Total
End Sub
-
Jun 10th, 2003, 04:51 PM
#9
Fanatic Member
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Jun 10th, 2003, 04:53 PM
#10
Thread Starter
Addicted Member
-
Jun 10th, 2003, 04:58 PM
#11
Fanatic Member
Some other pointers for you:
1. You set price to a string, but then assigned it a number, could cause lots of problems down the road
2. Prefix your variables! Strings should begin with str, integers should begin with int. It will keep things much easier to follow as your program grows.
3. Use Val() when reading from text boxes. If the user puts in text, it could cause problems.
4. The if statements where redundant. You already checked what txtNumRequired was in your select case statement
VB Code:
Option Explicit
Private Sub cmdSubmit_Click()
Dim strWholesale As String
Dim curPrice As Currency
Dim curTotal As Currency
Select Case Val(txtNumRequired.Text)
Case Is <= 5
curPrice = 50
curTotal = Val(txtNumRequired.Text) * curPrice
Case Is > 5, Is <= 10
intPrice = 45
curTotal = Val(txtNumRequired.Text) * curPrice
End Select
lblDisplayType.Caption = Option1(0).Tag
lblDisplay.Caption = "You ordered " + Val(txtNumRequired.Text) + " Items" '+ "The cost will be " + Total
lblDisplayPrice.Caption = curTotal
End Sub
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Jun 10th, 2003, 04:59 PM
#12
Fanatic Member
Originally posted by mbonfyre
thank you very much
You are quite welcome!
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Jun 10th, 2003, 05:07 PM
#13
Thread Starter
Addicted Member
I was just in the process of removing the if statements as I realised that they were not needed now, thanks for the tip re: prefixing variables etc. I take you point about val() - will use it and then look up what it means/how it works
God I LOVE this site and its helpful people
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|