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
Solved

Need Mult-functional Listbox

Posted on 2000-03-16
16
172 Views
Last Modified: 2010-05-02
I am trying to write a cash register
program with scrolling tape.  I would like to be able to have notes as well as figures.  The problem is I need the listbox to be able to vary the "column" widths per entry. Here is an example:

Bread      1.29
Frozen Piz 2.29
Frozen Peas .89
The decimal will line up of course

I would also like to be able to change the fonts for each "column".  I was thinking of using listboxes beheind the scenes and then print to a picture box.
The best idea or actual answer gets the points.  Thanks
0
Comment
Question by:VBStarter
  • 5
  • 5
  • 3
  • +2
16 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2624750
The listview control which is part of Microsoft's common controls allows you to have multiple columns easily (like in explorer).

It has multiple view styles but if you set it to be of report style you can add columns (for a cash register I guess you wouldnt want the column headers to be visible so you can set the hidecolumnheaders property to true).

if you add two column headers "Item" and "Cost", then set the alignment for the cost column to be rightaligned. Then you do the following to add an item to the top of the list :

Dim ltmNewItem as listitem

set ltmNewItem = listview1.listitems.add 0, "Bread"
    ltmnewitem.subitems(1) = "1.29"

do a similar routine for each item (the first param 0 would add it to the top of the list).
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2624760
Well, you could use ListView or MSFlexGrid controls...  With MSFlexGrid, you can change the font of each cell...


Cheers!®©
0
 

Author Comment

by:VBStarter
ID: 2625212
Thanks for the quick responses. The listview and the grid control would work for normal entries, but I need the column width to be adjustable.
Example:
Frozen Piz .89
Frozen Pi 1.89

A listview and/or Grid control have set column widths between rows.
Example:
Frozen Pi  .89
Frozen Pi 1.89

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 14

Expert Comment

by:mcrider
ID: 2625300
I don't get it... Why would you want variable lengths of a column per row????

With a flexgrid, you just set the column width to be the width of the longest item and you're done...


Cheers!®©
0
 

Author Comment

by:VBStarter
ID: 2625481
I want the user to see as much of the description as possible. I am limited in width on the tape. I want adjustable
cells to maximize the white space on the tape.

Example:

Tire Patc 1.89
Bicycle 119.99
14 spaces

Tire Patch Kit   1.89
Bicycle        119.99
22 spaces

I also want to be able to change font size.  I would lose more space if I have to make the column a set width for this feature.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2625545
To autosize a Listview Column..


<----- Code Begin ----->

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) _
    As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)
Private Const LVS_CW_AUTOSIZE = -1
Private Const LVS_CW_AUTOSIZE_USEHEADER = -2

Public Sub xlvwAutoSize _
(ByRef lvwHwnd As Long, _
ByRef ColumnIndex As Long)
    SendMessageLong _
        lvwHwnd, _
        LVM_SETCOLUMNWIDTH, _
        lvwIndex, _
        LVS_CW_AUTOSIZE
End Sub

<----- Code End ----->

If You want to include the header in the width test, change LVS_CW_AUTOSIZE to LVS_CW_AUTOSIZE_USEHEADER.



0
 
LVL 14

Expert Comment

by:mcrider
ID: 2625582
Well, Why not just print directly on the register tape... Assuming that it is dotmatrix... See the following microsoft KB article:

HOWTO: Print Line-by-Line to a Printer
http://support.microsoft.com/support/kb/articles/Q175/0/83.ASP?LNG=ENG&SA=MSDN&FR=0 


Cheers!®©
0
 

Author Comment

by:VBStarter
ID: 2625707
I still think I am not explaining myself very well, sorry.  Here is what I want to do.

This is exactly how the tape will look
Example:
NOTE:~ = space
Bicycle~119.99
Bicycle~T~9.99
Air fo~9999.99
[------------] 14 Spaces

Bicycle~~~~~~~~119.99
Bicycle Tire~~~~~9.99
Air for Tire~~9999.99
[-------------------] 21 spaces

The second way uses to many spaces

Also the value and description can be changed by the user.  

