Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Can't get a value out of a list box

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't get a value out of a list box

The usual way to do what you want is to use a spin button and a textbox.
Place the spinbutton next to the textbox.

Private Sub SpinButton1_Change
Textbox1.Value = SpinButton1.Value
End Sub

Set the spinbutton properties with a min of 0 and a max of 25

Then just read the value of the textbox.

--
Regards,
Tom Ogilvy


"JonR" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Can't get a value out of a list box

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
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

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
Comparing List A to List B and add what's missing from List B Gilbert Excel Discussion (Misc queries) 2 July 20th 09 11:18 PM
create new list from list A, but with exclusions from a list B Harold Good Excel Worksheet Functions 3 April 11th 08 11:23 PM
validation list--list depends on the selection of first list Michael New Users to Excel 2 April 27th 06 10:23 PM
list 1 has 400 names List 2 has 4000. find manes from list 1 on 2 Ed Excel Worksheet Functions 5 September 12th 05 09:48 AM
find names on list 1 in list 2. list 1 4000 names list 2 400 name Ed Excel Worksheet Functions 1 September 4th 05 12:48 AM


All times are GMT +1. The time now is 07:17 PM.

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"