If a(1, 2) > a(1, 1) And a(1, 3) > a(1, 2) And a(2, 2) > a(2, 1) And a(2, 3) > a(2, 2) Then col = True
If a(2, 1) > a(1, 1) And a(2, 2) > a(1, 2) And a(2, 3) > a(1, 3) Then row = True
If col = True And row = True Then '让人难以理解的是这两个变量居然是True!
Label1.Caption = a(1, 1)
Label2.Caption = a(1, 2)
Label3.Caption = a(1, 3)
Label4.Caption = a(2, 1)
Label5.Caption = a(2, 2)
Label6.Caption = a(2, 3)
End If 天哪,执行如上语句,六个label的caption分别显示的是1,5,5,5,5,6。为什么呀?这样的话逻辑变量col和row的值应该都是False啊!莫非显示的并不是数组的值?
If a(2, 1) > a(1, 1) And a(2, 2) > a(1, 2) And a(2, 3) > a(1, 3) Then row = True
If col = True And row = True Then '让人难以理解的是这两个变量居然是True!
Label1.Caption = a(1, 1)
Label2.Caption = a(1, 2)
Label3.Caption = a(1, 3)
Label4.Caption = a(2, 1)
Label5.Caption = a(2, 2)
Label6.Caption = a(2, 3)
End If 天哪,执行如上语句,六个label的caption分别显示的是1,5,5,5,5,6。为什么呀?这样的话逻辑变量col和row的值应该都是False啊!莫非显示的并不是数组的值?
col和row 我都定义的是窗体变量.在窗体的装载事件中就赋值为false了。
'/*************************************************************************************/
'把123456填入如下表格内:'----------------------
'| | | |
'| | | |
'----------------------
'| | | |
'| | | |
'----------------------'要求:1、每一列右边的数字比左边的大
' 2、每一行下面的数字比上面的大
'/*************************************************************************************/Option Base 1 ' 设定数组下限从数字1开始Option ExplicitDim a(2, 3), i, j As Integer
Dim b(4) As Integer
Dim a1, a2, a3, a4 As Integer
Dim col, row As BooleanPrivate Sub Command1_Click()
Dim b(4), i As Integer
Randomize
i = 1
j = 1
For i = 1 To 2 '将数组清零
For j = 1 To 3
a(i, j) = 0
Next j
Next i
b(1) = 2
For i = 2 To 4
b(i) = i + 1
Next i
a(1, 1) = 1
a(2, 3) = 6
For a1 = 1 To 4
For a2 = 1 To 4
For a3 = 1 To 4
For a4 = 1 To 4
a(1, 2) = b(a1)
a(1, 3) = b(a2)
a(2, 1) = b(a3)
a(2, 2) = b(a4)
If (a(1, 2) > a(1, 1)) And (a(1, 3) > a(1, 2)) And (a(2, 2) > a(2, 1)) And (a(2, 3) > a(2, 2)) Then col = True
If (a(2, 1) > a(1, 1)) And (a(2, 2) > a(1, 2)) And (a(2, 3) > a(1, 3)) Then row = True
If col = True And row = True Then
Label1.Caption = a(1, 1)
Label2.Caption = a(1, 2)
Label3.Caption = a(1, 3)
Label4.Caption = a(2, 1)
Label5.Caption = a(2, 2)
Label6.Caption = a(2, 3)
For i = 1 To 10
For j = 1 To 10000
Next j
Next i
End If
Next a4
Next a3
Next a2
Next a1
End SubPrivate Sub Command2_Click()
End
End SubPrivate Sub Form_Load()
i = 1
j = 1
For i = 1 To 2
For j = 1 To 3
a(i, j) = 0
Next j
Next i
col = False
row = False
End Sub
帮帮忙哈.
if col= (true and (row=true))
if (col= (true and row)) =true
if col= ((true and row) =true)是哪一种?
你改成这样试试
...
If col = True And row = True Then
stop'<-----加一行
Label1.Caption = a(1, 1)
..
运行暂停时,你看看那些值是什么,我看了几个,基本正常
If (a(1, 2) > a(1, 1)) And (a(1, 3) > a(1, 2)) And (a(2, 2) > a(2, 1)) And (a(2, 3) > a(2, 2)) Then
col = True
Else
col = False
End IfIf (a(2, 1) > a(1, 1)) And (a(2, 2) > a(1, 2)) And (a(2, 3) > a(1, 3)) Then
row = True
Else
row = False
End If