![]() |
Excel 2007 Need help for test
I hope somebody can please help asap. I have a huge computer
programming exam tomorrow and I do not understand how to use the redim statement with dynamic arrays or how to call a subroutine. I have to know how to do both by tomorrow. Could sombody please break it down to me. I have been reading excel 2007 vba for dummies but it kind of skips over these two areas. |
Excel 2007 Need help for test
Have you looked at http://support.microsoft.com/kb/142134 (which was the
first thing Google found on the subject)? -- David Biddulph wrote in message ... I hope somebody can please help asap. I have a huge computer programming exam tomorrow and I do not understand how to use the redim statement with dynamic arrays or how to call a subroutine. I have to know how to do both by tomorrow. Could sombody please break it down to me. I have been reading excel 2007 vba for dummies but it kind of skips over these two areas. |
Excel 2007 Need help for test
When you declare a dynamic array, use the following syntax:
Dim myArray() as Integer At that point, the size is not determined. You use the ReDim statement as follows: ReDim myArray(20) This will create an array of 20 elements. The first element is referred to as follows: myArray(lBound(myArray)) = 1 The last element is referred to as follows: myArray(uBound(myArray)) = 2 If you ReDim the array again, all the data in it will be overwritten. To leave the data, you use the Preserve keyword: ReDim Preserve myArray(50) Doing so will leave intact the first 20 items (if you have populated them), and create 30 new ones. Here's a subroutine example. I'll call the subroutine mySub: Public Sub mySub() ' do stuff here End Sub Now, let's say your main routine is called MainRoutine, which calls mySub: Public Sub MainRoutine() Call mySub() End Sub On Nov 28, 2:12 pm, wrote: I hope somebody can please help asap. I have a huge computer programming exam tomorrow and I do not understand how to use the redim statement with dynamic arrays or how to call a subroutine. I have to know how to do both by tomorrow. Could sombody please break it down to me. I have been reading excel 2007 vba for dummies but it kind of skips over these two areas. |
Excel 2007 Need help for test
Unless you do something special:
ReDim myArray(20) will result in an array with 21 elements. It'll be the same as: ReDim myArray(0 to 20) I find that always specifying the upper and lower bounds makes the code more self-documenting. iliace wrote: When you declare a dynamic array, use the following syntax: Dim myArray() as Integer At that point, the size is not determined. You use the ReDim statement as follows: ReDim myArray(20) This will create an array of 20 elements. The first element is referred to as follows: myArray(lBound(myArray)) = 1 The last element is referred to as follows: myArray(uBound(myArray)) = 2 If you ReDim the array again, all the data in it will be overwritten. To leave the data, you use the Preserve keyword: ReDim Preserve myArray(50) Doing so will leave intact the first 20 items (if you have populated them), and create 30 new ones. Here's a subroutine example. I'll call the subroutine mySub: Public Sub mySub() ' do stuff here End Sub Now, let's say your main routine is called MainRoutine, which calls mySub: Public Sub MainRoutine() Call mySub() End Sub On Nov 28, 2:12 pm, wrote: I hope somebody can please help asap. I have a huge computer programming exam tomorrow and I do not understand how to use the redim statement with dynamic arrays or how to call a subroutine. I have to know how to do both by tomorrow. Could sombody please break it down to me. I have been reading excel 2007 vba for dummies but it kind of skips over these two areas. -- Dave Peterson |
All times are GMT +1. The time now is 12:21 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com