View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JonR JonR is offline
external usenet poster
 
Posts: 82
Default Can't get a value out of a list box

Hi Sebastien

Tom Ogilvy answered my question with the SpinButon control, just like you
suggested. Thanks for the help.

Jon

"sebastienm" wrote:

JonR,
Have you tried :
Form1.Listbox1.ListIndex=0
once all your items are added. It will select the first item.

Or maybe there is something i don't understand when you say : "the number is
automatically selected as you scroll through.".

In the Print dialog, it is not a list box that is used, but a SpinButton
(from the Control Toolbox toolbar, with its Orientation property set to
frmOrientationVertical) which is linked to textbox (displying the Spinbutton
value). Look at the Spinbutton control online help, they have an example.
I'll get back in a minute with it.

Regards,
Seb


"JonR" wrote:

Sebastien,
Thanks for the quick reply. I'm getting there, but not quite.

I can now extract the value from the list box, but I have to actively select
(click on) the value in the window. I want the value to be automatically
selected as you scroll through the list.

I'm trying to duplicate the "Number of Copies" function in the print dialog
box that is pretty standard for Windows. If you notice when you increase the
number of copies desired, the number is automatically selected as you scroll
through.

I can't use the print dialog box, since the entire collection of subs that
I'm writing allows the user to select and print only certain graphs from an
entire collection. I can't use the regular print dialog because there is no
way to pass the selected sheets to the dialog.

Thanks

Jon

"sebastienm" wrote:

Hi Jon,
I suppose it is because after the items are added, the listbox has no item
selected. So Value returns Null.
After adding the items you could set the first item as selected by default:
...
Form1.ListBox1.AddItem (num)
Next
Form1.Listbox1.ListIndex=0 'select the 1st item

Also, the reurned value of a listbox is (i believe) a String, therefore,
maybe you should explicitely convert it (depends where the problem comes from)
nCopies = cint(Form1.ListBox1.Value)

I hope this helps,
Sébastien

"JonR" wrote:

Hi
I have a userform that allows users to select and print various objects. I
am trying to incorporate a listbox that allows the user to select the number
of copies desired.

I can populate the listbox fairly easily, but when I try to run the print
program (or even a test MsgBox) I get an error stating that the value of the
variable nCopies is null.

How do I set this up so that the variable nCopies gets its value from the
list box?

Example code is below; the real deal jumps around a bit between several
different subs.


sub load ()
' populates the list box
Dim num As Integer
For num = 1 To 25
Form1.ListBox1.AddItem (num)
Next

end sub

sub printcopy ()
Dim nCopies as Integer
nCopies = Form1.ListBox1.Value
for i= 1 to nCopies
ActiveSheet.PrintOut
next
end sub