In the earlier posting you have learnt several simple VB programming tips how to convert temperature with basis Celcius, Fahrenheit, Rheamur and Kelvin. In this posting you will learn how to make a simple application to convert temperature with multiple basis with VB6 programming. You can select the temperature basis when the program's running.
The scenario of this simple application is as follow:
Now, how to built your simple application? Let's go on to the simple VB programming tips.
First, you have to create a screen design likes below image:
How to create the screen design? Follow step by step of below instructions:
Ok, the screen design already finished. Now, what's the program coding like?
Here it is the program coding. Follow the next simple VB programming tips.
'to add items in combo box
cboBasis.AddItem "Celcius"
cboBasis.AddItem "Fahrenheit"
cboBasis.AddItem "Rheamur"
cboBasis.AddItem "Kelvin"
'call procedure ConvPro
ConvPro
'call procedure ConvPro
ConvPro
Private Sub ConvPro()
If TxtTemp.Text = "" Then
'clear the text of text boxes
TxtCel.Text = ""
TxtFah.Text = ""
TxtRhe.Text = ""
TxtKel.Text = ""
Exit Sub
End If
'if Basis is blank then fill in with "Celcius" as default
If cboBasis.Text = "" Then
cboBasis.Text = "Celcius"
End If
Select Case cboBasis.Text
Case "Celcius"
GoTo ConvCel
Case "Fahrenheit"
GoTo ConvFah
Case "Rheamur"
GoTo ConvRhe
Case Else
GoTo ConvKel
End Select
'conversion for celcius basis
ConvCel:
TxtCel.Text = Val(TxtTemp.Text)
TxtFah.Text = Val(TxtTemp.Text) * 1.8 + 32
TxtRhe.Text = Val(TxtTemp.Text) * 0.8
TxtKel.Text = Val(TxtTemp.Text) + 273.15
Exit Sub
'conversion for fahrenheit basis
ConvFah:
TxtFah.Text = Val(TxtTemp.Text)
TxtCel.Text = (Val(TxtTemp.Text) - 32) / 1.8
TxtRhe.Text = ((Val(TxtTemp.Text) - 32) / 1.8) * 0.8
TxtKel.Text = ((Val(TxtTemp.Text) - 32) / 1.8) + 273.15
Exit Sub
'conversion for rheamur basis
ConvRhe:
TxtRhe.Text = Val(TxtTemp.Text)
TxtCel.Text = Val(TxtTemp.Text) / 0.8
TxtFah.Text = ((Val(TxtTemp.Text) / 0.8) * 1.8) + 32
TxtKel.Text = (Val(TxtTemp.Text) / 0.8) + 273.15
Exit Sub
'conversion for kelvin basis
ConvKel:
TxtKel.Text = Val(TxtTemp.Text)
TxtCel.Text = Val(TxtTemp.Text) - 273.15
TxtRhe.Text = (Val(TxtTemp.Text) - 273.15) * 0.8
TxtFah.Text = ((Val(TxtTemp.Text) - 273.15) * 1.8) + 32
End Sub
So your program will look like below listing:
Private Sub ConvPro()
If TxtTemp.Text = "" Then
'clear text of text boxex
TxtCel.Text = ""
TxtFah.Text = ""
TxtRhe.Text = ""
TxtKel.Text = ""
Exit Sub
End If
'if Basis is blank then fill in with "Celcius"
If cboBasis.Text = "" Then
cboBasis.Text = "Celcius"
End If
Select Case cboBasis.Text
Case "Celcius"
GoTo ConvCel
Case "Fahrenheit"
GoTo ConvFah
Case "Rheamur"
GoTo ConvRhe
Case Else
GoTo ConvKel
End Select
'conversion for celcius basis
ConvCel:
TxtCel.Text = Val(TxtTemp.Text)
TxtFah.Text = Val(TxtTemp.Text) * 1.8 + 32
TxtRhe.Text = Val(TxtTemp.Text) * 0.8
TxtKel.Text = Val(TxtTemp.Text) + 273.15
Exit Sub
'conversion for fahrenheit basis
ConvFah:
TxtFah.Text = Val(TxtTemp.Text)
TxtCel.Text = (Val(TxtTemp.Text) - 32) / 1.8
TxtRhe.Text = ((Val(TxtTemp.Text) - 32) / 1.8) * 0.8
TxtKel.Text = ((Val(TxtTemp.Text) - 32) / 1.8) + 273.15
Exit Sub
'conversion for rheamur basis
ConvRhe:
TxtRhe.Text = Val(TxtTemp.Text)
TxtCel.Text = Val(TxtTemp.Text) / 0.8
TxtFah.Text = ((Val(TxtTemp.Text) / 0.8) * 1.8) + 32
TxtKel.Text = (Val(TxtTemp.Text) / 0.8) + 273.15
Exit Sub
'conversion for kelvin basis
ConvKel:
TxtKel.Text = Val(TxtTemp.Text)
TxtCel.Text = Val(TxtTemp.Text) - 273.15
TxtRhe.Text = (Val(TxtTemp.Text) - 273.15) * 0.8
TxtFah.Text = ((Val(TxtTemp.Text) - 273.15) * 1.8) + 32
End Sub
Private Sub cboBasis_Click()
'call procedure ConvPro
ConvPro
End Sub
Private Sub Form_Load()
'to add items in combo box
cboBasis.AddItem "Celcius"
cboBasis.AddItem "Fahrenheit"
cboBasis.AddItem "Rheamur"
cboBasis.AddItem "Kelvin"
End Sub
Private Sub TxtTemp_Change()
'call procedure ConvPro
ConvPro
End Sub
What happen? The conversion should automatically occurs, so the results appear on the each text box. Look at below image for your illustration. Your program should look like it.
1 comments:
Awesome.Thanks for sharing this regarding temperature conversion.This help me lot to done my project.
Post a Comment