Re: beginner: VB.NET currency inputs
From: Cor Ligthert (notmyfirstname_at_planet.nl)
Date: 11/12/04
- Next message: Warren Sirota: "Re: Please help me clarify these byVal vs. byRef subtleties"
- Previous message: elziko: "Traversing Controls"
- In reply to: jcnews: "beginner: VB.NET currency inputs"
- Next in thread: Herfried K. Wagner [MVP]: "Re: beginner: VB.NET currency inputs"
- Reply: Herfried K. Wagner [MVP]: "Re: beginner: VB.NET currency inputs"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 12 Nov 2004 12:49:28 +0100
Hi JCnews,
Did you already tried it like this?
\\\\
If IsNumeric(TextBox1.Text) Then
TextBox1.Text = (2 * CDec(TextBox1.Text)).ToString("C")
'calculation as sample
Else
MessageBox.Show("false")
End If
///
I hope this helps?
Cor
"jcnews" <jcnews@earthlink.net> schreef in bericht
news:nzZkd.24640$KJ6.921@newsread1.news.pas.earthlink.net...
>I am writing a 'wage calculator' program where the user inputs a dollar
> amount and then calculations are performed. I need to make sure that the
> input is only something like this: "$12.42", or "$4", or "5.30", and have
> the output always be in this format: "$#.##". Currently, the output
> sometimes looks like this: "$54.321", or "$512.2".
>
> This is what I have come up with by researching in books and using the
> built-in help. It's actually just a conversion of a simple java program
> that I saw in a book. I'm not really sure if I am doing everything right,
> but the program works except for that one problem.
>
> Any advice would be appreciated.
>
> ---------------------------------------------------------------------
> The entire sub is here:
> ---------------------------------------------------------------------
> Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnCalculate.Click
>
> ' Anything above 40 hours will be overtime
> Const MaxHours As Integer = 40
>
> ' Declare variables -- input
> Dim dHourlyWage As Double
> Dim dHoursWorked As Double
>
> ' Declare variables -- calculations
> Dim dRegularHours As Double
> Dim dOvertimeHours As Double
> Dim dGrossWages As Double
>
> ' Declare variables -- output
> Dim strRegularHours As String
> Dim strOvertimeHours As String
> Dim strResult As String
>
> ' Place input into the variables, converting from strings to doubles
> dHourlyWage = Double.Parse(txtHourlyWage.Text,
> Globalization.NumberStyles.Currency)
> dHoursWorked = Double.Parse(txtHoursWorked.Text,
> Globalization.NumberStyles.Currency)
>
> ' Calculate if there is any overtime (over 40 hours)
> If dHoursWorked <= MaxHours Then
> dRegularHours = dHourlyWage * dHoursWorked
> dOvertimeHours = 0
> dGrossWages = dRegularHours
> Else
> dRegularHours = (dHourlyWage * MaxHours)
> dOvertimeHours = (dHoursWorked - MaxHours) * (1.5 * dHourlyWage)
> dGrossWages = dRegularHours + dOvertimeHours
> End If
>
> ' Convert doubles to strings for display on labels
> strResult = System.Convert.ToString(dGrossWages)
> strRegularHours = System.Convert.ToString(dRegularHours)
> strOvertimeHours = System.Convert.ToString(dOvertimeHours)
>
> ' Display total Gross Hours
> lblResult.Text = "$" & strResult
>
> ' Show hidden labels
> lblSummary.Visible = True
> lblRegularResult.Visible = True
> lblOvertimeResult.Visible = True
> lblRegularHours.Visible = True
> lblOvertimeHours.Visible = True
>
> ' Display results on Summary labels
> lblRegularResult.Text = "$" & strRegularHours
> lblOvertimeResult.Text = "$" & strOvertimeHours
>
>
- Next message: Warren Sirota: "Re: Please help me clarify these byVal vs. byRef subtleties"
- Previous message: elziko: "Traversing Controls"
- In reply to: jcnews: "beginner: VB.NET currency inputs"
- Next in thread: Herfried K. Wagner [MVP]: "Re: beginner: VB.NET currency inputs"
- Reply: Herfried K. Wagner [MVP]: "Re: beginner: VB.NET currency inputs"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|