高手們,進來見識這個怪問題吧?

chenlishu413 2003-05-20 02:31:07
我在一個FORM中畫了4個TEXT,一個COMMAND,大家幫忙看看代碼那裡有問題.給小弟指出來吧.
Option Explicit

Private Sub Command1_Click()
Dim A(3) As Long
Dim I As Integer

A(0) = Int(4 * Rnd)

RE1:
A(1) = Int(4 * Rnd)
If A(0) <> A(1) Then
Else
GoTo RE1
End If

RE2:
A(2) = Int(4 * Rnd)
If A(0) <> A(1) <> A(2) Then
Else
GoTo RE2
End If

RE3:
A(3) = Int(4 * Rnd)
If A(0) <> A(1) <> A(2) <> A(3) Then
Else
GoTo RE3
End If

Text1 = A(0)
Text2 = A(1)
Text3 = A(2)
Text4 = A(3)


End Sub

運行後居然還有重覆的數值.請大家賜教吧.
...全文
6 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Cooly 2003-05-20
修改一下你的判断.


Dim A(3) As Long
Dim I As Integer
Randomize

A(0) = Int(4 * Rnd)

RE1:
A(1) = Int(4 * Rnd)
If A(0) = A(1) Then
GoTo RE1
End If

RE2:
A(2) = Int(4 * Rnd)
If A(2) = A(0) Or A(2) = A(1) Then
GoTo RE2
End If

RE3:
A(3) = Int(4 * Rnd)
If A(3) = A(0) Or A(3) = A(1) Or A(3) = A(2) Then
GoTo RE3
End If

Text1 = A(0)
Text2 = A(1)
Text3 = A(2)
Text4 = A(3)
回复
Cooly 2003-05-20
加上Randomize就应该可以了
回复
chenlishu413 2003-05-20
我知道呀.不過必要的啦.你幫我找一找我上面程序中出現了什麼錯誤謝謝.
回复
Cooly 2003-05-20
尽量避免使用GOTO.
回复
chenlishu413 2003-05-20
用GOTO 語句不行嗎?
回复
Cooly 2003-05-20
Option Explicit

Private Sub Command1_Click()
Dim A(3) As Long
Dim I As Integer, J As Integer
Randomize '你缺少这一句

For I = 0 To 3
A(I) = Int(Rnd * 4)
If I > 0 Then
For J = 0 To I - 1
If A(I) = A(J) Then
I = I - 1
Exit For
End If
Next
End If

Next
Text1 = A(0)
Text2 = A(1)
Text3 = A(2)
Text4 = A(3)
End Sub
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-20 02:31
社区公告
暂无公告