Consulting

Results 1 to 13 of 13

Thread: Solved: How to Use VBTAB

  1. #1

    Solved: How to Use VBTAB

    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?

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Here's a simple way... [VBA]Public Const vbTab As String = " " '< Put your spaces here[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by xld
    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 [VBA]MsgBox "my message part1" & " " & "my message part2"[/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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'.

  6. #6
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    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.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Using a string defeats the purpose of VBTab
    eg
    [vba]MsgBox "Note:" & vbTab & "Data1" & vbCr & vbTab & "Data2" & vbCr _
    & vbTab & "Data3" & vbCr[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    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

  9. #9
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    5
    Location
    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

  10. #10
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    @Bob,

    Sub
    Dim sysTab as String
       sysTab = vbTab
       vbTab = "   "
    
       blah 
       blah
       blah
    
    vbTab = sysTab
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  11. #11
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    @RtbComp -- all true, but that was a 13 year old post, so I doubt if it's an issue any more

    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  12. #12
    VBAX Newbie
    Joined
    Jun 2020
    Posts
    5
    Location
    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,

  13. #13
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    @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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •