LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default ListBox and arrays

I have UserForm1 with TextBox1, TextBox2, TextBox3, ListBox1,
CommandButton1, and CommandButton2.

The user enters information in the 3 TextBoxes, then presses CommandButton1
to add that info to ListBox1. The code for CommandButton1 is:

Private Sub CommandButton1_Click()

x = lbRangeList.ListCount

'If Item2 is higher than Item3, display a message box
'and do not update ListBox1 to include the range. Otherwise, update the
list.

If Val(TextBox2.Value) < Val(TextBox2.Value) Then
ReDim Preserve Item1(x), Item2(x), Item3(x)
Item1(x) = TextBox1.Value
Item2(x) = TextBox2.Value
Item3(x) = TextBox3.Value
ListBox1.AddItem Item1(x)
ListBox1.List(ListBox1.ListCount - 1, 1) = Item2(x)
ListBox1.List(ListBox1.ListCount - 1, 2) = Item3(x)
x = x + 1 'Add 1 to x for the next item
End If
Else
a = MsgBox("Item1 cannot be higher than Item2. Please re-enter your
data.", vbCritical, "Invalid Entry")
End If
'Clear textboxes
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox"
Next ctrl
Item1.SetFocus
lbRangeList.ListIndex = -1

End Sub

I put these items in arrays (declared as public variables) for using the
arrays in other parts of my project. Here's my problem: I want to be able
to remove a line from ListBox1 by pressing CommandButton2. I can do this
easily enough, but my problem is in how to update the arrays I've created to
account for items I've removed from ListBox1. Currently, I have the
following code for ListBox2:

Sub CommandButton2_Click()

ListBox1.RemoveItem lbRangeList.ListIndex

End Sub

Which removes the items from ListBox1, but when I continue to run other
subroutines in the module, I get a subscript out of range error which I'm
assuming has to do with removing an item from ListBox1, but not updating the
arrays to account for this change.

Any help would be greatly appreciated.

--
Michael J. Malinsky
Pittsburgh, PA

"I am a bear of very little brain, and long
words bother me." -- AA Milne, Winnie the Pooh


 
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
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
Multicolumn Listbox and ordinary listbox Ron_D Excel Programming 0 June 4th 04 08:56 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 05:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"