Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Variables in Declaring an Array

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Variables in Declaring an Array

Take a look for help on the redim statement (note the key work preserve is
required to not clear the values of the array when it is resized.)

dim myArray() as sting
dim n as long

n = 0
redim preserve myArray(n)
myarray(0) = "this"
n = 1
redim preserve myarray(n)
myarray(0) = "that"

--
HTH...

Jim Thomlinson


"Jimmy" wrote:

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Variables in Declaring an Array

2 things jim

you have a typo he
dim myArray() as sting (string)

and should this be:

array(n) = "that"


--


Gary


"Jim Thomlinson" wrote in message
...
Take a look for help on the redim statement (note the key work preserve is
required to not clear the values of the array when it is resized.)

dim myArray() as sting
dim n as long

n = 0
redim preserve myArray(n)
myarray(0) = "this"
n = 1
redim preserve myarray(n)
myarray(0) = "that"

--
HTH...

Jim Thomlinson


"Jimmy" wrote:

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Variables in Declaring an Array

My typing takes a little to be desired... I should really proof read before
hitting the Post button. You are correct on the String thing. As for the
Array(n) = "that"
it was just a quick n dirty demo. Yes n probably makes more sense...
--
HTH...

Jim Thomlinson


"Gary Keramidas" wrote:

2 things jim

you have a typo he
dim myArray() as sting (string)

and should this be:

array(n) = "that"


--


Gary


"Jim Thomlinson" wrote in message
...
Take a look for help on the redim statement (note the key work preserve is
required to not clear the values of the array when it is resized.)

dim myArray() as sting
dim n as long

n = 0
redim preserve myArray(n)
myarray(0) = "this"
n = 1
redim preserve myarray(n)
myarray(0) = "that"

--
HTH...

Jim Thomlinson


"Jimmy" wrote:

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Variables in Declaring an Array

i'm not as knowledgeable as you, i was just checking how it worked so i could
learn more about arrays. noticed how i "asked" instead of saying "this is how it
should be". i didn't know for sure. it should also probably be:
myarray(n) = "this"
right?

i know i don't type very well, so i understand the typo.

thanks
--


Gary


"Jim Thomlinson" wrote in message
...
My typing takes a little to be desired... I should really proof read before
hitting the Post button. You are correct on the String thing. As for the
Array(n) = "that"
it was just a quick n dirty demo. Yes n probably makes more sense...
--
HTH...

Jim Thomlinson


"Gary Keramidas" wrote:

2 things jim

you have a typo he
dim myArray() as sting (string)

and should this be:

array(n) = "that"


--


Gary


"Jim Thomlinson" wrote in message
...
Take a look for help on the redim statement (note the key work preserve is
required to not clear the values of the array when it is resized.)

dim myArray() as sting
dim n as long

n = 0
redim preserve myArray(n)
myarray(0) = "this"
n = 1
redim preserve myarray(n)
myarray(0) = "that"

--
HTH...

Jim Thomlinson


"Jimmy" wrote:

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Variables in Declaring an Array

Looks like you have the hang of ReDim to me... Like I said in my original
post the only trick is to understanding the use of the preserver key word.
Preserve adds some overhead however so my origninal code should have been...

dim myArray() as sting
dim n as long

n = 0
redim myArray(n) 'Note no Preserve as there is nothing to save
myarray(n) = "this"
n = 1
redim preserve myarray(n)
myarray(n) = "that"

Redim essentially makes a new array that is the size that you specify and
then points the array variable at the new array. The preserve key word tells
the compiler to copy over the values from the old array to the new array...
--
HTH...

Jim Thomlinson


"Gary Keramidas" wrote:

i'm not as knowledgeable as you, i was just checking how it worked so i could
learn more about arrays. noticed how i "asked" instead of saying "this is how it
should be". i didn't know for sure. it should also probably be:
myarray(n) = "this"
right?

i know i don't type very well, so i understand the typo.

thanks
--


Gary


"Jim Thomlinson" wrote in message
...
My typing takes a little to be desired... I should really proof read before
hitting the Post button. You are correct on the String thing. As for the
Array(n) = "that"
it was just a quick n dirty demo. Yes n probably makes more sense...
--
HTH...

Jim Thomlinson


"Gary Keramidas" wrote:

2 things jim

you have a typo he
dim myArray() as sting (string)

and should this be:

array(n) = "that"


--


Gary


"Jim Thomlinson" wrote in message
...
Take a look for help on the redim statement (note the key work preserve is
required to not clear the values of the array when it is resized.)

dim myArray() as sting
dim n as long

n = 0
redim preserve myArray(n)
myarray(0) = "this"
n = 1
redim preserve myarray(n)
myarray(0) = "that"

--
HTH...

Jim Thomlinson


"Jimmy" wrote:

Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Variables in Declaring an Array

you can't but you have 2 options.
You can declare const like const MAX_ITEMS AS INTEGER before declaring
variables (see example 1)
Another option is not using a fixed array but a variable size array
(see example 2)
Hope this helps.

example 1
CONST MAX_ITEMS AS INTEGER=10
Dim myArray(0 To MAX_ITEMS ) As String

Example 2
option base 1
dim n as integer
dim myArray() as string
n=15
redim myArray(1 to n)

Jimmy wrote:
Dim myArray(0 To n) As String

The dimensions of this array change throughout.

Why can't I use the variable 'n' in the declaration?

And, more importantly, can someone help me solve this problem?

Thanks,

Jimmy


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables freekrill Excel Discussion (Misc queries) 2 July 19th 06 06:36 AM
Declaring variables Mike Excel Programming 4 November 28th 05 07:05 PM
Declaring Variables matt_steer[_2_] Excel Programming 2 May 17th 04 09:53 PM
Declaring Variables Brad Excel Programming 3 May 12th 04 08:13 PM
Declaring Variables Robert[_16_] Excel Programming 2 November 20th 03 04:16 PM


All times are GMT +1. The time now is 10:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"