Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default using variables in listbox

Try
Public Chosen() as string



John wrote:

I tried the public declaration in the general form
It won't let me do the redim... says it's already declared
My variable is Chosen(100). Public Chosen(100) as String

After unloading the userform the array data is still gone. Before
unloading the data is in there.

What is the command to hide the form? If nothing else works.

John

Dave Peterson wrote:
You could hide the userform instead of unloading it.

Or you could declare your array (is that what you're using?) in a General module
and make it public:

In a general module:
Public myArr() as string

In the Ok button of the userform (or where you want it):

Private Sub CommandButton1_Click()
Dim L As Long
Dim iCtr as long

redim myArr(0 to me.listbox1.listcount - 1)

ictr = -1

For L = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(L) = True Then
ictr = ictr + 1
myarr(ictr) = Me.ListBox1.List(L)
End If
Next L

if ictr = -1 then
'nothing selected, what should happen here?
'stop the process and warn the user???
else
redim preserve myArr(0 to iCtr)
end if

unload me

End Sub

When the userform is unloaded, then the array will still exist.

John wrote:
Here's my problem. The program runs until "UserForm1.Show" which opens
the listbox and everything works great. I run code similar to what you
offered below and have my data in an array.

But now what? I want to close the listbox and use the data to do other
things. If I do "Unload UserForm1" all the variables are wiped out.

I have a command button "OK" on the userform but the manual I used
(Excel VBA Programming for Dummies) didn't say what to use for it. The
only thing I know is "unload userform1."

Thanks

Harald Staff wrote:
Hi John

Sure. Question is, pass them from the listbox and to what ?

General way to scan the listbox for selections:

Private Sub CommandButton1_Click()
Dim L As Long
For L = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(L) = True Then
MsgBox Me.ListBox1.List(L)
End If
Next
End Sub

HTH. Best wishes Harald


"John" wrote in message
...
My first attempts at using listboxes.

have listbox in a user form with multiple selections.

Is there a way to pass the selections out of the listbox? Right now
when I close the listbox all the variables holding the selections
disappear too.

Or to do more with the selections do I just hide the listbox?

Thanks

JOhn



--

Dave Peterson
Reply
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
Storing variables in a macro and using those variables to performcalculations. [email protected] Excel Programming 3 December 10th 07 04:13 PM
XL 2003: ListBox ListCount (and other) properties missing from Local Variables window Michel S. Excel Programming 3 February 14th 07 07:35 PM
Fill a Listbox with mult. Variables in userform Jennifer Excel Programming 2 May 23rd 06 07:28 PM
listbox and variables Anson[_2_] Excel Programming 0 June 23rd 04 06:24 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM


All times are GMT +1. The time now is 02:58 PM.

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

About Us

"It's about Microsoft Excel"