4 Replies - 1769 Views - Last Post: 27 March 2012 - 08:06 AM Rate Topic: -----

#1 nelliegirl  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 147
  • Joined: 08-February 08

convert selected currancy and display

Posted 25 March 2012 - 03:40 PM

I have the program almost finished when I text it the only radio button that works is the united kingdom pound the rest show all zeros.
Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

Private Sub americanTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles americanTextBox.KeyPress

        ' allows the text box to accept only numbers
        ' and the backspace key for editing
        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso
            e.KeyChar <> ControlChars.Back Then
            e.Handled = True
        End If

    End Sub

    Private Sub displayButton_Click(sender As System.Object, e As System.EventArgs) Handles displayButton.Click
        ' declare varibles

        Dim canDollar As Decimal
        Dim euro As Decimal
        Dim rupee As Decimal
        Dim yen As Decimal
        Dim peso As Decimal
        Dim rand As Decimal
        Dim pound As Decimal
        Dim amDollar As Decimal

        ' convert uer input to double
        Decimal.TryParse(americanTextBox.Text, amDollar)

        ' convert us dollars to selected currancy 
        ' calculate american dollar
        If CanadaRadioButton.Checked = True Then
            canDollar = CDec(amDollar * 1.01615)
        End If

        If EuroRadioButton.Checked = True Then
            euro = CDec(amDollar * 0.63849)
        End If

        If RupeeRadioButton.Checked = True Then
            rupee = CDec(amDollar * 40.1798)
        End If

        If YenRadioButton.Checked = True Then
            yen = CDec(amDollar * 104.39)
        End If

        If PesoRadioButton.Checked = True Then
            peso = CDec(amDollar * 10.4613)
        End If

        If randRadioButton.Checked = True Then
            rand = CDec(amDollar * 7.6031)
        End If

        If poundRadioButton.Checked = True Then
            pound = CDec(amDollar * 0.504285)
        End If

        ' convrt to decimal
        displayLabel.Text = canDollar.ToString("C3")
        displayLabel.Text = euro.ToString("C3")
        displayLabel.Text = rupee.ToString("C3")
        displayLabel.Text = yen.ToString("C3")
        displayLabel.Text = peso.ToString("C3")
        displayLabel.Text = rand.ToString("C3")
        displayLabel.Text = pound.ToString("C3")


    End Sub

    Private Sub exitButton_Click(sender As System.Object, e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

End Class




I am not sure what I am doing wrong.

Is This A Good Question/Topic? 0
  • +

Replies To: convert selected currancy and display

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5566
  • View blog
  • Posts: 11,903
  • Joined: 02-June 10

Re: convert selected currancy and display

Posted 25 March 2012 - 04:28 PM

It has nothing to do with your radio buttons.

Its because you keep replacing the text in the one textbox, AFTER you do all the calculations.

The last value you put in there is the only one you would see, which is pounds.

64 displayLabel.Text = canDollar.ToString("C3")
65 displayLabel.Text = euro.ToString("C3")
66 displayLabel.Text = rupee.ToString("C3")
67 displayLabel.Text = yen.ToString("C3")
68 displayLabel.Text = peso.ToString("C3")
69 displayLabel.Text = rand.ToString("C3")
70 displayLabel.Text = pound.ToString("C3")

Was This Post Helpful? 0
  • +
  • -

#3 nelliegirl  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 147
  • Joined: 08-February 08

Re: convert selected currancy and display

Posted 27 March 2012 - 04:56 AM

View PosttlhIn`toq, on 25 March 2012 - 04:28 PM, said:

It has nothing to do with your radio buttons.

Its because you keep replacing the text in the one textbox, AFTER you do all the calculations.

The last value you put in there is the only one you would see, which is pounds.

64 displayLabel.Text = canDollar.ToString("C3")
65 displayLabel.Text = euro.ToString("C3")
66 displayLabel.Text = rupee.ToString("C3")
67 displayLabel.Text = yen.ToString("C3")
68 displayLabel.Text = peso.ToString("C3")
69 displayLabel.Text = rand.ToString("C3")
70 displayLabel.Text = pound.ToString("C3")



So what am I doing wrong! I tried it a couple of different ways and still is not working correctly.
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: convert selected currancy and display

Posted 27 March 2012 - 05:15 AM

As tlhIn`toq has already explained, you're righting into the same label every time.

If you wanted to display them all at once, define new labels for each.

So you have something like:

lblRupee.Text = rupee.ToString("C3")
lblGBPounds.Text = pound.ToString("C3")
etc.

Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5566
  • View blog
  • Posts: 11,903
  • Joined: 02-June 10

Re: convert selected currancy and display

Posted 27 March 2012 - 08:06 AM

Or move your label assignment inside the appropriate If...else statement.


47 If YenRadioButton.Checked = True Then
48 yen = CDec(amDollar * 104.39)
67 displayLabel.Text = yen.ToString("C3")
49 End If

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1