Formating in listbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kin®sole

    #1

    Formating in listbox

    Hi
    I am trying to add two variables to a list box and keep everything in line.I
    get the result below

    Gaz £2000
    Jimmy £3000
    fred £4000

    but would like to get this result


    Gaz £2000
    Jimmy £3000
    fred £4000

    I am using to courier font so the letter are equally spaced but don't know
    how to format the spaces to take into account the different length of the
    variables

    Any pointers


    --
    cheers dude
    ************
    kin®sole
    ************




  • CajunCoiler \(http://www.cajuncoiler.tk\)

    #2
    Re: Formating in listbox

    Start with a fixed string length....

    Next, subtract the length of the name, and the length of
    the pound amount, and this leaves you with the number
    of spaces to put in between, to format them properly.

    number_of_space s = max_string_leng th - name_length - pound_length

    formatted_strin g$ = name$ + string$(number_ of_spaces, " ") + pound$

    As a sidenote, for better format alignment, I would
    suggest switching to the "fixedsys" font, if all the
    characters you need are available in it.
    --
    C.L. Mayeux
    Owner, MSB Data Systems

    "Kin®sole" <kinrsole@NOSPA Mhotmail.com> wrote in message
    news:23c8ee853e 13babdf9cc599b9 66e77d3@news.te ranews.com...[color=blue]
    > Hi
    > I am trying to add two variables to a list box and keep everything in[/color]
    line.I[color=blue]
    > get the result below
    >
    > Gaz £2000
    > Jimmy £3000
    > fred £4000
    >
    > but would like to get this result
    >
    >
    > Gaz £2000
    > Jimmy £3000
    > fred £4000
    >
    > I am using to courier font so the letter are equally spaced but don't know
    > how to format the spaces to take into account the different length of the
    > variables
    >
    > Any pointers
    >
    >
    > --
    > cheers dude
    > ************
    > kin®sole
    > ************
    >
    >
    >
    >[/color]


    Comment

    • Raoul Watson

      #3
      Re: Formating in listbox


      "Kin®sole" <kinrsole@NOSPA Mhotmail.com> wrote in message
      news:23c8ee853e 13babdf9cc599b9 66e77d3@news.te ranews.com...[color=blue]
      > Hi
      > I am trying to add two variables to a list box and keep everything in[/color]
      line.I[color=blue]
      > get the result below
      >
      > Gaz £2000
      > Jimmy £3000
      > fred £4000
      >
      > but would like to get this result
      >
      >
      > Gaz £2000
      > Jimmy £3000
      > fred £4000
      >
      > I am using to courier font so the letter are equally spaced but don't know
      > how to format the spaces to take into account the different length of the
      > variables[/color]

      Well, you have to first determine the widest acceptable size. Once this is
      done, you can create a simple function such as this (this is one of the many
      ways):

      Function allign2Vars(v1$ , v2$, colWidth)
      Dim vw
      vw = Len(v1$) + Len(v2$)
      ' trap for too small of a size
      If ((colWidth \ 2) - Len(v1$)) < 1 Then
      allign2Vars = v1$ & v2$
      Else
      allign2Vars = v1$ & String(colWidth \ 2 - Len(v1$), 32) & v2$
      End If
      End Function

      To use it, simply pass the two vars and the limit width. Assuming you want
      to not exceed 20 characters width:

      a$ = "Jim": b$ = "Smith"
      c$ = allign2Vars(a$, b$, 20)
      List1.AddItem c$

      a$ = "Susan": b$ = "Young"
      c$ = allign2Vars(a$, b$, 20)
      List1.AddItem c$


      Comment

      • Kin®sole

        #4
        Re: Formating in listbox

        Thanks for the replies.
        Very helpful


        --
        cheers dudes
        ************
        kin®sole
        ************


        "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
        news:beZyc.2088 1$wi2.14887@nwr dny01.gnilink.n et...[color=blue]
        >
        > "Kin®sole" <kinrsole@NOSPA Mhotmail.com> wrote in message
        > news:23c8ee853e 13babdf9cc599b9 66e77d3@news.te ranews.com...[color=green]
        > > Hi
        > > I am trying to add two variables to a list box and keep everything in[/color]
        > line.I[color=green]
        > > get the result below
        > >
        > > Gaz £2000
        > > Jimmy £3000
        > > fred £4000
        > >
        > > but would like to get this result
        > >
        > >
        > > Gaz £2000
        > > Jimmy £3000
        > > fred £4000
        > >
        > > I am using to courier font so the letter are equally spaced but don't[/color][/color]
        know[color=blue][color=green]
        > > how to format the spaces to take into account the different length of[/color][/color]
        the[color=blue][color=green]
        > > variables[/color]
        >
        > Well, you have to first determine the widest acceptable size. Once this is
        > done, you can create a simple function such as this (this is one of the[/color]
        many[color=blue]
        > ways):
        >
        > Function allign2Vars(v1$ , v2$, colWidth)
        > Dim vw
        > vw = Len(v1$) + Len(v2$)
        > ' trap for too small of a size
        > If ((colWidth \ 2) - Len(v1$)) < 1 Then
        > allign2Vars = v1$ & v2$
        > Else
        > allign2Vars = v1$ & String(colWidth \ 2 - Len(v1$), 32) & v2$
        > End If
        > End Function
        >
        > To use it, simply pass the two vars and the limit width. Assuming you want
        > to not exceed 20 characters width:
        >
        > a$ = "Jim": b$ = "Smith"
        > c$ = allign2Vars(a$, b$, 20)
        > List1.AddItem c$
        >
        > a$ = "Susan": b$ = "Young"
        > c$ = allign2Vars(a$, b$, 20)
        > List1.AddItem c$
        >
        >[/color]


        Comment

        • Randy Birch

          #5
          Re: Formating in listbox

          You want custom tab stops in a listbox ... and you might even want
          right-aligned tabs as well.

          Grab this tool http://vbnet.mvps.org/code/listapi/cooltabs.htm to generate
          the code you need ... and read up on the code here:
          VBnet provides Intermediate and Advanced Win32 API code for VB developers. Comprehensive Code, FAQ, Developers Resources & News, alphabetical API/Type/Constant/Method Index, along with the largest Visual Basic-related links list on the net.


          --

          Randy Birch
          MVP Visual Basic

          Please respond only to the newsgroups so all can benefit.


          "Kin®sole" <kinrsole@NOSPA Mhotmail.com> wrote in message
          news:23c8ee853e 13babdf9cc599b9 66e77d3@news.te ranews.com...
          : Hi
          : I am trying to add two variables to a list box and keep everything in
          line.I
          : get the result below
          :
          : Gaz #2000
          : Jimmy #3000
          : fred #4000
          :
          : but would like to get this result
          :
          :
          : Gaz #2000
          : Jimmy #3000
          : fred #4000
          :
          : I am using to courier font so the letter are equally spaced but don't know
          : how to format the spaces to take into account the different length of the
          : variables
          :
          : Any pointers
          :
          :
          : --
          : cheers dude
          : ************
          : kin.sole
          : ************
          :
          :
          :
          :

          Comment

          • Trevor Watson

            #6
            Re: Formating in listbox

            Couldn't he just use the format command

            List1.AddItem Format("Gaz", "!@@@@@@@@@@@@@ @@") & "£2000"

            This would give a 15 character block for the first part ("Gaz") and add the
            value after

            The "!" is needed because format automatically fills from the left, this
            forces it to the right


            Comment

            • Randy Birch

              #7
              Re: Formating in listbox

              That requires a fixed-width font for the text to align properly. The API
              method actually sets tab stops at desired intervals thereby supporting the
              default font or another such as truetype. Personally, I deem an application
              as 'amateur' when a listbox must used a non-standard fixed-width font in
              order to align its contents.
              --

              Randy Birch
              MVP Visual Basic

              Please respond only to the newsgroups so all can benefit.


              "Trevor Watson" <trevor@gateway software.ca> wrote in message
              news:c8SdnYHBf6 UCKFDdRVn-uQ@look.ca...
              : Couldn't he just use the format command
              :
              : List1.AddItem Format("Gaz", "!@@@@@@@@@@@@@ @@") & "#2000"
              :
              : This would give a 15 character block for the first part ("Gaz") and add
              the
              : value after
              :
              : The "!" is needed because format automatically fills from the left, this
              : forces it to the right
              :
              :

              Comment

              Working...