A Digital Age Deserves A Digital Leader

Visual Basic Help

Visual Basic Help

Postby thankins » Thu Sep 18, 2003 4:06 pm

Hi guys, hopefully you can help me. I have to do this program for class and can't seem to figure out what to do. and the d*mn tutorials are helping.

Here is my problem: Create a program where user should select the package for the customer from a set of radio button and enter the number of hours used. A check box captioned "Non-Profit Organization" should also appear on the form. The application should calculate and display the total due. If the user selects "Non Profit Org" check box a 20% discount should be deducted.
Package A: 10 hours for 9.95 Addition Hours 2.00 per hour
Package B: 20 hours for 14.95 Addition Hours 1.00 per hour
Package C: Unlimted hours for 19.95


I have the layout done and all that but I dont know how to calculate the addition hours in with price. If you want I could email you the vb file and you could look at it. What should it look like

Please HELP

Travis
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

here is what I have so far

Postby thankins » Thu Sep 18, 2003 4:11 pm

Here is what I have so far for the calulate button:
I also have a const global variable called nonProfit for the 20% discount
I know what to do till I get to the question marks and then I dont know what to type, I typed what is next to ? marks from what I got from an example

Private Sub btbCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btbCalc.Click
'Claculates and displays the price for internet usage

'Declare local variables
Dim packageA As Double 'Price for Package A
Dim packageB As Double 'Price for Package B
Dim packageC As Double 'Price for Package C
Dim discount As Double 'Discount
Dim totalFee As Double 'Total Fee


'Validate the number of Hours
If Val(txtHours.Text) < 1 Or Val(txtHours.Text) > 744 Then
MessageBox.Show("Enter a vlaue in the range of 1-744 for " & _
"hours of usage.", "Input Error")
Else
'Calulates the package rate
If radPacA.Checked = True Then
packageA = 9.95
ElseIf radPacB.Checked = True Then
packageB = 14.95
ElseIf radPacC.Checked = True Then
packageC = 19.95

End If

??? 'Calculates the discount for Non Profit Org
??? If chkNonProfit.Checked = True Then
??? packageA = packageA * nonProfit
??? packageB = packageB * nonProfit
?????? packageC = packageC * nonProfit
End If


'Determines the extra charge if any
?????? Select Case Val(txtHours.Text)
Case Is > 10


End Select
End Sub
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

Help

Postby thankins » Thu Sep 18, 2003 7:53 pm

anyone? Some please help I am desperate :-?
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

Postby augie » Thu Sep 18, 2003 8:07 pm

Just be patient, a couple of knowledgeable people will be on soon. Gotta make money.
Community Director
User avatar
Posts: 7870
Joined: Mon Aug 26, 2002 1:55 am
Location: Laurentians, Quebec

thanks

Postby thankins » Thu Sep 18, 2003 8:11 pm

Thanks Auggie, I am just freaking out. Being the bad student I am, I have waited the last minute to do it, and now stressing out! But I will what and see if some of those "money makers" can help! LOL
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

Postby Weaver » Thu Sep 18, 2003 8:24 pm

Glad to see you have made it this far. I have never touched Visual Basic, so you will have to bear with me.

From what I can tell you are having problems just figuring out the final total for a given number of hours based on the specified package type. I'll go ahead and attempt one of them and that should convey an approach.

I am going to use pseudocode instead of C syntax in an effort to keep it simple.

Before I dive in, I want to comment on a few things that I have noticed thus far.

-The 9.95 for 10 hours plus $2 for each hour should all be stored in globals somewhere in case they need to be changed.

PKGA_BASE_RT = 9.95
PKGA_BASE_HRS = 10
PKGA_EXTRA_HR_RT = 2

I would do this for each of the three packages to some extent. It will impress (the teacher) and it is considered good practice.

Let's begin (pseudocode remember)

Code: Select all
PKGA_BASE_RT = 9.95
PKGA_BASE_HRS = 10
PKGA_EXTRA_HR_RT = 2
NP_DSCT_PCNT = .20

/* "hours_used" will be the number of hours the job took
     Calculate total for package A (w/o discount)
     First see if hours is less than PKG_A_BASE_HRS */

if( hours_used < PKGA_BASE_HRS )
     packageA_subTotal = PKGA_BASE_RT
else
     packageA_subTotal = PACKAGE_A_BASE_RATE + (( hours_used - PKGA_BASE_HRS ) * PKGA_EXTRA_HR_RT )


/* Calculate discount if there is one and figure it into grand total
    "discount" a boolean value if the box is checked or not */

