473,605 Members | 2,095 Online

# array of booleans?

Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?
Nov 21 '05 #1
6 22043
This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?

Dim arr() As Boolean = {b1, b2, b3}
For i As Integer = 0 To arr.Length - 1
arr(i) = True
Next

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Nov 21 '05 #2
Dim bArray(9) As Boolean

For lCnt As Integer = 0 To bArray.Length - 1
bArray(lCnt) = True
Next lCnt

Imran.

"chech" <ch***@c.com> wrote in message
news:21******** *************** *****@phx.gbl.. .
Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?

Nov 21 '05 #3
Sub objthing()
Dim B1 As Boolean, B2 As Boolean, B3 As Boolean
Dim obj(2) As boolean
obj(0) = Bn1
obj(1) = Bn2
obj(2) = Bn3
Bn1 = False
For i As Integer = 0 To obj.Length - 1
obj(i) = True
Next
Console.WriteLi ne(Bn1) 'Bn1 is still False
End Sub

Is there some kind of structure I could place my booleans
into where I could use them in a loop as above? Would an
Arraylist work? Or some kind of pointer structure?
-----Original Message-----
Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?
.

Nov 21 '05 #4
* "chech" <ch***@c.com> scripsit:
Possible to have array of booleans?

In addition to the other replies: Make sure you read the documentation
on value types, reference types, and boxing.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5
In article <21************ *************** *@phx.gbl>, chech wrote:
Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?

Option Explicit On
Option Strict On

Module Module1

Sub Main()
Dim booleans() As Boolean = {True, True, True, True, True, True}

For Each b As Boolean In booleans
Console.WriteLi ne(b)
Next b

For i As Integer = 0 To booleans.Length - 1
booleans(i) = False
Next i

For Each b As Boolean In booleans
Console.WriteLi ne(b)
Next b
End Sub

End Module

--
Tom Shelton [MVP]
Nov 21 '05 #6
Chech,

Why not you can have from every object an array

Cor
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.