Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create and Update Multidimensional Array
This is my first attempt to create a multidimension array and I'm failing
miserably. Part A: I am trying to take data from text files and insert them into an array. I know how to open the files and get the data. This is what I know: The number of files are not consistent. The number of line items in each file is not consistent. I would like to create an array, and input the data from the text file into the array. Repeat for each file. ex: FILE1: Desc-1 item1 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create and Update Multidimensional Array
Part B...
http://support.microsoft.com/kb/213748/en-us "How to Populate One List Box Based on Another List Box" -- Jim Cone San Francisco, USA http://www.realezsites.com/bus/primitivesoftware "TroyH.PHS" wrote in message -snip- Part B: I have a userform with 2 listboxes side by side. The left listbox (listbox1) will contain the first item in each row of the array or column 1. (ex: Desc-1, Desc-2, Desc-3, etc.) The right listbox (listbox2) will contain the remaining items past the first column and is determined by which item is selected in listbox 1 (item1 ... itemXX) I don't really have any code as I keep erroring out with just trying to get it started. Can anyone help? Thanks. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create and Update Multidimensional Array
Part A:
Dim textArr(noOfFiles -1, maxNoOfItems) Dim i As Integer, j As Integer i = 0 j = 0 For i To noOfFiles textArr(noOfFiles, 0) = getDescr() 'first item of second dimension is always description For j To noOfItems textArr(noOfFiles, j +1) = getItem() Next j Next i Part B: You would populate the first ListBox with your textArr like so: Dim i As Integer For i = 0 To UBound(textArr, 1) lstBox1.add textArr(i, 0) Next i And in your second ListBox's change event, you want something like this: Dim indx As Integer indx = lstBox1.ListIndex If indx = 0 Then Dim i As Integer i = 1 while (i <= UBound(textArr, 2) And (textArr(indx, i) < "") lstBox2.add textArr(indx, i) i = i + 1 wend Else lstBox2.clear End If Regards, Steve |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create and Update Multidimensional Array
You need to get the upper bound of the second dimension, not the first:
For x = 0 To UBound(arrCAT_NAM, 2) Debug.Print "#: " & arrCAT_NAM(0, x) Debug.Print "Descr: " & arrCAT_NAM(1, x) Next x Regards, Steve TroyH.PHS schrieb: Thanks for the quick reply. I appreciate the help but I think I may have goofed in my initial design. But I do appreciate the info and it has helped clear some light on my mistake. Let me try again. I need to build an array as the info comes about. I do not have all the data at the beginning. I need help with using the REDIM statement and how to pull the data from a multi-dimension array. I now know that my inital idea for an array went: # Item Desc. 4 DESC1 5 DESC2 6 DESC3 7 DESC4 8 DESC5 9 DESC6 ... <--- New row added when data was found coded as: ReDim Preserve arrCAT_NAM(COUNT, 1) arrCAT_NAM(arrCOUNT, 0) = # arrCAT_NAM(arrCOUNT, 1) = DESC COUNT = COUNT + 1 I learned that I was wrong, it has to be: 4 5 6 7 8 9 DESC1 DESC2 DESC3 DESC4 DESC5 DESC6 coded as: ReDim Preserve arrCAT_NAM(1, COUNT) arrCAT_NAM(0, arrCOUNT) = # arrCAT_NAM(1, arrCOUNT) = DESC COUNT = COUNT + 1 So my questions is, how do I pull the data out. I tried... For x = 0 To UBound(arrCAT_NAM, 1) MsgBox arrCAT_NAM(x, 0) Next x but it does not work. Thanks. " wrote: Part A: Dim textArr(noOfFiles -1, maxNoOfItems) Dim i As Integer, j As Integer i = 0 j = 0 For i To noOfFiles textArr(noOfFiles, 0) = getDescr() 'first item of second dimension is always description For j To noOfItems textArr(noOfFiles, j +1) = getItem() Next j Next i Part B: You would populate the first ListBox with your textArr like so: Dim i As Integer For i = 0 To UBound(textArr, 1) lstBox1.add textArr(i, 0) Next i And in your second ListBox's change event, you want something like this: Dim indx As Integer indx = lstBox1.ListIndex If indx = 0 Then Dim i As Integer i = 1 while (i <= UBound(textArr, 2) And (textArr(indx, i) < "") lstBox2.add textArr(indx, i) i = i + 1 wend Else lstBox2.clear End If Regards, Steve |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Multidimensional array - lookup | Excel Programming | |||
Syntax for multidimensional array | Excel Programming | |||
Sort MultiDimensional Array | Excel Programming | |||
Multidimensional Array | Excel Programming | |||
MAX of Multidimensional Array | Excel Programming |