Forum Discussion
6 Replies
Sort By
- AlexKarasChampion Level 3Hi,
Dim arr(7)
arr(0)=1
arr(1)=2
arr(2)=3
arr(3)=4
arr(4)=5
arr(5)=6
arr(6)=7 - venkat001Occasional ContributorThanks Alexei,
Any other method of declaring. F.Ex. if we get 'n' no of elements from the user and wants to process each element by reading it from for loop and do some action depends on case logic.
Ex:
User Input: 1,5,8,6,9,10....n
Code:
Sub Expectedinfo( array_input)
Dim arr()
arr()= array_input
a=ubound(arr()) ' to identify array size
For i=0 to a
'' Statements
Next
End Sub
Regards,
Venkates K - hlalumiereRegular ContributorWell if you get a string like this: "1,2,3,4,5,6", you can use Split() to transform that into an array.
If you receive an array why would you need to cast it? - venkat001Occasional ContributorThanks Hugo
Well, split() function is good when i know my array with pre-defined delimiter, suppose if i want read cell values from excel and want to put it an array elements. In that case we may not know array size so we need to read from for loop.
Ex.
Sub array
Dim arr()
For i=0 to 10
a(i)= Excel.cells(i,1) ' getting error in a(i)
Next
End sub
Regards,
venkates k - sastoweSuper ContributorIs the CELLS collection 0 based or 1 based?
- venkat001Occasional ContributorThanks to all.
Got solution. when we declare dynamic array DIM arr() and try to asign the value before declaring the array dimension. we will get error message.
Ex. To read Excel data
Sub Temp
Dim arr()
''' Statements to be added '''''
x= Excel.Application.Activesheet.Usedrange.rows.count
y= Excel.Application.Activesheet.Usedrange.columns.count
ReDim arr(x)
For i=0 to x
Forj=0 to
arr(i,j)=Excel.cells(i+1,j+1)
Next
Next
End Sub
Regards,
Venkates K
Related Content
- 2 years agobknutson
Recent Discussions
- 57 minutes agoJacobjacob44