question about creating array

  • Thread starter Thread starter wcc
  • Start date Start date
W

wcc

Hello group,

What's a better way to create an array like this?

Dim arrFieldInfo As Variant
arrFieldInfo = Array(Array(1, 2),Array(2, 2),Array(3, 2),Array(4,
2),Array(5, 2),Array(6, 2),Array(7, 2),Array(8, 2),Array(9,
2),Array(10, 2),Array(11, 2),Array(12, 2),Array(13, 2),Array(14,
2),Array(15, 2),Array(16, 2),Array(17, 2), Array(18,2),Array(19,
2),Array(20, 2),Array(21, 2),Array(22, 2), Array(23, 2), Array(24,
2),Array(25, 2),Array(26, 2),Array(27, 2),Array(28, 2),
Array(29, 2),Array(30, 2),Array(31, 2),Array(32, 2))

Thans for your help.

wcc
 
wcc said:
Hello group,

What's a better way to create an array like this?

Dim arrFieldInfo As Variant
arrFieldInfo = Array(Array(1, 2),Array(2, 2),Array(3, 2),Array(4,
2),Array(5, 2),Array(6, 2),Array(7, 2),Array(8, 2),Array(9,
2),Array(10, 2),Array(11, 2),Array(12, 2),Array(13, 2),Array(14,
2),Array(15, 2),Array(16, 2),Array(17, 2), Array(18,2),Array(19,
2),Array(20, 2),Array(21, 2),Array(22, 2), Array(23, 2), Array(24,
2),Array(25, 2),Array(26, 2),Array(27, 2),Array(28, 2),
Array(29, 2),Array(30, 2),Array(31, 2),Array(32, 2))

Thans for your help.

wcc

Hi wcc

Do you mean something like this?
After running the routine the array NewArray() holds the
values from arrFieldInfo.

Sub test45()
'Leo Heuser, 6 August 2006
Dim arrFieldInfo As Variant
Dim Counter As Long
Dim NewArray() As Variant

arrFieldInfo = Array(Array(1, 2), Array(2, 2), Array(3, 2), _
Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), _
Array(9, 2), Array(10, 2), Array(11, 2), Array(12, 2), Array(13, 2), _
Array(14, 2), Array(15, 2), Array(16, 2), Array(17, 2), Array(18, 2), _
Array(19, 2), Array(20, 2), Array(21, 2), Array(22, 2), Array(23, 2), _
Array(24, 2), Array(25, 2), Array(26, 2), Array(27, 2), Array(28, 2), _
Array(29, 2), Array(30, 2), Array(31, 2), Array(32, 2))

ReDim NewArray(LBound(arrFieldInfo) To UBound(arrFieldInfo), _
LBound(arrFieldInfo) To LBound(arrFieldInfo) + 1)

For Counter = LBound(NewArray, 1) To UBound(NewArray, 1)
NewArray(Counter, LBound(NewArray)) = _
arrFieldInfo(Counter)(LBound(arrFieldInfo))
NewArray(Counter, LBound(NewArray) + 1) = _
arrFieldInfo(Counter)(LBound(arrFieldInfo) + 1)
Next Counter


End Sub
 
You're trying to import a file (say comma delimited) and want each field to be
text?

Dim myArray() As Variant
Dim iCtr As Long
Dim maxFields As Long

maxFields = 256 '256 columns maximum

ReDim myArray(1 To maxFields, 1 To 2)
For iCtr = 1 To maxFields
myArray(iCtr, 1) = iCtr
myArray(iCtr, 2) = 2
Next iCtr

Workbooks.OpenText Filename:="C:\someworkbookname.xls", Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, _
Space:=False, Other:=False, FieldInfo:=myArray
 
Thanks a lot Dave. That is exactly what I'm trying to do. Also thanks
to Leo for helping.

A question on the argument "origin". What does 437 represent? From the
help file, I only see three values:
xlMacintosh 1
xlMSDOS 3
xlWindows 2

I'm using xlWindows. Just curious.

Regards,
wcc
 
I should have deleted it!

From xl2003's help:

Additionally, this could be an integer representing the code page number of the
desired code page. For example, "1256" would specify that the encoding of the
source text file is Arabic (Windows). If this argument is omitted, the method
uses the current setting of the File Origin option in the Text Import Wizard.

I use USA Windows setting--so I'm guessing that it's got something to do with
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top