VB中已经定义了变量为什么编译的时候还是出现未定义变量的现象
Option Explicit '强制声明Dim V40 As Single
Dim R40 As Single
Dim L40 As Single
Dim C40 As Single
Dim F40 As Single
Dim XL40 As Single '声明感抗为单精度类型
Dim RF40 As Single '声明反馈电阻为单精度类型
Dim XC40 As Single '声明容抗为单精度类型
Dim I40 As Single
Dim Z40 As Single '声明容抗为单精度类型
Dim IR As Single '声明电阻电流为单精度类型
Dim IC As Single '声明电容流为单精度类型
Dim IL As Single '声明电感电流为单精度类型
Const vbkeyDecPt = 46 '定义 vbkeyDecPt为46
Const pi = 22 / 7 '定义pi为22/7
Private Sub calculate_Click() '计算按钮的敲击事件
I40 = Val(TextI40.Text)
R40 = Val(TextR40.Text) '将电阻文本框里的文本转为数值
L40 = Val(TextL40.Text)
C40 = Val(TextC40.Text)
F40 = Val(TextF40.Text)
If L40 = 0 Then
XL40 = 0
Else
XL40 = 2 * pi * F40 * L40 '计算感抗
End If
If C40 = 0 Then
XC40 = 0
Else
XC40 = 1 / (2 * pi * F40 * C40) '计算容抗
End If
If L40 = 0 Or C40 = 0 Then
LblRF40.Caption = " "
Else
RF40 = 1 / (2 * pi * (L40 * C40) ^ (1 / 2)) '计算共振频率
End If
Z40 = 1 / ((1 / R40) ^ 2 + (1 / XL40 - 1 / XC40) ^ 2) ^ (1 / 2) '计算阻抗
V40 = I40 * Z40 '计算电流
IR = V40 / R40 '计算电阻电流
IC = V40 / XC40 '计算电容电流
IL = V40 / XL40 '计算电感电流
LblZ40.Caption = Format$(Z40, "###.00ohms") '格式化输出阻抗值,双精度保留两位小数
LblV40.Caption = Format$(V40, "###.000000A") '格式化输出电压值,双精度保留六位小数
LblRF40.Caption = Format$(RF40, "###.0000HZ") '格式化输出共振频率值,双精度保留四位小数
LblIR.Caption = Format$(IR, "###.0000A") '格式化输出电阻电流值,双精度保留四位小数
LblIC.Caption = Format$(IC, "###.0000A") '格式化输出电容电流值,双精度保留四位小数
LblIL.Caption = Format$(IL, "###.0000A") '格式化输出电感电流值,双精度保留四位小数
End Sub
Private Sub clear_Click() '清除声明
TextI40.Text = " " '清空电流文本框
TextR40.Text = " "
TextL40.Text = " "
TextC40.Text = " "
TextF40.Text = " "
LblZ40.Caption = " " '清空所得阻抗值
LblV40.Caption = " "
LblRF40.Caption = " "
LblIR.Caption = " "
LblIC.Caption = " "
LblIL.Caption = " "
End Sub