Click here to Skip to main content
15,923,083 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionVisaul Basic program giving me fits! Pin
Chris081212-Oct-09 5:14
Chris081212-Oct-09 5:14 
AnswerRe: Visaul Basic program giving me fits! Pin
IvanIT12-Oct-09 6:05
IvanIT12-Oct-09 6:05 
AnswerRe: Visaul Basic program giving me fits! Pin
Dave Kreskowiak12-Oct-09 6:56
mveDave Kreskowiak12-Oct-09 6:56 
GeneralRe: Visaul Basic program giving me fits! Pin
Paul Conrad13-Oct-09 5:47
professionalPaul Conrad13-Oct-09 5:47 
GeneralRe: Visaul Basic program giving me fits! Pin
Dave Kreskowiak13-Oct-09 6:36
mveDave Kreskowiak13-Oct-09 6:36 
GeneralRe: Visual Basic program giving me fits! Pin
Chris081214-Oct-09 5:42
Chris081214-Oct-09 5:42 
GeneralRe: Visual Basic program giving me fits! Pin
Dave Kreskowiak14-Oct-09 11:51
mveDave Kreskowiak14-Oct-09 11:51 
AnswerRe: Visaul Basic program giving me fits! Pin
Henry Minute12-Oct-09 6:57
Henry Minute12-Oct-09 6:57 
One way to deal with this, and I repeat ONE way, is to create a class to hold the charging information and in your form_load event handler add an instance of this class to each of the RadioButtons.

Here is a very simple example of such a class:
Public Class ChargingInfo
	Private bHours As Int32    'base hours
	Private bRate As Double    'base rate
	Private aRate As Double    'additional rate

	Public Property BaseHours() As Int32
		Get
			Return Me.bHours
		End Get
		Set(ByVal value As Int32)
			Me.bHours = value
		End Set
	End Property


	Public Property BaseRate() As Double
		Get
			Return Me.bRate
		End Get
		Set(ByVal value As Double)
			Me.bRate = value
		End Set
	End Property

	Public Property AdditionalRate() As Double
		Get
			Return Me.aRate
		End Get
		Set(ByVal value As Double)
			aRate = value
		End Set
	End Property

End Class


and the Form_Load handler:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim ci As ChargingInfo = New ChargingInfo()
    ci.BaseHours = 10
    ci.BaseRate = 9.95
    ci.AdditionalRate = 2.0
    Me.radA.Tag = ci

    ci = New ChargingInfo()
    ci.BaseHours = 20
    ci.BaseRate = 14.95
    ci.AdditionalRate = 1
    Me.radB.Tag = ci

    ci = New ChargingInfo()
    ci.BaseHours = 0
    ci.BaseRate = 19.95
    ci.AdditionalRate = 0
    Me.radC.Tag = ci
End Sub


Then in your btnCalculate_Click event handler you first retrieve the ChargingInfo from the checked RadioButton and that can then be used throughout the calculation. (As an alternative you could handle the CheckedChanged event handler for the RadioButtons and set a form wide variable to the correct ChargingInfo). Something like this:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    Dim cost As Double
    Dim ci As ChargingInfo
    Dim chargeableHours As Int32 = Math.Min(744, enteredHours)

    If Me.radC.Checked Then
        ci = CType(Me.radC.Tag, ChargingInfo)
    ElseIf Me.radB.Checked Then
        ci = CType(Me.radB.Tag, ChargingInfo)
    Else
        ci = CType(Me.radA.Tag, ChargingInfo)
    End If

    If ci.BaseHours = 0 Then
        cost = chargeableHours * ci.BaseRate
    Else
        cost = Math.Min(ci.BaseHours, chargeableHours) * ci.BaseRate
        chargeableHours = chargeableHours - ci.BaseHours
        If chargeableHours > 0 Then
            cost = cost + (chargeableHours * ci.AdditionalRate)
        End If
    End If

    If Me.chboxNonProfit.Checked Then
        cost = cost * 0.8
    End If

            Me.txtTotalCost.Text = cost.ToString()
End Sub


**NOTE** enteredHours is the number of hours actually used, you didn't say where that comes from.

Hope that this gives you some ideas. Smile | :)

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

GeneralRe: Visaul Basic program giving me fits! Pin
Mycroft Holmes12-Oct-09 17:57
professionalMycroft Holmes12-Oct-09 17:57 
GeneralRe: Visaul Basic program giving me fits! Pin
Henry Minute13-Oct-09 0:28
Henry Minute13-Oct-09 0:28 
QuestionHow To Create a basic Gantt chart Pin
Anoop Brijmohun12-Oct-09 3:24
Anoop Brijmohun12-Oct-09 3:24 
AnswerRe: How To Create a basic Gantt chart Pin
Henry Minute12-Oct-09 4:18
Henry Minute12-Oct-09 4:18 
GeneralRe: How To Create a basic Gantt chart Pin
Anoop Brijmohun12-Oct-09 4:24
Anoop Brijmohun12-Oct-09 4:24 
AnswerRe: How To Create a basic Gantt chart Pin
Andy_L_J12-Oct-09 18:37
Andy_L_J12-Oct-09 18:37 
QuestionPassing ByVal or ByRef Pin
PAguilar0912-Oct-09 1:54
PAguilar0912-Oct-09 1:54 
AnswerRe: Passing ByVal or ByRef Pin
freakyit12-Oct-09 3:02
freakyit12-Oct-09 3:02 
GeneralRe: Passing ByVal or ByRef Pin
PAguilar0912-Oct-09 3:48
PAguilar0912-Oct-09 3:48 
GeneralRe: Passing ByVal or ByRef Pin
Luc Pattyn12-Oct-09 3:53
sitebuilderLuc Pattyn12-Oct-09 3:53 
AnswerRe: Passing ByVal or ByRef Pin
Andy_L_J12-Oct-09 19:02
Andy_L_J12-Oct-09 19:02 
QuestionHelp for Filtering Database by Date !! Pin
jeshra27911-Oct-09 5:14
jeshra27911-Oct-09 5:14 
AnswerRe: Help for Filtering Database by Date !! Pin
dan!sh 11-Oct-09 6:04
professional dan!sh 11-Oct-09 6:04 
GeneralRe: Help for Filtering Database by Date !! Pin
jeshra27911-Oct-09 7:01
jeshra27911-Oct-09 7:01 
GeneralRe: Help for Filtering Database by Date !! Pin
Richard MacCutchan11-Oct-09 8:11
mveRichard MacCutchan11-Oct-09 8:11 
GeneralRe: Help for Filtering Database by Date !! Pin
jeshra27911-Oct-09 18:10
jeshra27911-Oct-09 18:10 
GeneralRe: Help for Filtering Database by Date !! Pin
dan!sh 11-Oct-09 18:37
professional dan!sh 11-Oct-09 18:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.