Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Comparing List A to List B and add what's missing from List B | Excel Discussion (Misc queries) | |||
create new list from list A, but with exclusions from a list B | Excel Worksheet Functions | |||
validation list--list depends on the selection of first list | New Users to Excel | |||
list 1 has 400 names List 2 has 4000. find manes from list 1 on 2 | Excel Worksheet Functions | |||
find names on list 1 in list 2. list 1 4000 names list 2 400 name | Excel Worksheet Functions |