|
|
|
Visual Basic doesn't provide any way to declare an array and initialize its elements at the same time. In most cases you end up with setting individual elements one by one, as in: |
Under VB4, VB5, and VB6 you can create an array of Variants on the fly, using the Array() function: |
but there is no similar function to create arrays of data types other than Variant. If you're using VB6, however, you can create String arrays using the Split() function: |
Under VB6 you can also take advantage of the capability for a Function to return an array, and build your own array initialization routines, such as the following one: |
Click here to copy the following block | Function ArrayInt(ParamArray values() As Variant) As Integer() Dim i As Long ReDim res(0 To UBound(values)) As Integer For i = 0 To UBound(values) res(i) = values(i) Next ArrayInt = res() End Function |
You could also build a routine that tests the type of values passed to it, and returns an array of the correct type. In this case, the function should be declared to return a Variant.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|