Solved

Need Mult-functional Listbox

Posted on 2000-03-16
16
164 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
Comment Utility
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
Comment Utility
Well, you could use ListView or MSFlexGrid controls...  With MSFlexGrid, you can change the font of each cell...


Cheers!®©
0
 

Author Comment

by:VBStarter
Comment Utility
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
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Well good-luck...


Cheers!®©
0
 
LVL 27

Accepted Solution

by:
Ark earned 100 total points
Comment Utility
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 27

Expert Comment

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

Author Comment

by:VBStarter
Comment Utility
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 27

Expert Comment

by:Ark
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

12 Experts available now in Live!

Get 1:1 Help Now