![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2008
Posts: 5
Rep Power: 0
![]() |
Select...Case help *urgent*
I am trying to make a function that performs the following:
If I enter "SAVE20P" it will take a subtotal from elsewhere, multiply it by 1.2, and return a value that will later be subtracted from the subtotal. If I enter "SAVE50D" it should return the value 50 as the discount amount and that will be later subtracted from a subtotal. I thought using Select...Case would be my best bet though for some reason I can't get it to work. Here is what I have so far: I am calling it with GetDiscount(tbxDiscode.Text, sngDiscount, sngSubtotal
Private Function GetDiscount(ByVal strDiscode As String, ByVal sngDis As Single, ByVal sngSubt As Single)
Select Case strDiscode
Case "SAVE20P"
sngDis = sngSubt * 1.2
Case "SAVE50D"
sngDis = 50
End Select
End FunctionLast edited by big_k105; Oct 7th, 2008 at 9:55 AM. |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Oct 2008
Posts: 6
Rep Power: 0
![]() |
Re: Select...Case help *urgent*
I don't know VB, am a .net C# guy...but do you need " : " after your case? I think you may also want break points. Here's how it would look in C#
private void GetDiscount(string strDiscode, float sngDis, float sngSubt) {
switch (strDiscode) {
case "SAVE20P":
sngDis = (sngSubt * 1.2);
break;
case "SAVE50D":
sngDis = 50;
break;
}
}Does your code compile when you build the page/project? Last edited by big_k105; Oct 7th, 2008 at 10:02 AM. |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Feb 2005
Location: PA, USA
Posts: 254
Rep Power: 4
![]() |
Re: Select...Case help *urgent*
I would probably do it somewhere along the lines of this
Public Class Form1
Enum strDiscodeEnum
SAVE20P
SAVE50D
End Enum
''' <summary>
''' Button1 click event handler
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' just a variable to hold the value returned from our function
Dim ValueToBeSubtractedFromSubTotal As Single
ValueToBeSubtractedFromSubTotal = GetDiscount(strDiscodeEnum.SAVE20P)
'display result in a messagebox
MsgBox(ValueToBeSubtractedFromSubTotal)
End Sub
Private Function GetDiscount(ByVal strDiscode As strDiscodeEnum) As Single
Select Case strDiscode
Case strDiscodeEnum.SAVE20P
Return CType(txtValueFromElsewhere.Text, Single) * 1.2
Case strDiscodeEnum.SAVE50D
Return 50
End Select
End Function
End Classbut for the sake of your homework, you can do something like this Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' just a variable to hold the value returned from our function
Dim ValueToBeSubtractedFromSubTotal As Single
ValueToBeSubtractedFromSubTotal = GetDiscount("SAVE20P")
'display result in a messagebox
MsgBox(ValueToBeSubtractedFromSubTotal)
End Sub
Private Function GetDiscount(ByVal strDiscode As String) As Single
Select Case strDiscode
Case "SAVE20P"
Return CType(txtValueFromElsewhere.Text, Single) * 1.2
Case "SAVE50D"
Return 50
End Select
End Function
End Classbtw txtValueFromElsewhere is just a textbox on my form in which the user would enter something like 2.34 you were on the right track, which is why I am helping you, even though we usually don't help out very much with assignments around here, if you show you are trying and actually make an attempt, people will help.
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
|
|
#4 |
|
PFO Founder
![]() ![]() |
Re: Select...Case help *urgent*
Are you getting any kind of errors?
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB Phone Number to Name... | NDawg28 | Visual Basic | 9 | Mar 10th, 2007 10:40 PM |
| Custom Case Ideas | Indigno | Coder's Corner Lounge | 18 | Aug 10th, 2006 7:13 PM |
| reloading html select boxs...is there a better way? | MegaArcon | Python | 13 | May 26th, 2006 4:06 AM |
| my Calculator | layer | Other Scripting Languages | 4 | Mar 9th, 2005 8:09 PM |
| HELP!!! Implementing Case function into JList/ArrayList | c1ph3r | Java | 1 | Feb 25th, 2005 7:48 PM |