如何在VisualBasic中制作长度转换器

电子说

1.2w人已加入

描述

步骤1:创建项目

VisualBasic

VisualBasic

步骤1:打开 Microsoft Visual Basic。

步骤2:通过单击创建新项目新项目 或按 Ctrl + N 。

步骤3:选择 Windows窗体应用程序 ,并将其命名为“ Length Converter ”。

步骤4:重命名 Form1.vb 更改为“ Length.vb ”。 这是易于使用的方法。

步骤5:将 Form1 重命名为“ LengthForm ”,并将文本设置为“ Length Converter ”。 这是易于使用的方法。

步骤6:根据自己的喜好调整大小。我已经制作了一个‘ 500,300’ 。

第7步:在表格顶部插入标签,然后将命名为“ 标题 ”,并输入文字“ 长度 转换器 “

第8步:插入两个按钮。一个在中心。将其命名为“ ConvertButton ”,并输入文字“ Convert ”。 第二个按钮是可选的。 将其放在右上角,并将其命名为“ ExitButton ”,并输入文字“ Exit 》“

步骤9:插入两个ComboBox,将其中一个放置在左侧,将另一个放置在右侧。在左侧命名为“ LengthList1 ”,在右侧命名为“ LengthList2 ”。使它们两个上的文字均为“ 选择 单位 ”

第10步:插入两个文本框并将其放置在组合框下方。将它们命名为“ UnitText1 ”和“ UnitText2 ”。将文本留空。

步骤2:获取基本代码

VisualBasic

步骤11:双击‘ExitButton’。

步骤12:插入以下代码:‘This will close the application’

Me.Close() 步骤13:双击点击“转换按钮”。

步骤14:插入以下代码:

‘These are the Boolean for the Length in the first box’

Dim Mile1 As Boolean

Dim KM1 As Boolean

Dim M1 As Boolean

Dim CM1 As Boolean

‘These are the Boolean for the length in the second box’

Dim Mile2 As Boolean

Dim KM2 As Boolean

Dim M2 As Boolean

Dim CM2 As Boolean

‘These are the inserted numbers that will be converted’

Dim Num1 As String

Num1 = UnitText1.Text

Dim Num1 As String

Num2 = UnitText2.Text

步骤3 :转换单位

VisualBasic

步骤15:在先前的代码下方插入以下内容:

‘What it is converting’

If LengthList1.Text = (“Mile”) And LengthList2.Text = (“Kilometre”) Then

Mile1 = True

KM2 = True

End If

‘The equation for the conversion’

If Mile1 = True and KM2 = True Then

UnitText2.Text = Num1 / 0.62137

End If

If LengthList1.Text = (“Mile”) And LengthList2.Text = (“Metre”) Then

Mile1 = True

M2 = True

End If

If Mile1 = True and M2 = True Then

UnitText2.Text = Num1 / 0.0062137

End If

If LengthList1.Text = (“Mile”) And LengthList2.Text = (“Centimetre”) Then

Mile1 = True

CM2 = True

End If

If Mile1 = True and CM2 = True Then

UnitText2.Text = Num1 / 0.0000062137

End If

If LengthList1.Text = (“Kilometre”) And LengthList2.Text = (“Mile”) Then

KM1 = True

Mile2 = True

End If

If KM1 = True and Mile2 = True Then

UnitText2.Text = Num1 * 0.62137

End If

If LengthList1.Text = (“Kilometre”) And LengthList2.Text = (“Metre”) Then

KM1 = True

M2 = True

End If

If KM1 = True and M2 = True Then

UnitText2.Text = Num1 / 0.001

End If

If LengthList1.Text = (“Kilometre”) And LengthList2.Text = (“Centimetre”) Then

KM1 = True

CM2 = True

End If

If KM1 = True and CM2 = True Then

UnitText2.Text = Num1 / 0.000001

End If

If LengthList1.Text = (“Metre”) And LengthList2.Text = (“Mile”) Then

M1 = True

Mile2 = True

End If

If M1 = True and Mile2 = True Then

UnitText2.Text = Num1 * 0.000621317

End If

If LengthList1.Text = (“Metre”) And LengthList2.Text = (“Kilometre”) Then

M1 = True

KM2 = True

End If

If M1 = True and KM2 = True Then

UnitText2.Text = Num1 / 1000

End If

If LengthList1.Text = (“Metre”) And LengthList2.Text = (“Centimetre”) Then

M1 = True

CM2 = True

End If

If M1 = True and CM2 = True Then

UnitText2.Text = Num1 / 0.01

End If

If LengthList1.Text = (“Centimetre”) And LengthList2.Text = (“Mile”) Then

CM1 = True

Mile2 = True

End If

If CM1 = True and Mile2 = True Then

UnitText2.Text = Num1 * 0.000000621317

End If

If LengthList1.Text = (“Centimetre”) And LengthList2.Text = (“Kilometre”) Then

CM1 = True

KM2 = True

End If

If CM1 = True and KM2 = True Then

UnitText2.Text = Num1 * 0.00001

End If

If LengthList1.Text = (“Centimetre”) And LengthList2.Text = (“Metre”) Then

CM1 = True

M2 = True

End If

If CM1 = True and M2 = True Then

UnitText2.Text = Num1 * 0.01

End If

‘If converting into same unit then the valve will be the same’

If LengthList1.Text = LengthList2.Text Then

UnitText2.Text = Num1

End If

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分