# New to VB

I have just started a course on VB and need some help calculkating produc cost = .95 and second product = .50 I will also need to figure taxes at 5,7,10%

I just cant seem to figure this out
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Dim product_cost
Dim second_product
Dim TAX_RATE
Dim tax_to_pay

product_cost = product_cost * 0.95
second_product= second_product * 0.5

TAX_RATE = 5 'or 7 or 10

tax_to_pay = product_cost * TAX_RATE / 100

0
Commented:
Declare your variables as a specific type, to avoid troubles

Dim product_cost, second_product, tax_to_pay as double
Dim TAX_RATE as integer

product_cost = product_cost * 0.95
second_product= second_product * 0.5

TAX_RATE = 5 'or 7 or 10

tax_to_pay = product_cost * TAX_RATE / 100

0
Author Commented:
for an extra 200 pts.

Ok, this is what should be happening.

Large = \$.95
Regular = \$.50

Using the menu titled Tax Rate;  there is a variable tax rate of 5,7,10 and tax free or 0 to choose from  once a rate is selected using the menu. I should be able to enter any number
And then hit the Calculate button and it should calculate number of large  + number of regular and depending on the rate calculate the price +Tax  in one text box.

Shipping charges should also be calculated at the same time but will fall under a different text box

Shipping cost is based on
Large weighs = 11oz
Regular weighs= 6 oz

Shipping is \$1 per pound and \$.10 per additional oz

Lastly is total and I have that figured.

0
Commented:
Sounds like homework...
0
Commented:
Start like this:

1) Designe GUI of the application. That is: create form, add menu on the from, add command button and anme it cmd Calculate, add text box(es) to enter value(s) and display result(s).

2) Each of this objects has Events. Selct events for them (On_Click) and add code to do what you need.

3) Code is mathematical calculation:
txtShippingCost = txtWeight * txtQuantity * TAX_RATE

In your posting you have described task, but was is the problem?
0
Assistant Vice PresidentCommented:
I think this is what you're looking for. It basically just spells out what bistrica outlined. Copy the code below into Notepad and save it as Main.frm, then open Main.frm in VB and run or compile it. Let me know if you have questions.

Jeff

