13 Replies - 1110 Views - Last Post: 23 February 2013 - 07:09 AM Rate Topic: -----

#1 nelliegirl  Icon User is offline

  • D.I.C Head

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

Currency Converter

Posted 22 February 2013 - 10:40 PM

This is my code every time I change the convert from dollar to Yen, euros or pesos I get the same total every time. example: I enter 20.00 for the first textbox, yen for the second and my total result would be 1538.00 and if I change it to euros or pesos I get the same result. Also the example in my text book the have a different total then what I have the total the have for my example is total result s 2130.00
Public Class CurrencyConverterForm

    Private Sub convertButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles convertButton.Click
        ' delared varibles
        Dim amount As Decimal
        Dim result As Decimal
        Dim dollar As Double
        Dim yen As Integer
        Dim euros As Integer
        Dim pesos As Integer

        amount = Val(currencyTextBox.Text)
        dollar = Val(dollarsTextBox.Text)
        result = Val(convertedResultLabel.Text)


        If amount = yen Then
            result = 76.9 * dollar
        ElseIf amount = euros Then
            result = 0.74 * dollar
        ElseIf amount = pesos Then
            result = 14 * dollar
        End If

        convertedResultLabel.Text = String.Format("{0:F}", result)

        dollarsTextBox.Focus()

    End Sub

    Private Sub currencyTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles currencyTextBox.TextChanged
        convertedResultLabel.Text = String.Empty
    End Sub

    Private Sub dollarsTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dollarsTextBox.TextChanged
        convertedResultLabel.Text = String.Empty
    End Sub
End Class ' CurrencyConverterForm



Is This A Good Question/Topic? 0
  • +

Replies To: Currency Converter

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 22 February 2013 - 10:54 PM

Just to inform you nelliegirl the programming language you are using is vb.net not vb6, so please be more careful when choosing the forum to post your question in.

Debugging Skills

This post has been edited by AdamSpeight2008: 22 February 2013 - 10:58 PM

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: Currency Converter

Posted 22 February 2013 - 11:19 PM

Sorry about that hit the wrong button. Did you see what I am doing wrong in my code.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 22 February 2013 - 11:24 PM

Step through the code with the debugger does the code actually do what you think it does.
If not what differs?
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Currency Converter

Posted 22 February 2013 - 11:27 PM

View Postnelliegirl, on 22 February 2013 - 11:40 PM, said:

This is my code every time I change the convert from dollar to Yen, euros or pesos I get the same total every time. example: I enter 20.00 for the first textbox, yen for the second and my total result would be 1538.00 and if I change it to euros or pesos I get the same result. Also the example in my text book the have a different total then what I have the total the have for my example is total result s 2130.00

In your code, you have a line: If amount = yen Then

Ask yourself what decimal value "yen" has.
There are a few other lines of similar errors.

Above your Class statement, I would recommend putting two lines:

Option Explicit On
Option Strict On


Now look at your code again. Fix all the errors that are shown by the wiggly underline. Hint: At the end of the wiggly underline, you'll find a short red underline. driving your mouse cursor over that will cause an exclamation mark to show up. Clicking on it will often bring up a way to fix it. Clicking on that will apply the fix.

As well, you should learn how to debug your code. See our Debugging Tutorial.
Was This Post Helpful? 0
  • +
  • -

#6 nelliegirl  Icon User is offline

  • D.I.C Head

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

Re: Currency Converter

Posted 22 February 2013 - 11:42 PM

Thanks I forgot about the two lines. I started debugging it and it only goes throught the first if statement and then it steps out. I am not understanding why.
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 22 February 2013 - 11:54 PM

It'll step out because you have no "default" else on the if statement.
Was This Post Helpful? 0
  • +
  • -

#8 nelliegirl  Icon User is offline

  • D.I.C Head

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

Re: Currency Converter

Posted 23 February 2013 - 12:09 AM

I don't understand. I change my last elseif to else statement and that didn't work.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 23 February 2013 - 12:12 AM

Imagine what to do if all of the if statements are false.

If amount = yen Then
  result = 76.9 * dollar
ElseIf amount = euros Then
  result = 0.74 * dollar
ElseIf amount = pesos Then
  result = 14 * dollar
Else
  ' What to do if all of the above are false.
End If


This post has been edited by AdamSpeight2008: 23 February 2013 - 12:14 AM

Was This Post Helpful? 0
  • +
  • -

#10 nelliegirl  Icon User is offline

  • D.I.C Head

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

Re: Currency Converter

Posted 23 February 2013 - 12:19 AM

Ok I did that but it doesn't matter it is not calculating correctly if I type yen, euros or pesos I get the same answer.
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 23 February 2013 - 12:35 AM

You are typing yen into a textbox? then converting that text into a integer variable named yen.

This will result in the variable with a value of zero (0).

This post has been edited by AdamSpeight2008: 23 February 2013 - 12:39 AM

Was This Post Helpful? 0
  • +
  • -

#12 nelliegirl  Icon User is offline

  • D.I.C Head

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

Re: Currency Converter

Posted 23 February 2013 - 12:44 AM

Thanks for your help I am giving up on this and do some research online.
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Currency Converter

Posted 23 February 2013 - 12:56 AM

What you going to look for in your research?

Simplify the problem. Go create a CONSOLE application (no forms at all).
Then think about the algorithm. Then think about the code.
What types are going to use.

This post has been edited by AdamSpeight2008: 23 February 2013 - 12:56 AM

Was This Post Helpful? 0
  • +
  • -

#14 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Currency Converter

Posted 23 February 2013 - 07:09 AM

View Postnelliegirl, on 23 February 2013 - 01:19 AM, said:

Ok I did that but it doesn't matter it is not calculating correctly if I type yen, euros or pesos I get the same answer.

Again, go back to my post, and put those two lines in. You WILL have errors on those If statements. Look at what the editor is telling you about those errors. Fix them. You'll make progress.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1