Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I select a font for a listbox. 2

Status
Not open for further replies.

JensKKK

Technical User
May 8, 2007
119
GB
I created a list box and I display a lsit of name (variable in length) and followed by some numeric expressions.

Ideally I would like to format the output. The routine below is rough draft.

I measure the length of the name using the Len(dummy) function.

However I am displaying my data in Arial -> and idealy I would like to change it to courier.

I am using a listbox from the Toolbars Forms menu.

Any ideas to solve the formating dilema are welcome.

Cheers

For i = 1 To j
dummy = Sheets("3d rotate").Cells(10999 + i, 1)
If Len(dummy) = 3 Then
spacer1 = " "
End If
If Len(dummy) = 4 Then
spacer1 = " "
End If
If Len(dummy) = 5 Then
spacer1 = " "
End If
If Len(dummy) = 6 Then
spacer1 = " "
End If
If Len(dummy) = 7 Then
spacer1 = " "
End If
If Len(dummy) = 8 Then
spacer1 = " "
End If
msg = MsgBox("dummy: " & dummy & " lange " & Len(dummy))
Sheets("3d rotate").Cells(999 + i, 1) = Sheets("3d rotate").Cells(10999 + i, 1) & spacer1 & Round(Sheets("3d rotate").Cells(10999 + i, 2), 0) & " %" & " CV: " & Round(Sheets("3d rotate").Cells(10999 + i, 4), 0) & " %"
Sheets("3d rotate").Cells(1999 + i, 1 + Selected_Drug) = Sheets("3d rotate").Cells(10999 + i, 3)
Next
 




Hi,

"I am using a listbox from the Toolbars Forms menu."

wysiwyg. (What you see is what you get)

If you use the Control Toolbox, you get more control, and you must program more stuff.

Skip,

[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue]
 

First, you can simplify your code:
Code:
    If Len(dummy) = 3 Then
        spacer1 = "           "
    End If
    If Len(dummy) = 4 Then
        spacer1 = "         "
    End If
    If Len(dummy) = 5 Then
        spacer1 = "        "
    End If
    If Len(dummy) = 6 Then
        spacer1 = "       "
    End If
    If Len(dummy) = 7 Then
        spacer1 = "       "
    End If
    If Len(dummy) = 8 Then
        spacer1 = "       "
    End If
with:
Code:
    Select Case Len(dummy)
        Case 3
            spacer1 = Space(11)
        Case 4
            spacer1 = Space(9)
        Case 5
            spacer1 = Space(8)
        Case 6 To 8
            spacer1 = Space(7)
    End Select

But, more important: Arial is a true font, so the letter 'W' takes more space than the letter 'i', so just counting the number of characters is not enough. Word 'Wwmmw' will take more space than the word 'Iilil' - both have 5 characters.

You may want to use a listbox with 2 columns in it.


Have fun.

---- Andy
 
Thanks Andrzejek,

any ideas how I can change the font from Arial to Courier for example?

How do I get a listbox with two columns?
 
Andrzejek,

I figured it out

I tried what Skip said and now I chose the font and I found out how to use more than one column.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top