Solved

Selected property and printing

Posted on 2004-10-08
10
176 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now