Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 7th, 2008, 4:24 AM   #1
Sinensis
Newbie
 
Join Date: Oct 2008
Posts: 5
Rep Power: 0 Sinensis is on a distinguished road
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 Function

Last edited by big_k105; Oct 7th, 2008 at 9:55 AM.
Sinensis is offline   Reply With Quote
Old Oct 7th, 2008, 8:39 AM   #2
cbender
Newbie
 
Join Date: Oct 2008
Posts: 6
Rep Power: 0 cbender is on a distinguished road
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.
cbender is offline   Reply With Quote
Old Oct 7th, 2008, 9:16 AM   #3
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 254
Rep Power: 4 melbolt is on a distinguished road
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 Class


but 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 Class


btw 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
melbolt is offline   Reply With Quote
Old Oct 7th, 2008, 10:02 AM   #4
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,667
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
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.
big_k105 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC