作业帮 > 综合 > 作业

运行提示变量不能用在该表达式何故?(附代码)

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/05 17:30:26
运行提示变量不能用在该表达式何故?(附代码)
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
首先,你出现这个错误的原因是你的枚举常量里面已经定义了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 Su