Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB6 and vbTab

Posted on 2003-10-28
9
Medium Priority
?
4,555 Views
Last Modified: 2009-07-29
I am using a listbox to display a number of items separated by vbTab. The first vbTab seems to jump approx 20 spaces where subsequent ones jump approx 5 spaces.
How can I change the first vbTab to be 5 spaces also ?
Anyone any ideas ?
0
Comment
Question by:JimScott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 8

Expert Comment

by:ampapa
ID: 9632889
Have you tried Tab(#)?
0
 
LVL 1

Expert Comment

by:mahesh_mp
ID: 9632893
hello jimscott
 you use space your problem will be solved


List1.AddItem Space(5) & "sss" & Space(5) & "cc" & Space(5) & "cc" & Space(5) & "cc" & Space(5) & "cc"
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9633365
The tab character goes from one tabstop to the next tabstop.   Tabstops are set up as 8 spaces, if the first word is 8 characters, then the tab will move the next item to offset 16.  

If the first word on row 2 is 3 characters then tab will move the next item to offset 8.  Tab doesn't put a fixed amount of space between each item, it moves to the next tabstop.  You could use your own formatting like mahesh suggests with spaces instead of tabs.  Another option is to use the ListView instead of the listbox.  It is designed for multiple columns and you can add items to each column as opposed to trying to format them.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Accepted Solution

by:
daffyduck14mil earned 200 total points
ID: 9633711
Hi,

Both Mahesh_mp and SRigney are correct, tabs are very poor at getting a list very straight. However, you can manipulate the distance of the tabstops themselfs with the SendMessage API.

There is a message specific for Listbox controls, it is named LB_SETTABSTOPS. This is used to specify tab stops in a listbox control. Tab stops are specified in dialog base units, which represent one-forth of the average character width.

For our example, I have chosen to use four tabs to demonstrate things. The code below will set tab stops at specified intervals.

Private Declare Function winSendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Private Const LB_SETTABSTOPS = &H192

Private Sub Form_Load()
  Dim aTabs(3) As Long
  Dim lReturn As Long
  Dim lCounter As Long
 
  aTabs(0) = 20
  aTabs(1) = 40
  aTabs(2) = 60
  aTabs(3) = 80
 
  lReturn = winSendMessageLong(List1.hwnd, LB_SETTABSTOPS, 4, aTabs(0))
 
  For lCounter = 0 To 9
    List1.AddItem "Text that is long" & vbTab & "with some more" & vbTab & "Tabs!" & vbTab & "!" & vbTab & "!"
  Next
End Sub

In this example, the first tabstop is set at about 5 characters (20 divided by 4), the second at about 10 characters and so on. So, you can set the first tabstop to a reasonable large size, so it will look better.

Grtz.©

D.
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 10163528
Hi,
From the looks of it, a typical hit and run action.
D.
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 10623075
Dan,

How can I object to your suggestion... ;-)

Grtz.©

D.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

688 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