| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 429 人关注过本帖
标题:奇怪 IF循环莫名其妙停止了
只看楼主 加入收藏
woa
Rank: 1
等 级:新手上路
帖 子:159
专家分:0
注 册:2008-12-4
结帖率:85.37%
收藏
已结贴  问题点数:20 回复次数:1 
奇怪 IF循环莫名其妙停止了
Private Sub Command2_Click()
Dim a As String, b As String, c As String, x As String

x = Text1.Text
a = Text2.Text

Open App.Path & "\1.txt" For Append As #1


If Check1.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-1")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
End If


If Check2.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-2")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
End If


If Check3.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-3")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
End If
Close #1

End Sub




Text1.Text=A5000-55A
Text2.Text=5000-55

选中 Check1 运行结果 Text3.Text=A5000-15A
选中 Check2 运行结果 Text3.Text=A5000-25A
选中 Check3 运行结果 Text3.Text=A5000-35A

全选 则 Text3.Text=A5000-15A
文本输入了3次 A5000-15A 值,而不是A5000-15A A5000-25A  A5000-35A 搞不懂怎么回事

[ 本帖最后由 woa 于 2010-9-8 23:20 编辑 ]
2010-09-08 23:19
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:20 
因为你循环里是判断三次.

全选的情况下,你需要成块判断,而不是独立判断.

优先级,Check1>Check2>Check3 ,就是同时选中 Check1 和 Check2 时,Check1起作用,

程序代码:
If Check1.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-1")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
ElseIf Check2.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-2")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
ElseIf Check3.Value = 1 Then
b = a
c = Mid(b, 5, 2)
b = Replace(b, c, "-3")
x = Replace(x, a, b)
Print #1, x
Text3.Text = x
End If

授人于鱼,不如授人于渔
早已停用QQ了
2010-09-09 08:18
快速回复:奇怪 IF循环莫名其妙停止了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024732 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved