Text File Help Needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roy Riddex

    Text File Help Needed

    I have a text file which holds data for 30 cars in the following way:

    CarRegistration CarType CarClass Available

    I'm trying to display the full contents of this text file in a list box so
    the user can see the total car fleet, my problem is that I want everything
    to line up. So far what I'm getting is something like:

    R296RKV Ford Mondeo Large On Hire
    TUVWXYZ Vauxhall Vectra Large
    Available

    Is there a way to line these up or a more efficient way of displaying the
    fleet other than using a listbox?

    Thanks in advance for any help.
    Roy

    PS. It's a college assignment and the text file is a must have, so I'm stuck
    with it.


  • J French

    #2
    Re: Text File Help Needed

    On Fri, 27 Feb 2004 09:24:17 -0000, "Roy Riddex"
    <roy_riddexNOSP [email protected] o.uk> wrote:
    [color=blue]
    >I have a text file which holds data for 30 cars in the following way:
    >
    >CarRegistratio n CarType CarClass Available
    >
    >I'm trying to display the full contents of this text file in a list box so
    >the user can see the total car fleet, my problem is that I want everything
    >to line up.[/color]

    Option Explicit: DefObj A-Z

    ' Add one Listbox
    ' Add one command button

    Private Declare Function SendMessage _
    Lib "user32" Alias "SendMessag eA" _
    (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
    Private Const LB_SETTABSTOPS = &H192


    ' ############### ############### ############### ########
    '
    ' TabWidth(0) = Number of Tabs
    ' TabWidth(1 to n) = Width of Each Field in Bytes
    '
    Sub SetTabWidths(Ta bWidth() As Long)
    Dim Max&, L9%
    If TabWidth(0) < 1 Or TabWidth(0) > UBound(TabWidth ) Then
    MsgBox ("EPL - Bad TabWidth(0) in SetTabWidths")
    End If
    Max = TabWidth(0)
    ReDim Q&(Max + 1)
    For L9 = 1 To Max
    Q(L9) = TabWidth(L9) * 4 ' 4 Dialog Units Per Char
    Q(L9) = Q(L9 - 1) + Q(L9)
    Next
    Call SendMessage(Lis t1.hWnd, LB_SETTABSTOPS, Max, Q&(1))
    End Sub

    Private Sub Command1_Click( )
    Dim L9%, Q&(2)
    For L9 = 1 To 20
    List1.AddItem Str$(L9) + vbTab _
    + Str$(L9) + "a" + vbTab _
    + "Col3"
    Next

    Q(0) = 2 ' 1st Column is zero offset
    Q(1) = 10
    Q(2) = 10
    Call Me.SetTabWidths (Q())
    End Sub




    Comment

    • Rick Rothstein

      #3
      Re: Text File Help Needed

      > I have a text file which holds data for 30 cars in the following way:[color=blue]
      >
      > CarRegistration CarType CarClass Available
      >
      > I'm trying to display the full contents of this text file in a list box so
      > the user can see the total car fleet, my problem is that I want everything
      > to line up. So far what I'm getting is something like:
      >
      > R296RKV Ford Mondeo Large On Hire
      > TUVWXYZ Vauxhall Vectra Large
      > Available
      >
      > Is there a way to line these up or a more efficient way of displaying the
      > fleet other than using a listbox?
      >
      > Thanks in advance for any help.
      > Roy
      >
      > PS. It's a college assignment and the text file is a must have, so I'm[/color]
      stuck[color=blue]
      > with it.[/color]

      Have you considered using a FlexGrid? Add a Microsoft FlexGrid Control to
      your project (Projects/Components from VB's menubar), change the FixedCols
      to 0 (leave FixedRows at 1 and put your column header text in its cells),
      FocusRect to 0-flexFocusNone and SelectionMode to 1-flexSelectionBy Row. That
      will produce a reasonable looking substitute ListBox with "tabbed" fields.
      If you don't want the grid lines to show (making it look more like a
      ListBox), you could set the GridLines property to 0-flexGridNone. Of course,
      placing data into the grid is different from doing the same in a ListBox,
      but still quite simple to do. You would then get the item the user clicks on
      from the Row property.

      Rick - MVP


      Comment

      • K-man

        #4
        Re: Text File Help Needed

        Try changing the font to "Courier New"


        "Roy Riddex" <roy_riddexNOSP [email protected] o.uk> wrote in message
        news:31E%b.5029 [email protected] er.co.uk...[color=blue]
        > I have a text file which holds data for 30 cars in the following way:
        >
        > CarRegistration CarType CarClass Available
        >
        > I'm trying to display the full contents of this text file in a list box so
        > the user can see the total car fleet, my problem is that I want everything
        > to line up. So far what I'm getting is something like:
        >
        > R296RKV Ford Mondeo Large On Hire
        > TUVWXYZ Vauxhall Vectra Large
        > Available
        >
        > Is there a way to line these up or a more efficient way of displaying the
        > fleet other than using a listbox?
        >
        > Thanks in advance for any help.
        > Roy
        >
        > PS. It's a college assignment and the text file is a must have, so I'm[/color]
        stuck[color=blue]
        > with it.
        >
        >[/color]


        Comment

        • Randy Birch

          #5
          Re: Text File Help Needed

          : Is there a way to line these up or a more efficient way of displaying the
          : fleet other than using a listbox?

          Use a listview control (ms common controls set) similar to the files listing
          in explorer. Set the control's view property to report, add the four
          columnheaders, and add the item data / subitems ...

          dim itmx as listitem

          set itmx = listview1.listi tems.add (,, sCarRegistratio n)
          itmx.subitems(1 ) = sCarType
          itmx.subitems(2 ) = sCarClass
          itmx.subitems(3 ) = sAvailable

          You can even change the icons for each one based on some parameter, perhaps
          a red car for 'on hire' and a green car for 'available'. To do this add an
          imagelist to the form, add the 16x16 icons, and use as required. This can be
          done either during the load ...

          set itmx = listview1.listi tems.add (,, sCarRegistratio n, ,
          ndxOfCarHiredIc on )

          set itmx = listview1.listi tems.add (,, sCarRegistratio n, ,
          ndxOfCarAvailab leIcon )

          .... or later ...

          itmx.SmallIcon = ndxOfCarAvailab leIcon


          You can then add code to sort the listview based on a specific column ...

          Private Sub ListView1_Colum nClick(ByVal ColumnHeader As
          MSComctlLib.Col umnHeader)

          With ListView1
          .SortKey = ColumnHeader.In dex - 1
          .SortOrder = Abs(Not .SortOrder = 1)
          .Sorted = True
          end with


          --

          Randy Birch
          MVP Visual Basic

          Please respond only to the newsgroups so all can benefit.


          "Roy Riddex" <roy_riddexNOSP [email protected] o.uk> wrote in message
          news:31E%b.5029 [email protected] er.co.uk...
          : I have a text file which holds data for 30 cars in the following way:
          :
          : CarRegistration CarType CarClass Available
          :
          : I'm trying to display the full contents of this text file in a list box so
          : the user can see the total car fleet, my problem is that I want everything
          : to line up. So far what I'm getting is something like:
          :
          : R296RKV Ford Mondeo Large On Hire
          : TUVWXYZ Vauxhall Vectra Large
          : Available
          :

          :
          : Thanks in advance for any help.
          : Roy
          :
          : PS. It's a college assignment and the text file is a must have, so I'm
          stuck
          : with it.
          :
          :


          Comment

          • Roy Riddex

            #6
            Re: Text File Help Needed

            >Have you considered using a FlexGrid? Add a Microsoft FlexGrid Control to[color=blue]
            >your project (Projects/Components from VB's menubar), change the FixedCols
            >to 0 (leave FixedRows at 1 and put your column header text in its cells),
            >FocusRect to 0-flexFocusNone and SelectionMode to 1-flexSelectionBy Row.[/color]
            That[color=blue]
            >will produce a reasonable looking substitute ListBox with "tabbed" fields.
            >If you don't want the grid lines to show (making it look more like a
            >ListBox), you could set the GridLines property to 0-flexGridNone. Of[/color]
            course,[color=blue]
            >placing data into the grid is different from doing the same in a ListBox,
            >but still quite simple to do. You would then get the item the user clicks[/color]
            on[color=blue]
            >from the Row property.[/color]
            [color=blue]
            >Rick - MVP[/color]

            I like this idea Rick. Couple of questions though. I can only get column
            header text into header 1 using the FormatString property, how do I get the
            rest of the headings in? And, how do I populate the grid with my data? for
            example how would I allocate text to B2?
            Thanks again


            Comment

            • Rick Rothstein

              #7
              Re: Text File Help Needed

              > >Have you considered using a FlexGrid? Add a Microsoft FlexGrid Control to[color=blue][color=green]
              > >your project (Projects/Components from VB's menubar), change the[/color][/color]
              FixedCols[color=blue][color=green]
              > >to 0 (leave FixedRows at 1 and put your column header text in its cells),
              > >FocusRect to 0-flexFocusNone and SelectionMode to 1-flexSelectionBy Row.[/color]
              > That[color=green]
              > >will produce a reasonable looking substitute ListBox with "tabbed"[/color][/color]
              fields.[color=blue][color=green]
              > >If you don't want the grid lines to show (making it look more like a
              > >ListBox), you could set the GridLines property to 0-flexGridNone. Of[/color]
              > course,[color=green]
              > >placing data into the grid is different from doing the same in a ListBox,
              > >but still quite simple to do. You would then get the item the user clicks[/color]
              > on[color=green]
              > >from the Row property.[/color]
              >[color=green]
              > >Rick - MVP[/color]
              >
              > I like this idea Rick. Couple of questions though. I can only get column
              > header text into header 1 using the FormatString property, how do I get[/color]
              the[color=blue]
              > rest of the headings in? And, how do I populate the grid with my data? for
              > example how would I allocate text to B2?[/color]

              You didn't show any code, so I'm not sure where you went wrong. Here is how
              to assign the first three column headers

              MSFlexGrid1.For matString = "Header1|Header 2|Header3"

              Note the vertical bar being used as the separator. You can also place the
              header in the same way you can place text elsewhere in the grid... use the
              TextMatrix property. For example, to place Header4, you could do this...

              MSFlexGrid1.Tex tMatrix(0, 3) = "Header4"

              To place some text value into, say, cell c4 (I didn't want to use B2 because
              B equates to 2) this way...

              MSFlexGrid1.Tex tMatrix(3, 2) = "Some Text Value"

              You'll need to place all your data using For-Next loops.

              Rick - MVP


              Comment

              Working...