Re: beginner: VB.NET currency inputs

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Cor Ligthert (notmyfirstname_at_planet.nl)
Date: 11/12/04


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
>
>



Relevant Pages

  • Re: Reading an INI file
    ... I have been strugling with your problem about making faster the painting of ... the labels. ... > Dim lpAppName As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Access 2000 help with Mid and InStr
    ... This calculation is in a module, ... As String ... Dim lngHours As Long ... > calculate the difference where you need it in a query. ...
    (microsoft.public.access.gettingstarted)
  • Re: Enter the result of a formula using VBA
    ... I am not sure where the date cell is, which cell you want to compare ... Dim adjCol As String ... .Calculation = xlCalculationManual ...
    (microsoft.public.excel.programming)
  • Re: Enter the result of a formula using VBA
    ... I am not sure where the date cell is, which cell you want to compare ... Dim adjCol As String ... .Calculation = xlCalculationManual ...
    (microsoft.public.excel.programming)
  • Re: Median Calculation
    ... correctness by hand... ... Public Function kMedian(strTable As String, strQty As String, _ ... or Null if there are no records for the calculation ... Dim rs As DAO.Recordset ...
    (microsoft.public.access.modulesdaovba)