Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Definition and use of multi-dimensional variables

I want to define and use multi-dimensional variables.

I can define variables of type variant (i.e. Dim field() as variant), and
then refine them by using: Redim field(1 to i); to build i variables (field(1)
, field(2) ... field(i)) in variant field.

What I want to do now is define the variables field(1), field(2) etc. to ...
field(i), such that each 'field(i)' variable contains ~4 sub-variables. i.e:

field - field(1) - (fldRange as Range
Name As String
Title As String
index As Integer, etc.

field(2) - fldRange as Range
Name As String
Title As String
index As Integer,

etc; to ..................

field(i) - fldRange as Range
Name As String
Title As String
index As Integer

Is this possible, and can anyone explain how I can do this?

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Definition and use of multi-dimensional variables

Try using a multi-dimensional array... a quick example would be:

Sub test()
Dim myarray(1 To 10, 1 To 3) As Variant
Dim i As Integer, x As Integer, j As Integer
For i = 1 To 10 Step 1
myarray(i, 1) = "My Name" & i
myarray(i, 2) = "My Title" & i
myarray(i, 3) = i
Next i
For x = 1 To 10 Step 1
For j = 1 To 3 Step 1
Debug.Print myarray(x, j)
Next j
Next x
End Sub

Try it out (make sure that the immediate window is visible)

HTH
Sandy

On Nov 20, 1:45 pm, "Arthur Negus via OfficeKB.com" <u5428@uwe wrote:
I want to define and use multi-dimensional variables.

I can define variables of type variant (i.e. Dim field() as variant), and
then refine them by using: Redim field(1 to i); to build i variables (field(1)
, field(2) ... field(i)) in variant field.

What I want to do now is define the variables field(1), field(2) etc. to ...
field(i), such that each 'field(i)' variable contains ~4 sub-variables. i.e:

field - field(1) - (fldRange as Range
Name As String
Title As String
index As Integer, etc.

field(2) - fldRange as Range
Name As String
Title As String
index As Integer,

etc; to ..................

field(i) - fldRange as Range
Name As String
Title As String
index As Integer

Is this possible, and can anyone explain how I can do this?

--
Message posted viahttp://www.officekb.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Definition and use of multi-dimensional variables

Hi there,

You can create your own Type variable, here is an example...



Option Explicit

Public Type Field
Range As Range
Name As String
Title As String
Index As Long
End Type

Sub TestMyType()

'Declare variables
Dim myField1 As Field, myField2 As Field, myField3 As Field, v

'Set first field variable
myField1.Index = 1
myField1.Name = "My First Variable Name"
myField1.Range = Range("A1")
myField1.Title = "VAR TITLE1"

'Set second field variable
myField2.Index = 2
myField2.Name = "My Second Variable Name"
myField2.Range = Range("A2")
myField2.Title = "VAR TITLE2"

'Set third field variable
myField3.Index = 3
myField3.Name = "My Third Variable Name"
myField3.Range = Range("A3")
myField3.Title = "VAR TITLE3"

End Sub



The other option could be to just make a two-dimensional array...


Dim arrField(1 to i, 1 to 4)


HTH

--
Regards,
Zack Barresse, aka firefytr



"Arthur Negus via OfficeKB.com" <u5428@uwe wrote in message
news:6994e3b85fb4c@uwe...
I want to define and use multi-dimensional variables.

I can define variables of type variant (i.e. Dim field() as variant), and
then refine them by using: Redim field(1 to i); to build i variables
(field(1)
, field(2) ... field(i)) in variant field.

What I want to do now is define the variables field(1), field(2) etc. to
...
field(i), such that each 'field(i)' variable contains ~4 sub-variables.
i.e:

field - field(1) - (fldRange as Range
Name As String
Title As String
index As Integer, etc.

field(2) - fldRange as Range
Name As String
Title As String
index As Integer,

etc; to ..................

field(i) - fldRange as Range
Name As String
Title As String
index As Integer

Is this possible, and can anyone explain how I can do this?

--
Message posted via http://www.officekb.com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Definition and use of multi-dimensional variables

Also, I'm not sure how high your field(i) is going to go but you might
want to look at Chip Pearson's website (link below) regarding Class
modules, it has a great introduction to them and has an
example/walk-through of what I think you are trying to accomplish (it
also gives a brief description of Type Variables that ZB posted about),
if nothing else, it's a great link for lot of excel/vba tricks and
tutorials...and advancing your knowledge of VBA!

http://www.cpearson.com/excel/ClassModules.htm
or
http://www.cpearson.com/excel.htm
if you're not interested in Class Modules


Sandy

Arthur Negus via OfficeKB.com wrote:
I want to define and use multi-dimensional variables.

I can define variables of type variant (i.e. Dim field() as variant), and
then refine them by using: Redim field(1 to i); to build i variables (field(1)
, field(2) ... field(i)) in variant field.

What I want to do now is define the variables field(1), field(2) etc. to ...
field(i), such that each 'field(i)' variable contains ~4 sub-variables. i.e:

field - field(1) - (fldRange as Range
Name As String
Title As String
index As Integer, etc.

field(2) - fldRange as Range
Name As String
Title As String
index As Integer,

etc; to ..................

field(i) - fldRange as Range
Name As String
Title As String
index As Integer

Is this possible, and can anyone explain how I can do this?

--
Message posted via http://www.officekb.com


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
Multi Dimensional Lookup coolkat Excel Discussion (Misc queries) 1 June 14th 11 11:48 PM
Multi Dimensional Array steve Excel Programming 4 September 26th 06 07:33 PM
Multi Dimensional Array andym Excel Programming 11 July 10th 06 05:09 AM
Multi-dimensional arrays gti_jobert[_5_] Excel Programming 6 February 6th 06 04:45 AM
Multi-Dimensional Array Let & Get Trip[_3_] Excel Programming 0 September 21st 05 08:41 PM


All times are GMT +1. The time now is 02:24 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"