Visual Studio Conversion Suite
Posted
by KingPop
on Stack Overflow
See other posts from Stack Overflow
or by KingPop
Published on 2010-05-24T10:07:24Z
Indexed on
2010/05/24
10:11 UTC
Read the original article
Hit count: 530
I have this as my conversion program for the "Length", how can I do it the simpliest way instead of keeping the if, elseif, else too much, i do not have much experience and trying to improve my programming skills on visual studio 2008.
Basically, I get annoyed with the formulas because I don't know if it is right, I use google but doesn't help because i don't know how to get it right when the program converts from type to type.
Public Class Form2
Dim Metres As Integer
Dim Centimetres As Integer
Dim Inches As Integer
Dim Feet As Integer
Dim Total As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ErrorMsg.Hide()
End Sub
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
Metres = 1
Centimetres = 0.01
Inches = 0.0254
Feet = 0.3048
txtTo.Text = 0
If txtFrom.Text <> "" Then
If IsNumeric(txtFrom.Text) And IsNumeric(txtTo.Text) Then
If cbFrom.Text = "Metres" And cbTo.Text = "Centimetres" Then
Total = txtFrom.Text * Metres
txtTo.Text = Total
ElseIf cbFrom.Text = "Metres" And cbTo.Text = "Inches" Then
Total = txtFrom.Text * 100
txtTo.Text = Total
ElseIf cbFrom.Text = "Metres" And cbTo.Text = "Feet" Then
ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Metres" Then
ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Inches" Then
ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Feet" Then
ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Metres" Then
ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Centimetres" Then
ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Feet" Then
ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Metres" Then
ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Centimetres" Then
ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Inches" Then
End If
End If
End If
End Sub
End Class
This is the source for what I have done at the moment.
© Stack Overflow or respective owner