| | |
assigning arrays in VB
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
Just got a quick question
I know how to assign arrays using the DIM command, but I want to give the array a set of constant figures that will never change
Under Delphi I would use the following when declaring the array at startup
var
myarray :array[0..8] of integer = (value1, value2, value3, etc, etc)
how can I do this under VB6, I have looked at the MSDN help but it only shows on how to create the DIM array, and nothing about assigning a particular list.
I have set the line as
Dim myarray(8) as integer
but if I add '= (value1, value2, value3, etc, etc) it reports an error
does this mean I have to set each item individually on each line as follows
myarray(0)=value1
myarray(1)=value2
myarray(2)=value3
or is there an easier solution
thanks
I know how to assign arrays using the DIM command, but I want to give the array a set of constant figures that will never change
Under Delphi I would use the following when declaring the array at startup
var
myarray :array[0..8] of integer = (value1, value2, value3, etc, etc)
how can I do this under VB6, I have looked at the MSDN help but it only shows on how to create the DIM array, and nothing about assigning a particular list.
I have set the line as
Dim myarray(8) as integer
but if I add '= (value1, value2, value3, etc, etc) it reports an error
does this mean I have to set each item individually on each line as follows
myarray(0)=value1
myarray(1)=value2
myarray(2)=value3
or is there an easier solution
thanks
The unfortunate answer is that VB ultimately only allows you to assign arrays as such. However, There is a minor solution that you can take into play. Depending on the data type, you can use different predefined functions in VB to return yourself arrays, but it's kind of crappy. There is a function, in VB4-6, Called "Array", but it will only assign variant data types, and to be perfectly honest with you, variant data types suck. They are huge, bulky, and make your program slower than needs be. They are really ugly variable, and should be avoided. You can use the function like this, however:
If The Data Type Were Strings, You could get fancy, and use the split function, but it's not really the same concept as you were wanting:
Or You can create a function to handle this, which is probably the best means of doing so. It's a bit of a pain, compared to a language like Perl, or Delphi, where assigning values is fairly easy.
Let me know how this code works for you, and if you need any further assistance. I'll be glad to help.
The information referenced here, was taken from: devx.com, and the credit belongs to : Francesco Balena.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim theArray() As Variant theArray() = Array("Spring", "Summer", "Fall", "Winter")
If The Data Type Were Strings, You could get fancy, and use the split function, but it's not really the same concept as you were wanting:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
dim strArray as string strArray = split("summer;winter;spring;fall", ";")
Or You can create a function to handle this, which is probably the best means of doing so. It's a bit of a pain, compared to a language like Perl, or Delphi, where assigning values is fairly easy.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Let me know how this code works for you, and if you need any further assistance. I'll be glad to help.
The information referenced here, was taken from: devx.com, and the credit belongs to : Francesco Balena.
![]() |
Similar Threads
- Assigning Arrays (Visual Basic 4 / 5 / 6)
- Arrays (C++)
- FreeBSD only assigning inet6 addresses to ndis0 (*nix Software)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: VB Newbie Help pls
- Next Thread: Stored Procedures in Oracle
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






