运行提示变量不能用在该表达式何故?(附代码)Enum zimu '定义字母对应数字的枚举型变量A = 1B = 2C = 3D = 4E = 5F = 6G = 7H = 8i = 9J = 10K = 11L = 12M = 13N = 14O = 15P = 16Q = 17R = 18S = 19T = 20U = 21V = 22W = 23X =
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 21:35:34
运行提示变量不能用在该表达式何故?(附代码)Enum zimu '定义字母对应数字的枚举型变量A = 1B = 2C = 3D = 4E = 5F = 6G = 7H = 8i = 9J = 10K = 11L = 12M = 13N = 14O = 15P = 16Q = 17R = 18S = 19T = 20U = 21V = 22W = 23X =
运行提示变量不能用在该表达式何故?(附代码)
Enum zimu '定义字母对应数字的枚举型变量
A = 1
B = 2
C = 3
D = 4
E = 5
F = 6
G = 7
H = 8
i = 9
J = 10
K = 11
L = 12
M = 13
N = 14
O = 15
P = 16
Q = 17
R = 18
S = 19
T = 20
U = 21
V = 22
W = 23
X = 24
Y = 25
Z = 26
End Enum
Private Sub Command1_Click()
jhm = Text1.Text
Dim zjhm As String
Dim shuzi As zimu
For i = 1 To 15
shuzi = Mid(jhm,i,0) '顺次读取输入的15个大写字母,并转成数值
zjhm = zjhm & shuzi '把这些数值排列连起来,实现字母转数字
Next i
Text1.Text = zjhm
Print zjhm
End Sub
运行提示变量不能用在该表达式何故?(附代码)Enum zimu '定义字母对应数字的枚举型变量A = 1B = 2C = 3D = 4E = 5F = 6G = 7H = 8i = 9J = 10K = 11L = 12M = 13N = 14O = 15P = 16Q = 17R = 18S = 19T = 20U = 21V = 22W = 23X =
首先,你出现这个错误的原因是你的枚举常量里面已经定义了i,下面的for循环里就不能将i作为循环变量了.然后Mid(jhm, i, 0)应改为Mid(jhm, i, 1),每次取一个字符
再者,枚举常量没有转换的功能,它只起到别名的作用,实际值是不变的
因此程序应改为
Private Sub Command1_Click()
jhm = Text1.Text
Dim zjhm As String
Dim shuzi As String
For ii = 1 To 15
shuzi = CStr(Asc(Mid(jhm, ii, 1)) - Asc("A")) '顺次读取输入的15个大写字母,并转成数值
zjhm = zjhm & shuzi '把这些数值排列连起来,实现字母转数字
Next ii
Text1.Text = zjhm
Print zjhm
End Sub