Visual Basic Help
20 posts
• Page 2 of 2 • 1, 2
Re: hmmm
thankins wrote:
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]
When you double click on the particular button on the project form, you'll be presented with a blank function i.e.:
Private Sub Option1_Click()
End Sub
Set any variables and/or calculations specific to the button there. Since VB is "event driven" none of the code written in "Option1_Click()" will execute until the user selects the button.
With that, you may have to re-structure your program flow a bit. I'm no VB guru so can't really help you there.
hope this helps...
GP
Come on, I know thier is some person in this forum knows vb.
I don't know about that one... I don't want to knock the langauge, as it does a fine job of that on its own. Personally I would recommend removing VB from your list of langauges that you use.
-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
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
- Weaver
- PROfessional Member
- Posts: 1967
- Joined: Wed Jun 19, 2002 12:05 am
- Location: /home/weaver/
If you use the Dialog control, you can have the user select the file with the dialog. Save the [u]filename[/u] from the dialog into a SaveSetting in the registry. Call it from what ever sub you want to use it in with the GetSetting.
Ex:
Dim MyFile as String <- A VARIABLE TO HOLD THE FILES NAME AND PATH
Dialog1.show open <- Open the dialog and select file
If Dialog1.FileName = "" then exit sub <-If the user cancels avoid error
MyFile = Dialog1.FileName
SaveSetting(app.title,"MySettings","FilePath",MyFile)
now, if you want to get the file name and path you do this
text1.text = GetSetting(app.title,"MySettings","FilePath",""
what's coll about the GetSetting and SaveSetting method is that if you know the name of the app and section and key values, you can also call the same information from ANY vb application you write. I do this all the time when I program. I map databases on several client machines at work and store them this way to call them from other components of the software, also, because the mapping can change from machine to machine, you can DYNAMICALLY add delete or change the keys! If you want more information, let PM me and I will do a short vb proj to demo for you so you can learn how to do it yourself.
Ex:
Dim MyFile as String <- A VARIABLE TO HOLD THE FILES NAME AND PATH
Dialog1.show open <- Open the dialog and select file
If Dialog1.FileName = "" then exit sub <-If the user cancels avoid error
MyFile = Dialog1.FileName
SaveSetting(app.title,"MySettings","FilePath",MyFile)
now, if you want to get the file name and path you do this
text1.text = GetSetting(app.title,"MySettings","FilePath",""
what's coll about the GetSetting and SaveSetting method is that if you know the name of the app and section and key values, you can also call the same information from ANY vb application you write. I do this all the time when I program. I map databases on several client machines at work and store them this way to call them from other components of the software, also, because the mapping can change from machine to machine, you can DYNAMICALLY add delete or change the keys! If you want more information, let PM me and I will do a short vb proj to demo for you so you can learn how to do it yourself.
- eddiemacdonald42
- Posts: 6
- Joined: Wed May 19, 2004 8:32 am
- Location: Canada
I justlooked at your origional post. That program is tres simple my friend, it would take about ten minutes to do. you want it done so you can see how this works? WITHOUT a module?
- eddiemacdonald42
- Posts: 6
- Joined: Wed May 19, 2004 8:32 am
- Location: Canada
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Time Used"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(72, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(72, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadioButton3)
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(16, 56)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(208, 112)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Products"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(16, 80)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(176, 24)
Me.RadioButton3.TabIndex = 2
Me.RadioButton3.Text = "Package C"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(16, 48)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(176, 24)
Me.RadioButton2.TabIndex = 1
Me.RadioButton2.Text = "Package B"
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(176, 16)
Me.RadioButton1.TabIndex = 0
Me.RadioButton1.Text = "Package A"
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(152, 24)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(168, 24)
Me.CheckBox1.TabIndex = 3
Me.CheckBox1.Text = "Non-Profit Organization"
Me.CheckBox1.Visible = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(64, 192)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 4
Me.Button1.Text = "Calculate"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(168, 200)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 5
Me.Label2.Text = "Total"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(232, 200)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(104, 20)
Me.TextBox2.TabIndex = 6
Me.TextBox2.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 273)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim iHoursPerPackage As Integer
Dim dChargePerPackage As Decimal
Dim iExtraHours As Integer
Dim dExtraChargePerExtraHour As Decimal
Dim dDiscount As Decimal = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = CalculateTotalDue()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = 10
dChargePerPackage = 9.95
dExtraChargePerExtraHour = 2.0
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = 20
dChargePerPackage = 14.95
dExtraChargePerExtraHour = 1.0
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = Convert.ToInt32(TextBox1.Text)
dChargePerPackage = 19.95
dExtraChargePerExtraHour = 0
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
dDiscount = 0.2
End Sub
Private Function CalculateTotalDue() As Double
Dim dTotal As Double = 0
'Assign the Charge for the normal hour of usage
dTotal = dChargePerPackage
'Second find out the extra hour used and add to the above total
iExtraHours = Convert.ToInt32(TextBox1.Text) - iHoursPerPackage
If (iExtraHours > 0) Then
dTotal = dTotal + (iExtraHours * dExtraChargePerExtraHour)
End If
'Thirdly check if the Discount is available
If (dDiscount > 0) Then
dTotal = 0.8 * dTotal
End If
Return dTotal
End Function
End Class
I didnt have VS 6 on computer installed hence i created the code in VB.NET Hope the logic will understandable.
Just neglect the code with in the #Region tags thats .NET related.
Regards,
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Time Used"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(72, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(72, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.RadioButton3)
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(16, 56)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(208, 112)
Me.GroupBox1.TabIndex = 2
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Products"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(16, 80)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(176, 24)
Me.RadioButton3.TabIndex = 2
Me.RadioButton3.Text = "Package C"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(16, 48)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(176, 24)
Me.RadioButton2.TabIndex = 1
Me.RadioButton2.Text = "Package B"
'
'RadioButton1
'
Me.RadioButton1.Location = New System.Drawing.Point(16, 24)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(176, 16)
Me.RadioButton1.TabIndex = 0
Me.RadioButton1.Text = "Package A"
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(152, 24)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(168, 24)
Me.CheckBox1.TabIndex = 3
Me.CheckBox1.Text = "Non-Profit Organization"
Me.CheckBox1.Visible = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(64, 192)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 4
Me.Button1.Text = "Calculate"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(168, 200)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(56, 16)
Me.Label2.TabIndex = 5
Me.Label2.Text = "Total"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(232, 200)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(104, 20)
Me.TextBox2.TabIndex = 6
Me.TextBox2.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(432, 273)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.CheckBox1)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim iHoursPerPackage As Integer
Dim dChargePerPackage As Decimal
Dim iExtraHours As Integer
Dim dExtraChargePerExtraHour As Decimal
Dim dDiscount As Decimal = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = CalculateTotalDue()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = 10
dChargePerPackage = 9.95
dExtraChargePerExtraHour = 2.0
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = 20
dChargePerPackage = 14.95
dExtraChargePerExtraHour = 1.0
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
CheckBox1.Visible = True
iHoursPerPackage = Convert.ToInt32(TextBox1.Text)
dChargePerPackage = 19.95
dExtraChargePerExtraHour = 0
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
dDiscount = 0.2
End Sub
Private Function CalculateTotalDue() As Double
Dim dTotal As Double = 0
'Assign the Charge for the normal hour of usage
dTotal = dChargePerPackage
'Second find out the extra hour used and add to the above total
iExtraHours = Convert.ToInt32(TextBox1.Text) - iHoursPerPackage
If (iExtraHours > 0) Then
dTotal = dTotal + (iExtraHours * dExtraChargePerExtraHour)
End If
'Thirdly check if the Discount is available
If (dDiscount > 0) Then
dTotal = 0.8 * dTotal
End If
Return dTotal
End Function
End Class
I didnt have VS 6 on computer installed hence i created the code in VB.NET Hope the logic will understandable.
Just neglect the code with in the #Region tags thats .NET related.
Regards,
HellRaiser_2030
- hellraiser_2030
- Posts: 71
- Joined: Wed Apr 07, 2004 11:50 am
- Location: Boston
Re: Visual Basic Help
thankins wrote: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
Sorry , maybe a little too late, but I joined today... here is the code
- Code: Select all
Option Explicit
Const PKGA_BASE_RT = 9.95
Const PKGA_BASE_HRS = 10
Const PKGA_EXTRA_HR_RT = 2
Const PKGB_BASE_RT = 14.95
Const PKGB_BASE_HRS = 20
Const PKGB_EXTRA_HR_RT = 1
Const PKGC_BASE_RT = 19.95
Const PKGC_BASE_HRS = 0
Const PKGC_EXTRA_HR_RT = 0
Const NP_DSCT_PCNT = 0.2
Private Sub btbCalc_Click()
Dim dblSubTotal As Double
Dim dblTotal As Double
Dim dblUnitPrice As Double
Dim intMinHours As Integer
Dim dblExtraPrice As Double
'I understood user can select only one package, so I set a control array with the
'RadioButtons giving them the same name
'First we test if hours is numeric or not
If IsNumeric(txtHours.Text) Then
'Okay, let's see if they doesn't exceed the maximum number of hours
If (CInt(txtHours.Text) >= 1 And CInt(txtHours.Text) <= 744) Then
'Okay, everything set up correctly, now let's calculate the subtotal
'based upon the radio button checked
If radPack(0).Value = True Then
dblUnitPrice = PKGA_BASE_RT
intMinHours = PKGA_BASE_HRS
dblExtraPrice = PKGA_EXTRA_HR_RT
End If
If radPack(1).Value = True Then
dblUnitPrice = PKGB_BASE_RT
intMinHours = PKGB_BASE_HRS
dblExtraPrice = PKGB_EXTRA_HR_RT
End If
If radPack(2).Value = True Then
dblUnitPrice = PKGC_BASE_RT
intMinHours = PKGC_BASE_HRS
dblExtraPrice = PKGC_EXTRA_HR_RT
End If
'Begin calc
'Subtotal
If intMinHours = 0 Then
'We are with Package C, which means "plain price"
dblSubTotal = dblUnitPrice
Else
'We are with the other two Packages
If CInt(txtHours.Text) <= intMinHours Then
dblSubTotal = dblUnitPrice
Else
dblSubTotal = dblUnitPrice + ((CInt(txtHours.Text) - intMinHours) * dblExtraPrice)
End If
End If
'Discounts
If chkNonProfit.Value = Checked Then
dblTotal = dblSubTotal - (dblSubTotal * NP_DSCT_PCNT)
Else
dblTotal = dblSubTotal
End If
'Finish calc, now display the total due
txtTotalDue.Text = CStr(dblTotal)
Else
MsgBox "Hours must be between 1 and 744"
txtHours.SetFocus
End If
Else
MsgBox "Must type a numeric value for the hours"
txtHours.SetFocus
End If
End Sub
I hope you like it
20 posts
• Page 2 of 2 • 1, 2
Return to HTML, CSS, and Scripts
Who is online
Users browsing this forum: No registered users and 4 guests