找回密码
 立即注册
搜索

菜鸟关于vba的问题

2
回复
460
查看
[复制链接]

6

主题

188

帖子

31

幻币

一流武者

Rank: 3Rank: 3

积分
230
QQ
2016-4-12 13:28:13 显示全部楼层 |阅读模式
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A As Integer
E = 0
I = 0
S = 0
N = 0
T = 0
F = 0
J = 0
P = 0
LT = 0
For A = 17 To 105 Step 8
E = Val("TextBox" & A) + E
Next A
For A = 18 To 106 Step 8
I = Val("TextBox" & A) + I
Next A
For A = 19 To 107 Step 8
S = Val("TextBox" & A) + S
Next A
For A = 20 To 108 Step 8
N = Val("TextBox" & A) + N
Next A
For A = 21 To 109 Step 8
T = Val("TextBox" & A) + T
Next A
For A = 22 To 110 Step 8
F = Val("TextBox" & A) + F
Next A
For A = 23 To 111 Step 8
J = Val("TextBox" & A) + J
Next A
For A = 24 To 112 Step 8
P = Val("TextBox" & A) + P
Next A
For A = 17 To 111 Step 2
If "TextBox" & A = "" And "TextBox" & (A + 1) = "" Then LT = LT + 1
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E" & E & "分,I" & I & "分,S" & S & "分,N" & N & "分,T" & T & "分,F" & F & "分,J" & J & "分,P" & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!”"
If E > I Then TextBox113.Text = "E" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else TextBox116.Text = "P"
End Sub
运行完变量都为0,恳请指正,谢谢!
PPT学习论坛
回复

使用道具 举报

11

主题

219

帖子

24

幻币

一流武者

Rank: 3Rank: 3

积分
264
QQ
2016-4-12 15:18:15 显示全部楼层
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A, B As Integer
For A = 17 To 112
For B = 0 To 11
If A = 17 + B * 8 Then E = E + Val("TEXTBOX" & A)
If A = 18 + B * 8 Then I = I + Val("TEXTBOX" & A)
If A = 19 + B * 8 Then S = S + Val("TEXTBOX" & A)
If A = 20 + B * 8 Then N = N + Val("TEXTBOX" & A)
If A = 21 + B * 8 Then T = T + Val("TEXTBOX" & A)
If A = 22 + B * 8 Then F = F + Val("TEXTBOX" & A)
If A = 23 + B * 8 Then J = J + Val("TEXTBOX" & A)
If A = 24 + B * 8 Then P = P + Val("TEXTBOX" & A)
If Val("TEXTBOX" & A) = 0 Then LT = LT + 1 / 2
Next B
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E" & E & "分,I" & I & "分,S" & S & "分,N" & N & "分,T" & T & "分,F" & F & "分,J" & J & "分,P" & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!”"
If E > I Then TextBox113.Text = "E" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else TextBox116.Text = "P"
End Sub
简化为上面的形式,仍然不对。
PPT学习论坛
回复 支持 反对

使用道具 举报

17

主题

217

帖子

47

幻币

一流武者

Rank: 3Rank: 3

积分
279
QQ
2016-4-12 15:52:53 显示全部楼层
解决了,这样改的:
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A, B As Integer
For A = 17 To 112
    For B = 0 To 11
        If A = 17 + B * 8 Then E = Val(Me("TextBox" & A).Value) + E: GoTo 1
        If A = 18 + B * 8 Then I = I + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 19 + B * 8 Then S = S + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 20 + B * 8 Then N = N + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 21 + B * 8 Then T = T + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 22 + B * 8 Then F = F + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 23 + B * 8 Then J = J + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 24 + B * 8 Then P = P + Val(Me("TextBox" & A).Value): GoTo 1
    Next B
1:
If Val(Me("TextBox" & A).Value) = 0 Then LT = LT + 1 / 2
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E: " & E & "分,I: " & I & "分,S: " & S & "分,N: " & N & "分,T: " & T & "分,F: " & F & "分,J: " & J & "分,P: " & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!"
If E > I Then TextBox113.Text = "E" Else If E = I Then TextBox113.Text = "?" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else If S = N Then TextBox114.Text = "?" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else If T = F Then TextBox115.Text = "?" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else If J = P Then TextBox116.Text = "?" Else TextBox116.Text = "P"
End Sub
PPT学习论坛
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册