Solved

Selected property and printing

Posted on 2004-10-08
10
180 Views
Last Modified: 2010-05-02
Hi:
    Can someone give examples of how to use the selected property to print multiple selection from a List box?
0
Comment
Question by:LearningJava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 7

Expert Comment

by:HoweverComma
ID: 12264547
Dim Inum as Integer
Inum=0

While Inum< ListBox.ItemCount-1      ' -1 because it is Zero based
If ListBox.Selected(Inum)=True Then
    'It is selected we need to print
    ' If it is not numeric data the use Str(ListBox.ItemData(Inum))
    Printer.Print ListBox.ItemData(Inum)
End If
Printer.EndDoc
Wend
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12264554
Private Sub Command1_Click()
Dim c As Integer
For c = 0 To List1.ListCount - 1
    If List1.Selected(c) = True Then
        Debug.Print List1.List(c)
    End If
Next c
End Sub

S
0
 
LVL 10

Expert Comment

by:anv
ID: 12265387
Set List1 MultiSelect to true in design mode..

and then do following

dim ar() as string

Private Sub Command1_Click()
      Redim ar(List1.ListCount-1)
      dim i!,j!
      j=0

      for i = 0 to list1.ListCount - 1
         if List1.Selected(i) = True then
           printer.print List1.List(i)
           ar(j) = List1.List(i)''for storing into an array for later use.
           j=j+1
         end if
      next

instead of storing it into an array u can store the list into a text file...

which u can print later after the loop..
reasn being..

above code will print each line into a separate page (i suppose)

to avoid that ..u can append the list to a file...which u can print later..


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:LearningJava
ID: 12266236
Where does ListCount come from? I don't see it in the ListBox properties?

Also, can someone explain to me what ItemData means?
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12266262
Are you with VB or VBA?
ListCount is a property for listbox in VB.  ItemData is another property that allows you to set a specific NUMBER to each item in the list, so later on you can identity this item using the ItemData, like if you have a job number, or employee number, or part number, so you can display the item's name and store in ItemData the corresponding number for later use.

S
0
 

Author Comment

by:LearningJava
ID: 12266406
I am using Visual basic 6.0.

Ithought that the Listbox entries could be accessed by index number??
0
 
LVL 19

Expert Comment

by:Shauli
ID: 12266429
Yes, they are.

Dim c As Integer
For c = 0 To List1.ListCount - 1    'listcount is the number of items in the list
    If List1.Selected(c) = True Then    'c is looping among the index numbers.
        Debug.Print List1.List(c)    'doing your stuff with a specific item in the list. In this case - a selected item
        'do your stuff here
    End If
Next c

S

0
 

Author Comment

by:LearningJava
ID: 12266598
What is the meaning of Debug.Print?

Why not Printer.Print List1.List(c)?

Also, could you elaborate on ListCount? I don't see it in the  properties for Listbox.

0
 
LVL 19

Expert Comment

by:Shauli
ID: 12266662
Debug.Print is a convenient way to see the result in the immediate window (the bottom window on the VB) to check that your code does what you really expect it to do. If you want to print to a printer then Printer.Print List1.List(c) is just fine.

S
0
 
LVL 19

Accepted Solution

by:
Shauli earned 500 total points
ID: 12266691
ListCount must be in the property list. Type List1. (dot) and a list of properties will open. Scroll down (it is sorted alphabetically) and you'l find it there.
ListCount returns the total of items in a listbox. Lets say your listbox list is:

John Doe
Jane Doe
GW Bush
JF Kerry

Then ListCount will return 4. However, as the first index number for the list in a listbox is 0, then when you loop among the index of the list, you loop from 0 to ListCount -1, which means from 0 to 3 (in this case, where you have 4 items in the list)

S
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 4 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question