VERSION 5.00
Begin VB.Form Form1
Caption         =   "Order"
ClientHeight    =   2415
ClientLeft      =   165
ClientTop       =   855
ClientWidth     =   4695
LockControls    =   -1  'True
ScaleHeight     =   2415
ScaleWidth      =   4695
StartUpPosition =   3  'Windows Default
Begin VB.TextBox txtTotal
Alignment       =   1  'Right Justify
Appearance      =   0  'Flat
BackColor       =   &H8000000F&
BorderStyle     =   0  'None
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   960
Locked          =   -1  'True
TabIndex        =   14
TabStop         =   0   'False
Top             =   1920
Width           =   1215
End
Begin VB.TextBox txtShipping
Alignment       =   1  'Right Justify
Appearance      =   0  'Flat
BackColor       =   &H8000000F&
BorderStyle     =   0  'None
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   960
Locked          =   -1  'True
TabIndex        =   12
TabStop         =   0   'False
Top             =   1560
Width           =   1215
End
Begin VB.CommandButton cmdClose
Cancel          =   -1  'True
Caption         =   "Close"
Height          =   375
Left            =   3240
TabIndex        =   16
Top             =   600
Width           =   1335
End
Begin VB.TextBox txtTax
Alignment       =   1  'Right Justify
Appearance      =   0  'Flat
BackColor       =   &H8000000F&
BorderStyle     =   0  'None
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   960
Locked          =   -1  'True
TabIndex        =   9
TabStop         =   0   'False
Top             =   1200
Width           =   1215
End
Begin VB.TextBox txtSubtotal
Alignment       =   1  'Right Justify
Appearance      =   0  'Flat
BackColor       =   &H8000000F&
BorderStyle     =   0  'None
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   960
Locked          =   -1  'True
TabIndex        =   7
TabStop         =   0   'False
Top             =   840
Width           =   1215
End
Begin VB.CommandButton cmdCalculate
Caption         =   "Calculate"
Default         =   -1  'True
Height          =   375
Left            =   3240
TabIndex        =   15
Top             =   120
Width           =   1335
End
Begin VB.TextBox txtSmall
Alignment       =   1  'Right Justify
Height          =   285
Left            =   960
TabIndex        =   4
Top             =   480
Width           =   1215
End
Begin VB.TextBox txtLarge
Alignment       =   1  'Right Justify
Height          =   285
Left            =   960
TabIndex        =   1
Top             =   120
Width           =   1215
End
Begin VB.Label lblTaxRate
Caption         =   "(0%)"
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   2280
TabIndex        =   10
Top             =   1200
Width           =   855
End
Begin VB.Label lblTotal
Caption         =   "Total"
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   120
TabIndex        =   13
Top             =   1920
Width           =   735
End
Begin VB.Label lblShipping
Caption         =   "Shiping"
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   120
TabIndex        =   11
Top             =   1560
Width           =   735
End
Begin VB.Label lblSmallCost
Caption         =   "@ \$0.50"
Height          =   210
Left            =   2280
TabIndex        =   5
Top             =   525
Width           =   855
End
Begin VB.Label lblLargeCost
Caption         =   "@ \$0.95"
Height          =   210
Left            =   2280
TabIndex        =   2
Top             =   165
Width           =   855
End
Begin VB.Label lblTax
Caption         =   "Tax"
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   120
TabIndex        =   8
Top             =   1200
Width           =   735
End
Begin VB.Label lblSubtotal
Caption         =   "Subtotal"
BeginProperty Font
Name            =   "MS Sans Serif"
Size            =   8.25
Charset         =   0
Weight          =   700
Underline       =   0   'False
Italic          =   0   'False
Strikethrough   =   0   'False
EndProperty
Height          =   285
Left            =   120
TabIndex        =   6
Top             =   840
Width           =   735
End
Begin VB.Label lblSmall
Caption         =   "Small"
Height          =   210
Left            =   120
TabIndex        =   3
Top             =   525
Width           =   735
End
Begin VB.Label lblLarge
Caption         =   "Large"
Height          =   210
Left            =   120
TabIndex        =   0
Top             =   165
Width           =   735
End
Caption         =   "&File"
Caption         =   "E&xit"
End
End
Caption         =   "&Tax Rate"
Caption         =   "&10%"
End
Caption         =   "&7%"
End
Caption         =   "&5%"
End
Caption         =   "Tax &Free"
Checked         =   -1  'True
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdCalculate_Click()

On Error GoTo Err_cmdCalculate_Click

Dim lngLg As Long
Dim lngSm As Long
Dim curLg As Currency
Dim curSm As Currency
Dim curSb As Currency
Dim curTx As Currency
Dim lngWt As Long
Dim curSh As Currency

If IsNumeric(txtLarge.Text) Then
lngLg = CLng(txtLarge.Text)
End If

If IsNumeric(txtSmall.Text) Then
lngSm = CLng(txtSmall.Text)
End If

curLg = lngLg * 0.95
curSm = lngSm * 0.5
curSb = curLg + curSm

Select Case True
Case mitTaxRateFivePercent.Checked
curTx = curSb * 0.05
Case mitTaxRateSevenPercent.Checked
curTx = curSb * 0.07
Case mitTaxRateTenPercent.Checked
curTx = curSb * 0.1
Case Else
curTx = 0
End Select

lngWt = (lngLg * 11) + (lngSm * 6)
curSh = (lngWt \ 16) + ((lngWt Mod 16) * 0.1)