if( discount )
    packageA_Total = packageA_subTotal - ( packageA_subTotal * NP_DSCT_PCNT )
else
    packageA_Total = packageA_subTotal

return packageA_Total



There are a couple of ways to go about doing this. That is just a basic idea of one of them applied to package A. It is pseudocode, so it might be messy, but it should get you started.

-Weaver

Edit: Struggled to make look decent in "code" bbcode
Public Keys

The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
PROfessional Member
User avatar
Posts: 1967
Joined: Wed Jun 19, 2002 12:05 am
Location: /home/weaver/

hmmm

Postby thankins » Thu Sep 18, 2003 9:04 pm

Thanks Weaver, that helped a little. I think I got the global variable in there now but still a little lost on the whole radio button selection calculate thing.


Here are my class variable:
Code: Select all
The following class-level constants are used
    'to calculate the discounts
    Dim packageBaseRateA As Double = 9.95          'Package A Base Rate
    Dim packageBaseRateB As Double = 14.95         'Package B Base Rate
    Dim packageBaseRateC As Double = 19.95         'Package C Base Rate
    Dim pakABaseHrs As Double = 10                 'Package A Hours
    Dim pakBBaseHrs As Double = 20                 'Package B Hours
    Dim pakAExtraHours As Double = 2.0             'Package A Extra Hour Rate
    Dim pakBExtraHours As Double = 1.0             'Package B Extra Hour Rate
    Dim nonProfit As Double = 0.2                  'Non Profit Org Discount
             




and Here is my btnCalc_Click so far.
Code: Select all
  Private Sub btbCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btbCalc.Click
        'Claculates and displays the price for internet usage


        'Declares local variable
        Dim packageA As Double     'Package A
        Dim pacakgeB As Double     'Package B
        Dim pacakgeC As Double     'Package C
        Dim hoursUsed As Double    'Hours used by consumer

       
        'Validate the number of Hours
        If Val(txtHours.Text) < 1 Or Val(txtHours.Text) > 744 Then
            MessageBox.Show("Enter a vlaue in the range of 1-744 for " & _
                            "hours of usage.", "Input Error")



        Else
            If (hoursUsed < pakABaseHrs) Then
                packageA = 9.95
            Else
                packageA = packageA + ((hoursUsed - pakABaseHrs) * pakAExtraHours)





            End If



Hope all that makes sense. I set it up like you said but how do I get the radiobuttons in so that the program sees that radio button Package A is selected and calculates that. I believe that the hoursused If statement is correct I jut dont know how to add in the radio buttons [/code]
PRO Level 2
Posts: 30
Joined: Wed Mar 05, 2003 5:35 pm
Location: USA

Postby Weaver » Thu Sep 18, 2003 9:44 pm

Like I said before, I have never even touched Visual Basic. Thus, I haven't the first idea how to add in radio buttons. If you are taking this at a school your text should cover topics such as this.

Your problem now seems to be a language dependent problem (radio buttons), not a procedural one. Now that you are familiar with the procedure consult other sources to uncover the mystery of those radio buttons (or checkboxes).

-Weaver
Public Keys

The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
PROfessional Member
User avatar
Posts: 1967
Joined: Wed Jun 19, 2002 12:05 am
Location: /home/weaver/

Help needed

Postby odayict » Tue Mar 02, 2004 5:27 am

when i made programs that are directory related, it would not work because I dont know the full path.
for example If i want to create a text files at C:\Documents and Settings\"Current User"\Desktop\a.txt
how do i do it?
I dont know whats the path
help needed ASAP
people are relying on me
odayict

Re: Help needed

Postby Weaver » Tue Mar 02, 2004 3:34 pm

odayict wrote:when i made programs that are directory related, it would not work because I dont know the full path.
for example If i want to create a text files at C:\Documents and Settings"Current User"\Desktop\a.txt
how do i do it?
I dont know whats the path
help needed ASAP
people are relying on me


You should be able to use some VB/Windows API to detect the environment variable that says which user is logged in. Then just replace the user with "Current User".

If you open up a 'cmd' window and type 'set' you can see the list of current environmental variables. The variable you are looking to extract is 'USERNAME' or 'USERPROFILE', whichever you would feel more comfortable with. I would recommend using 'USERPROFILE'. You will have to use a VB/Windows API to ge able to grab this information from within your VB code.

Sounds about right to me. Remember that I haven't ever touched VB so don't trust me.

-Weaver
Public Keys

The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
PROfessional Member
User avatar
Posts: 1967
Joined: Wed Jun 19, 2002 12:05 am
Location: /home/weaver/

Next

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 1 guest