Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,562 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




If Else statment/currency converter

 
Reply to this topicStart new topic

If Else statment/currency converter

bkostertag
12 May, 2008 - 09:13 PM
Post #1

New D.I.C Head
*

Joined: 12 May, 2008
Posts: 1

I am new to programming. This is a problem from Deitel's simply visual basic 2005. I am trying to use an If Else statement to change dollars to Yen, Euros, and Pesos respectively. No matter what I type into the conversion textbox I get the yen * dollars result. Can anyone help?


vb

Public Class CurrencyConverter

Private Sub conversionButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles conversionButton.Click

' declare variables
Dim dollars As Double
Dim conversion As Decimal
Dim result As Decimal
Dim Yen As Integer
Dim Euros As Integer
Dim Pesos As Integer

' assign values from user input
dollars = Val(dollarsTextBox.Text)
conversion = Val(conversionTextBox.Text)
result = Val(resultLabel.Text)

If conversion = Yen Then
result = 115 * dollars
ElseIf conversion = Euros Then
result = 0.79 * dollars
ElseIf conversion = Pesos Then
result = 11 * dollars
End If

resultLabel.Text = String.Format("{0:F}", result)
End Sub
End Class


This post has been edited by PsychoCoder: 12 May, 2008 - 10:28 PM
User is offlineProfile CardPM
+Quote Post

anand_the_great
RE: If Else Statment/currency Converter
12 May, 2008 - 10:18 PM
Post #2

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 34

Hello.
bkostertag, I think it is best that you use less coding.
It is always a good habit to program to the minimum and use whatever of the convinience in provided in VB.
Example to use the combobox to list your (currencies).
CODE

Combo1.Add "Yen"
Combo1.Add "Euros"
'..... or the easiest is to go to property and enter the value in the "List"
'column. This means no coding.
'***** But always set the Combo1.Text = "your first list, say "Yen" ".
'That is Combo1.Text = "Yen". so that when program start, it points to
'something not null. =).

Private Sub Command_Whatever()
Label1 = ""
txtInput = ""
If Combo1.Text = "Yen" Then Label1 = txtInput * 115
If Combo1.Text = "Euros" Then Label1 = txtInput * 0.79
If Combo1.Text = "Pesos" Then Label1 = txtInput * 11
End Sub


Basically, the only of coding is in your Command_Whatever(). =).
Anand.

This post has been edited by anand_the_great: 12 May, 2008 - 10:35 PM
User is offlineProfile CardPM
+Quote Post

sam_benne
RE: If Else Statment/currency Converter
12 May, 2008 - 10:49 PM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 298



Thanked: 1 times
Dream Kudos: 400
My Contributions
I would use combo box to make it smaller but option buttons can be good and they also allow you to learn more than a combo box as they are more complex and if you are just starting then this would be a good idea. As this helped me learn alot fast.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:43PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month