Basic Visual Basic - Variable Conversion Tutorial

aka ibebak

Paragon
Joined
Aug 7, 2008
Messages
1,181
Reaction score
0
FP$
6
We're moving quickly in my computer programming class, I've developed my own style of coding, and my teacher says what I did today is a bit advanced, so I'll post a small mini-tutorial for anyone interested in learning visual basic.

What this does is convert cm to inches.

Variables used:
Switch: - Controls the radio button selection of each type of measurement; ie: Inches or Cm.
decMeasurement - Grabs and stores the measurement inputted in the textbox on the form.
decFinalOutput - The final converted number.

Just take a look at the code, it's pretty self-explanatory,
Code:
'Connor L.
'3/29/2012
'Program 4 - Variables

Public Class frmMain
    Dim switch As Integer
    Private Sub radInches_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radInches.CheckedChanged
        lblMeasurement.Text = "Centimeters:"
        switch = "1"
    End Sub

    Private Sub radCentimeters_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radCentimeters.CheckedChanged
        lblMeasurement.Text = "Inches:"
        switch = "2"
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim decMeasurement As Decimal
        Dim decFinalOutput As Decimal

        decMeasurement = Val(Me.txtInput.Text)

        If switch = 1 Then
            decFinalOutput = decMeasurement * 0.393700787

        ElseIf switch = 2 Then
            decFinalOutput = decMeasurement * 2.54
        End If

        lblResult.Text = "The measurement is " & decFinalOutput & "."
    End Sub
End Class
 
Not bad 😛, Very simple

My advice when making tutorials is to provide maybe screenshots or something for new comers 🙂
 
Nice for somebody who is new to visual basic like I am
Do you think Visual Basic is good for game development??
 
Back
Top Bottom