declaring array like in C

clabs
09-08-2003, 07:22 AM
Hi

In C we can declare like this
int[] = {1,2,3,4,5}
means int[0] = 1
int[1] =2.....
how do the same in VB
Now i am doing like this.
dim a() as byte
a(0) = 1
a(1) = 2....
in one line how can do that in VB

Gizm
09-08-2003, 07:35 AM
a = Array(1, 2, 3, 4, 5)G I Z M

clabs
09-08-2003, 08:05 AM
thanks for u r help., i want to store values of byte...as i know that
array function takes ...variant type....
let me know how to do that

clabs
09-08-2003, 08:25 AM
Dim Buffer1 As Variant
Dim bytef(2) As Byte
Dim bytef1

bytef(0) = CByte(65)
bytef(1) = CByte(84)
bytef(2) = CByte(13)

bytef1 = Array(CByte(65), CByte(84), CByte(13))

Buffer1 = bytef
Buffer1 = bytef1
msgbox bytef gives ?
Msgbox bytef1.....Error type mismatch

Let me what is wrong in this...i want to give total array to buffer array how to do that....

00100b
09-08-2003, 08:37 AM
There is probably a more efficient way, but a simple variation of GIZM's response would be (this at least does it in a single line of code as requested):

a = Array(CByte(1), CByte(2), CByte(3), CByte(4), CByte(5))

Where a() is a variant array containing elements of the Byte data type.

Thinker
09-08-2003, 09:51 AM
If you want a pure Byte array you can do this...

Dim myByte() As Byte
Dim myStr As String

myStr = Chr$(1) & Chr$(2) & Chr$(3) & Chr$(4) & Chr$(5)
myByte = StrConv(myStr, vbFromUnicode)

Thanatos
09-08-2003, 09:56 AM
What are you trying to accomplish?
EDIT - Looks like i was too slow. Looks like you've got your answers. :cool:

clabs
09-08-2003, 10:37 PM
thanks for u r replies ...i will check those and let u know ...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum