position of variables in a list

Hi,

I've a small problem.
I'm making a very simple cashregister program.  It this program, I use a list to add items.
Each item in that list have to contain 3 variables.
For example:

3   Cola                                  4,5
5   Fanta                                 6,5

'and so on

NOW HERE IS THE PROBLEM:
As in the example the '3' is stored in a variable1, the 'cola' in variable2 and the '4,5' in variable3.

Now I do the following:

List1.AddItem variable1 & vbTab & variable2 & vbTab & vbTab & vbTab & vbTab & vbTab & variable3

The problem is, when the characters or numbers stored in some of these variables ar longer I get this:


3   Cola                                  4,5
5   Fanta                                 6,5
3   The best beer                                9,5
5   Fristi                                8,0

As you can see in the 3th line, the 9,5 sticks out.  Does anyone have the solution to this problem.
(keep in mind, it's a very easy program so I dont want to use (or connect to) a database)
For example: Is it possible to declare each position of each variable, starting from the left edge of the list??)

Thanks in advance,

Vincent
vincentregentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SweatCommented:
vincentregent,

Easy "problem" to fix.

To properly align the three variables, you need to insure that all of the rows added to the listbox are of the same length.  So when you are dealing with the "3" or Variable1, then if you have more than ten rows and a value of two characters, then the "3" must be "3 ".

The same is true for the other two variables.  You'll need to pick a length, say 20 characters and insure that each variable2 is the same length.

Consider the following method:

    Variable1 = "Cola"
    Variable1 = Variable1 & Space$(20 - Len(Variable1))
    would become: "Cola                "

    or

    Variable1 = "The best beer"
    Variable1 = Variable1 & Space$(20 - Len(Variable1))
    would become: "The best beer       "

Then when you build the Additem line, each line will be of the same length and therefore lined up.

Let me know if this isn't clear.

Sweat


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vincentregentAuthor Commented:
Thanks a lot Sweat !!!!!!



Greetings,
Vincent
0
DocMCommented:

If you need to stay with the Tab as a separator, you could use a function like this:

Private Sub Command1_Click()
List1.Clear

a = 3: b = "The best beer": c = "9,5"
List1.AddItem CheckWidth(a, "1234") & CheckWidth(b, "1234567890") & c

a = 3: b = "Cola": c = "4.5"
List1.AddItem CheckWidth(a, "1234") & CheckWidth(b, "1234567890") & c

a = 5: b = "Fanta": c = "6, 5"
List1.AddItem CheckWidth(a, "1234") & CheckWidth(b, "1234567890") & c

 
End Sub
Function CheckWidth(strT, strMaxWidth) As String
 'We put at least one vbTab
 strMaxWidth = strMaxWidth & vbTab
 
 Me.Font = List1.Font
 Me.FontSize = List1.FontSize
 
 If TextWidth(strT & vbTab) > TextWidth(strMaxWidth) Then
  MsgBox "Text too long :" & strT
 
 Else
 
separator = ""
Do While TextWidth(strT & separator) < TextWidth(strMaxWidth)
 separator = separator & vbTab
Loop
 
 Do While TextWidth(strT & separator) < TextWidth(strMaxWidth)
 If separator = "" Then Exit Do
 separator = Mid(separator, 2)
Loop
 
End If

CheckWidth = strT & separator
 
End Function
0
vincentregentAuthor Commented:
Thanx for your help DocM.

Vincent
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.