PC Review


Reply
Thread Tools Rate Thread

Create and Update Multidimensional Array

 
 
=?Utf-8?B?VHJveUguUEhT?=
Guest
Posts: n/a
 
      11th Nov 2006
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
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      11th Nov 2006
Re: 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" <(E-Mail Removed)>
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.
 
Reply With Quote
 
wisccal@googlemail.com
Guest
Posts: n/a
 
      11th Nov 2006
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 With Quote
 
=?Utf-8?B?VHJveUguUEhT?=
Guest
Posts: n/a
 
      13th Nov 2006
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.



"(E-Mail Removed)" 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 With Quote
 
wisccal@googlemail.com
Guest
Posts: n/a
 
      16th Nov 2006
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.
>
>
>
> "(E-Mail Removed)" 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a multidimensional array of a certain type in runtime? Norbert Pürringer Microsoft C# .NET 1 13th Jun 2008 10:40 AM
share a structure array containing multidimensional char array C#/ Aykut Ergin Microsoft C# .NET 9 15th Apr 2008 07:40 AM
convert a jagged array into a multidimensional array TS Microsoft C# .NET 5 23rd Jan 2007 12:49 AM
Multidimensional Array Adrian T Microsoft Excel Programming 5 12th Aug 2004 08:12 PM
Creating an Array from a multidimensional array @ nospam.com Microsoft C# .NET 1 20th Aug 2003 12:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:04 PM.