I need to store a list box's source in code (or a hidden table? I don't
know.) The list grows. The user can add an item via form to the list.

I have a form and on the add click I want to add a 5 column entry to the
listbox

I know of the "additem" key word but how do I add the 5 items to one row

My items are like this: start (string), finish (string), difference
(integer), multiplier (double), total (double)
--
Chris Hayes
Still a beginner (only 12 years)

RE: How to store growiing list box values programatically by hayes

hayes
Mon Apr 16 19:54:00 CDT 2007

Ok, how about a growing array
I'm keeping the code to the form right now

I have a list box with 5 columns. 1) start (string), 2) finish (string), 3)
difference
(integer), 4) multiplier (double), 5) total (double)

These are all calculated in a Private sub on the on click event from the form.

If I declare a variable for the listbox row source [.List () =
strLstBoxSource] in the beginning of the code how do I set it up?

??? Dim strLstBoxSource (1 to ?, 1 to 5) as String ???

The source is empty to begin with but as the user adds rows via the form,
the Array grows.

1) How to set the original declaration?

2) When Where and How to ReDim and Preserve the new List for the listbox?

--
Chris Hayes
Still a beginner (only 12 years)


"CS Hayes" wrote:

> I need to store a list box's source in code (or a hidden table? I don't
> know.) The list grows. The user can add an item via form to the list.
>
> I have a form and on the add click I want to add a 5 column entry to the
> listbox
>
> I know of the "additem" key word but how do I add the 5 items to one row
>
> My items are like this: start (string), finish (string), difference
> (integer), multiplier (double), total (double)
> --
> Chris Hayes
> Still a beginner (only 12 years)

RE: How to store growiing list box values programatically by hayes

hayes
Tue Apr 17 14:44:02 CDT 2007

Boy, I am making progress but not there yet.

here's what I ended up with.

'I learned that I have to define a "dynamic" array

Dim varListBoxSource () as Variant

'Once I get to the place to define the boundaries and fill the variable
' I get this error <subscript out of range>

If IsNull(varListBoxSource) = True Then

'varListBoxSource will be Null if this is the first time

ReDim varListBoxSource(1 To 1, 1 To 5) As Variant
Else: ReDim Preserve varListBoxSource(UBound(varListBoxSource) + 1)

any suggestions?

--
Chris Hayes
Still a beginner (only 12 years)


"CS Hayes" wrote:

> Ok, how about a growing array
> I'm keeping the code to the form right now
>
> I have a list box with 5 columns. 1) start (string), 2) finish (string), 3)
> difference
> (integer), 4) multiplier (double), 5) total (double)
>
> These are all calculated in a Private sub on the on click event from the form.
>
> If I declare a variable for the listbox row source [.List () =
> strLstBoxSource] in the beginning of the code how do I set it up?
>
> ??? Dim strLstBoxSource (1 to ?, 1 to 5) as String ???
>
> The source is empty to begin with but as the user adds rows via the form,
> the Array grows.
>
> 1) How to set the original declaration?
>
> 2) When Where and How to ReDim and Preserve the new List for the listbox?
>
> --
> Chris Hayes
> Still a beginner (only 12 years)
>
>
> "CS Hayes" wrote:
>
> > I need to store a list box's source in code (or a hidden table? I don't
> > know.) The list grows. The user can add an item via form to the list.
> >
> > I have a form and on the add click I want to add a 5 column entry to the
> > listbox
> >
> > I know of the "additem" key word but how do I add the 5 items to one row
> >
> > My items are like this: start (string), finish (string), difference
> > (integer), multiplier (double), total (double)
> > --
> > Chris Hayes
> > Still a beginner (only 12 years)

Re: How to store growiing list box values programatically by Perry

Perry
Tue Apr 17 17:11:03 CDT 2007

Here are two examples filling a listbox
1) using the additem() method without arrays
2) using an array to pass to the Column property of a listbox
(both same result)

example 1
With Me.ListBox1
.AddItem "apples1"
.List(.ListCount - 1, 1) = "pears1"
.List(.ListCount - 1, 2) = "bananas1"

.AddItem "apples2"
.List(.ListCount - 1, 1) = "pears2"
.List(.ListCount - 1, 2) = "bananas2"

.AddItem "apples3"
.List(.ListCount - 1, 1) = "pears3"
.List(.ListCount - 1, 2) = "bananas3"
End With

example 2
Dim icnt As Integer
Dim arr()
For x = 1 To 3
ReDim Preserve arr(2, icnt)
arr(0, icnt) = "apples" & (icnt + 1)
arr(1, icnt) = "pears" & (icnt + 1)
arr(2, icnt) = "bananas" & (icnt + 1)
icnt = icnt + 1
Next
Me.ListBox1.Column = arr

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



"CS Hayes" <hayes.csmontypython@gmail.com> schreef in bericht
news:0125DE42-3EC1-45F0-B326-991C609F3AEE@microsoft.com...
>I need to store a list box's source in code (or a hidden table? I don't
> know.) The list grows. The user can add an item via form to the list.
>
> I have a form and on the add click I want to add a 5 column entry to the
> listbox
>
> I know of the "additem" key word but how do I add the 5 items to one row
>
> My items are like this: start (string), finish (string), difference
> (integer), multiplier (double), total (double)
> --
> Chris Hayes
> Still a beginner (only 12 years)


Re: How to store growiing list box values programatically by hayes

hayes
Tue Apr 17 20:32:02 CDT 2007

Perfect! The additem funtion of yours works perfect.

Thanks
--
Chris Hayes
Still a beginner (only 12 years)