?
Solved

New to VB

Posted on 2003-03-25
8
Medium Priority
?
185 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:lbay48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:bistrica
ID: 8208483
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
 
LVL 53

Expert Comment

by:Dhaest
ID: 8208535
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 Comment

by:lbay48
ID: 8215717
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.

Desperate please help!



0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 53

Expert Comment

by:Dhaest
ID: 8215943
Sounds like homework...
0
 
LVL 4

Expert Comment

by:bistrica
ID: 8215949
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
 
LVL 8

Accepted Solution

by:
Jeff Tennessen earned 1200 total points
ID: 8220753
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
   LinkTopic       =   "Form1"
   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
   Begin VB.Menu mnuFile
      Caption         =   "&File"
      Begin VB.Menu mitFileExit
         Caption         =   "E&xit"
      End
   End
   Begin VB.Menu mnuTaxRate
      Caption         =   "&Tax Rate"
      Begin VB.Menu mitTaxRateTenPercent
         Caption         =   "&10%"
      End
      Begin VB.Menu mitTaxRateSevenPercent
         Caption         =   "&7%"
      End
      Begin VB.Menu mitTaxRateFivePercent
         Caption         =   "&5%"
      End
      Begin VB.Menu mitTaxRateTaxFree
         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
 
  Unload Me

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
 

Author Comment

by:lbay48
ID: 8229336
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
 
LVL 8

Expert Comment

by:Jeff Tennessen
ID: 8235316
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question