PDA

View Full Version : [SOLVED] Solved: How to Use VBTAB



Cyberdude
05-20-2007, 02:31 PM
Once in awhile I use VBTAB to help me align text that I display with Msgbox. The trouble is that I really have no idea how to control the amount of tab space that occurs. Usually the default I get is satisfactory, but today I wanted a smaller value that the text is shifted and I couldn?t figure out a way to specify the tab value. How is that done?

johnske
05-20-2007, 05:18 PM
Here's a simple way... Public Const vbTab As String = " " '< Put your spaces here

Bob Phillips
05-21-2007, 01:24 AM
What a terrible idea, resetting a system constant!

Dude, my experience is that this is all down to trial and error, and it varies on different machines.

johnske
05-21-2007, 02:38 AM
What a terrible idea, resetting a system constant! ...As you say, it's an (inbuilt) system constant and hence you cannot possibly 'reset' it, you are intercepting its use by the system by replacing it with a user-defined constant with the same name - which you could just as easily replace with vbTab4, vbTab6, etc :) But really I can't see why you can't use MsgBox "my message part1" & " " & "my message part2" :dunno

Bob Phillips
05-21-2007, 04:01 AM
Because someone else comes along later and amends the code, and vbTab doesn't do what it is supposed to do, and they waste hours trying to track down the 'bug'.

malik641
05-21-2007, 06:34 AM
My feelings are the same as Bob's. What happens when you actually want to use the actual vbTab?

I would suggest just creating your own constant for each different application..something like sTab.

mdmackillop
05-21-2007, 10:42 AM
Using a string defeats the purpose of VBTab
eg
MsgBox "Note:" & vbTab & "Data1" & vbCr & vbTab & "Data2" & vbCr _
& vbTab & "Data3" & vbCr

Cyberdude
05-21-2007, 04:49 PM
Interesting comments. The use of a string of blanks is useful in some places, but is unpredictable in others. Believe me I've tried using blanks. What's nice about vTab is that it forces alignment in places where blanks are either thrown away (all but one) or the blanks seem to have unpredictable widths.

I shall assume from your comments that there isn't a way to control what vTab does.

Thanks for the comments, gang!
Sid :hi:

RtbComp
06-28-2020, 02:41 PM
People confuse tabs and spaces, a tab takes you to a fixed character position, not pad the data out with spaces.

123 tab5 456 gives 123..456
12 tab5 456 gives 12...456

and so on, calling a tab 5 spaces would give

123 tab5 456 would give 123.....456
12 tab5 456 gives 12.....456


Use LSET, RSET and SPACE$(N) with a fixed width font.



a$="12": b$="235": c$ = "Bolt"

S$ = Space$(5): RSet S$ = a$: a$ = S$
S$ = Space$(7): RSet S$ = b$: b$ = S$ + Space$(2)
S$ = Space$(10): LSet S$ = c$: c$ = S$

MsgBox a$+b$+c$+vbCrLf 'for each row gives a nicely aligned table

...12....235..Bolt




a$ is right justified into 5 spaces, b$ is right justified into 7 spaces and c$ is left justified into 10 spaces. The extra 2 spaces added to b$ separate the right and left justified columns by 2 spaces

SamT
06-28-2020, 05:01 PM
@Bob,


Sub
Dim sysTab as String
sysTab = vbTab
vbTab = " "

blah
blah
blah

vbTab = sysTab
End Sub

Paul_Hossler
06-28-2020, 06:02 PM
@RtbComp -- all true, but that was a 13 year old post, so I doubt if it's an issue any more :thumb

BTW - I tried to get the SysOps / Admins to automatically lock posts that had been idle for two years to prevent necro-posting, but for some reasons they couldn't

RtbComp
06-29-2020, 12:18 AM
Maybe not an issue for the OP, but possibly for new VBA users coming along? The information's now there for people who need it, those who don't can ignore it. Given that my method has been in use since the birth of BASIC I'm surprised nobody else suggested it,

macropod
06-29-2020, 12:31 AM
@RtbComp There is nothing in the original discussion to support the implications of your 'tabs and spaces' contention vis-a-vis the OP. Kindly don't re-open ancient (or any other) threads to post something isn't germane to the original discussion. Thread closed.