Example
BMX Bic~119.99 - Changed description
Bicycle~T~9.99
Air for~Ti~.99 - Changed value
[------------] 14 Spaces

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2625778
VBStarter.. load your data into a Listview.. after each update.. execute the Autosize Function provided above on your pertinent columns.. and the Listview columns will automatically adjust to the widest cell entry.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2625790
Well, here's a function that will format the line like you show above... It doesn't do anything with the font.

    Function FmtLine(Description As String, Price As Variant, LineLength As Integer) As String
        Dim lBuf As String
        Dim pString As String
        pString = " " + Format(CCur(Price), "0.00")
       
        lBuf = Left$(Description + Space(LineLength), _
            LineLength - Len(pString)) + pString
        FmtLine = lBuf
    End Function


Call it like this:

   x = FmtLine("Bicycle", 119.99, 14)
   debug.print x
   x = FmtLine("Bicycle T", 9.99, 14)
   debug.print x
   x = FmtLine("Air fo", 9999.99, 14)
   debug.print x


To get it to show up right, you need to use a font like "Courier New"...


Cheers!®©
0
 

Author Comment

by:VBStarter
ID: 2628369
Let's start over. First, thanks for all the post and second I still do not think I am explaining myself that well.

I will try again:

The tape has 25 characters and I want to be able to put a description and an
amount on each line.  
1. The description can be up to 25 characters and left justified.
2. The number can be up to 25 characters with the number having priority and is right justified.
3. Both description and number can be modified after they are on the tape with the above rules applying.
4. The description can be in a different font than the number.
5. The entire description will be saved even if overtyped.

Example:
Line 1
Description: This is description 1
Number: 9,9999.00
Displays:
This is descript 9,999.00

Line 2
Description: This is description 2
Number: 99.00
Displays:
This is description 99.00

Tape:
This is descript 9,999.00
This is description 99.00

This does not have to be one control, it would be nice but not necessary.  My first thought was 2 listboxes in the background printing to a picture box.

Thanks agin for your thoughts in this manor.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2628594
Well good-luck...


Cheers!®©
0
 
LVL 28

Accepted Solution

by:
Ark earned 100 total points
ID: 2632887
Hi
You can use two arrays of labels:
lblNumber() with right alignment and autosize=true and lblDescription() with left alignment, Autosize=False, wordwrap=False. With every new item simply
LeftEdge = 1000 ' for example
RigthEdge = 3000 ' for example

Load lblNumber(lastitem+1)
lblNumber(lastitem+1).Caption = NewNumber
lblNumber(lastitem+1).Left=RightEdge - lblNumber(lastitem+1).Width
lblNumber(lastitem+1).Top=lblNumber(lastitem).Top + lblNumber(lastitem+1).Height
lblNumber(lastitem+1).Visible=True

Load lblDescription(lastitem+1)
lblDescription(lastitem+1).left = LeftEdge
lblDescription(lastitem+1).width = RightEdge - RightEdge - lblNumber(lastitem+1).Width
lblDescription(lastitem+1).Top = lblNumber(lastitem+1).Top
lblDescription(lastitem+1).visible=True

You can change Font properties etc for lables as you want. Yo can assign Labels to scrollbar or use picturebox as container to scroll these labels
Cheers
0
 
LVL 28

Expert Comment

by:Ark
ID: 2632889
Hi
Sorry, this string should be
lblDescription(lastitem+1).width = RightEdge - LeftEdge - lblNumber(lastitem+1).Width
0
 

Author Comment

by:VBStarter
ID: 2637856
Thanks Ark.
Quick question. Is there a way to vertically align a label. When I change fonts on the labels it looks like the text shrinks to the upper right/left corner.  Thanks again.
0
 
LVL 28

Expert Comment

by:Ark
ID: 2638065
Hi
If you use borderless labels, you can try this:
Load lblDescription(lastitem+1)
lblDescription(lastitem+1).Autosize = True
lblDescription(lastitem+1).left = LeftEdge
lblDescription(lastitem+1).width = RightEdge - RightEdge - lblNumber(lastitem+1).Width
'Here you can play with Top and Height properties. For Example
If lblDescription(lastitem+1).Height < lblNumber(lastitem+1).Height Then
   lblDescription(lastitem+1).Top = lblNumber(lastitem+1).Top + (lblNumber(lastitem+1).Height - lblDescription(lastitem+1).Height) 'or you can divide value in brackets by 2
Else
   lblDescription(lastitem+1).Height = lblNumber(lastitem+1).Height
   lblDescription(lastitem+1).Top = lblNumber(lastitem+1).Top
End If
lblDescription(lastitem+1).visible=True
Cheers
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

856 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