txtSubtotal.Text = Format\$(curSb, "Currency")
txtTax.Text = Format\$(curTx, "Currency")
txtShipping.Text = Format\$(curSh, "Currency")
txtTotal.Text = Format\$(curSb + curTx + curSh, "Currency")

Exit_cmdCalculate_Click:
Exit Sub

Err_cmdCalculate_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (cmdCalculate_Click)", vbCritical
Resume Exit_cmdCalculate_Click

End Sub

Private Sub cmdClose_Click()

On Error GoTo Err_cmdClose_Click

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (cmdClose_Click)", vbCritical
Resume Exit_cmdClose_Click

End Sub

Private Sub mitFileExit_Click()

On Error GoTo Err_mitFileExit_Click

cmdClose_Click

Exit_mitFileExit_Click:
Exit Sub

Err_mitFileExit_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (mitFileExit_Click)", vbCritical
Resume Exit_mitFileExit_Click

End Sub

Private Sub mitTaxRateFivePercent_Click()

On Error GoTo Err_mitTaxRateFivePercent_Click

mitTaxRateFivePercent.Checked = True
mitTaxRateSevenPercent.Checked = False
mitTaxRateTaxFree.Checked = False
mitTaxRateTenPercent.Checked = False

lblTaxRate.Caption = "(5%)"

cmdCalculate_Click

Exit_mitTaxRateFivePercent_Click:
Exit Sub

Err_mitTaxRateFivePercent_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (mitTaxRateFivePercent_Click)", vbCritical
Resume Exit_mitTaxRateFivePercent_Click

End Sub

Private Sub mitTaxRateSevenPercent_Click()

On Error GoTo Err_mitTaxRateSevenPercent_Click

mitTaxRateFivePercent.Checked = False
mitTaxRateSevenPercent.Checked = True
mitTaxRateTaxFree.Checked = False
mitTaxRateTenPercent.Checked = False

lblTaxRate.Caption = "(7%)"

cmdCalculate_Click

Exit_mitTaxRateSevenPercent_Click:
Exit Sub

Err_mitTaxRateSevenPercent_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (mitTaxRateSevenPercent_Click)", vbCritical
Resume Exit_mitTaxRateSevenPercent_Click

End Sub

Private Sub mitTaxRateTaxFree_Click()

On Error GoTo Err_mitTaxRateTaxFree_Click

mitTaxRateFivePercent.Checked = False
mitTaxRateSevenPercent.Checked = False
mitTaxRateTaxFree.Checked = True
mitTaxRateTenPercent.Checked = False

lblTaxRate.Caption = "(0%)"

cmdCalculate_Click

Exit_mitTaxRateTaxFree_Click:
Exit Sub

Err_mitTaxRateTaxFree_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (mitTaxRateTaxFree_Click)", vbCritical
Resume Exit_mitTaxRateTaxFree_Click

End Sub

Private Sub mitTaxRateTenPercent_Click()

On Error GoTo Err_mitTaxRateTenPercent_Click

mitTaxRateFivePercent.Checked = False
mitTaxRateSevenPercent.Checked = False
mitTaxRateTaxFree.Checked = False
mitTaxRateTenPercent.Checked = True

lblTaxRate.Caption = "(10%)"

cmdCalculate_Click

Exit_mitTaxRateTenPercent_Click:
Exit Sub

Err_mitTaxRateTenPercent_Click:
MsgBox Err.Number & ": " & Err.Description & _
" (mitTaxRateTenPercent_Click)", vbCritical
Resume Exit_mitTaxRateTenPercent_Click

End Sub
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Jeff,

Thanks for the help, the code is a little advance for me, but I was able to see wheer I made my mistakes and what I need to work on. I'm not sure what "mit" means but Im getting there. My main problem was that I was failing to give exact commands for each event.

LB
0
Assistant Vice PresidentCommented:
LB, "mit" is just the control prefix I use for "menu item." It has no special significance, and you can use whatever works best for you. Glad the solution was able to help you!

Jeff
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.