Code to determine number of vbTabs to use

  • Thread starter Thread starter SStory
  • Start date Start date
S

SStory

Can anyone tell me what algorithm I should use to determine how many tabs to
add to a string.

I have two strings.

I want to add them to a listbox concatenated but with a tab between them.

one tab makes them not line up as string A and B are variable length.

String A is the shortest of the 2 and the Key.

What can I do to determine how many vbTabs to put in between the strings so
they will line up?

thanks

shane
 
* "SStory said:
Can anyone tell me what algorithm I should use to determine how many tabs to
add to a string.

I have two strings.

I want to add them to a listbox concatenated but with a tab between them.

one tab makes them not line up as string A and B are variable length.

String A is the shortest of the 2 and the Key.

What can I do to determine how many vbTabs to put in between the strings so
they will line up?

Why not use a ListView control in details view instead?

- or -

Use PInvoke on 'SendMessage' + 'LB_SETTABSTOPS'. A VB6 sample can be
found here:

<http://www.mvps.org/vbnet/index.html?code/listapi/listrightalign.htm>
 
Herfried,
Use PInvoke on 'SendMessage' + 'LB_SETTABSTOPS'. A VB6 sample can be
found here:
You know, I always thought it odd that the ListBox has a UseTabStops
property, but has no method of setting what the TabStops should be...

If you include the following in the Load event for your form, you will see
that the tabstops default to about "8" or so. Which depending on the OP's
strings lengths may be sufficent to work with.

For x As Integer = 1 To 19
ListBox1.Items.Add((New String("x"c, x) & ControlChars.Tab &
x.ToString()))
Next x
' Make the ListBox display tabs within each item.
ListBox1.UseTabStops = True

Just a thought
Jay
 
well, Herfried,

I took a data form that was an MS example that has a listbox for lookup and
nav buttons and build a nice inheritable baseform that requires little code
and allows you to override a lot of things and uses a listbox.

In this case I wanted list items to have tabs. So having to make a listview
in this case defeated the purpose, although maybe I need to make another
version that uses a listview instead.... Interesting idea.

I haven't used PInvoke yet.

What object has PInvoke for me to use to call? I assume pinvoke is used to
make a winapi call or something...unmanaged code. I was trying to come up
with some algorithm that would figure so many charachters gets a tab and
more chars less tabs and assumed 8 chars per tab but haven't gotten it to
working yet.

Thanks,

Shane
 
Hi Jay B,

Just a little thing I use in my examples (and only there)
dim x as integer
for x = 1 to 19

I do that because in 2002 this not posible and there are a lot with the
standard edition visiting this newsgroup.
For x As Integer = 1 To 19

(was there a reason why you did start with one?)

But maybe you have other idea's about it, it is more work so maybe I should
change that?

:-)
Cor
 
Cor,
(was there a reason why you did start with one?)
I started with 1, as that is what the sample in MSDN started with, look up
ListBox.UseTabStops for the original sample.

You are correct, keeping the sample at a 2002 level is beneficial for those
who choose not to upgrade.

However I prefer to show current & label as such (I forgot the label).
Showing current may help motivate those people to move to current... Also
the variable is only used in the For loop, so I prefer to scope it in the
For loop.

Just a thought
Jay
 
* "SStory said:
I took a data form that was an MS example that has a listbox for lookup and
nav buttons and build a nice inheritable baseform that requires little code
and allows you to override a lot of things and uses a listbox.

In this case I wanted list items to have tabs. So having to make a listview
in this case defeated the purpose, although maybe I need to make another
version that uses a listview instead.... Interesting idea.

I haven't used PInvoke yet.

What object has PInvoke for me to use to call? I assume pinvoke is used to
make a winapi call or something...unmanaged code. I was trying to come up
with some algorithm that would figure so many charachters gets a tab and
more chars less tabs and assumed 8 chars per tab but haven't gotten it to
working yet.

There is no managed way to set the tabstops (untested):

\\\
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByRef aint() As Integer _
) As Int32

Private Const LB_SETTABSTOPS As Int32 = &H192
..
..
..
Dim aintTabs() As Integer = {0, 120}
SendMessage(MyListbox.Handle, LB_SETTABSTOPS, 2, aintTabs(0))
///
 
Back
Top