Link to home
Start Free TrialLog in
Avatar of VBStarter
VBStarter

asked on

Need Mult-functional Listbox

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
Avatar of paulstamp
paulstamp

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).
Well, you could use ListView or MSFlexGrid controls...  With MSFlexGrid, you can change the font of each cell...


Cheers!®©
Avatar of VBStarter

ASKER

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

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!®©
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.
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.



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!®©
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

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.
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!®©
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.
Well good-luck...


Cheers!®©
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi
Sorry, this string should be
lblDescription(lastitem+1).width = RightEdge - LeftEdge - lblNumber(lastitem+1).Width
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.
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