vb中 boolean怎么用?

有什么例子可以理解理解吗?
或者我有个代码 ,大家看看哪儿错了?
Private Sub Command1_Click()
Picture1.AutoSize = True
Picture1.ScaleMode = 3
Picture1.Picture = LoadPicture("c:\1.bmp")
End Sub

Private Sub Command2_Click()
Dim bool() As Boolean
Dim a() As Long
Dim b() As Long
x = 1
For j = 1 To 1000
If bool(j) = True And x = 1 Then a(z) = j And x = 2 Else
If bool(j) = False And x = 2 Then b(z) = j And x = 1

Next
Print a(z), b(z)
End Sub

Function bool() As Boolean
For i = 1 To 1000
If Picture1.Point(i, j) = 0 Then bool(j) = True
Next
End Function

问题在
Function bool() As Boolean

Dim bool() As Boolean
这里

犯的错误有三:
一、函数名称和变量名称相同,产生二义性,必须有所区别
二、函数是没有数组形式的,但可以接受数组作为参数,如
Function nbool(bool() as boolean)
三、定义动态数组,调用时,必须redim,且指定数组的长度,如:
dim bool() as boolean
redim bool(1 to 1000) as boolean
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-07-14
你的bool函数定义错误,定义函数的方法也没搞明白,下面是我给你改的代码:
Function bool(kj as Integer ) As Boolean '传导j的值
For i = 1 To 1000
If Picture1.Point(i, kj) = 0 Then bool = True '应该是函数名作为返回变量
Next
End Function

上午没仔细看你的程序,原来你循环也有问题啊,你是不是要打印出两列,前面一列正确,后面一列错误啊?帮你改了下,你的bool函数里循环是没有用的,只会返回最后一个值,下面是改后的代码:

Private Sub Command2_Click()
Dim bool() As Boolean
Dim a() As Long
Dim b() As Long
x = 1
for i=1 to 1000
For j = 1 To 1000
If bool(i,j) = True And x = 1 Then
a(z) = j : x = 2
Print a(z)
End if
If bool(i,j) = False And x = 2 Then
b(z) = j :x = 1
Print ,b(z)
End if
Next j
next i
End Sub

Function bool(ki as integer,kj as Integer ) As Boolean '传导i,j的值
If Picture1.Point(ki, kj) = 0 Then bool = True '应该是函数名作为返回变量
End Function
第2个回答  2009-07-13
dim i as integer
dim j as integer
dim c as boolean
c = a(0)
for i = 0 to h - 1
if a(i) and (not) c then
b( j) = i
j=j+1
end if
c = a(i)
next i

这里 if a(i) and (not) c then 就是当前行是黑的前面的行是白的

hi 出了点问题,解释写在这了
第3个回答  2021-01-03

第40期 Arduino入门爱欧篇 04:boolean