469,327 Members | 1,238 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

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.
Jul 17 '05 #1
6 4330
On Fri, 27 Feb 2004 09:24:17 -0000, "Roy Riddex"
<ro**************@blueyonder.co.uk> wrote:
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.


Option Explicit: DefObj A-Z

' Add one Listbox
' Add one command button

Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(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(TabWidth() 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(List1.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


Jul 17 '05 #2
> 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.


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-flexSelectionByRow. 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
Jul 17 '05 #3
Try changing the font to "Courier New"
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:31*****************@news-binary.blueyonder.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

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.

Jul 17 '05 #4
: 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.listitems.add (,, sCarRegistration)
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.listitems.add (,, sCarRegistration, ,
ndxOfCarHiredIcon )

set itmx = listview1.listitems.add (,, sCarRegistration, ,
ndxOfCarAvailableIcon )

.... or later ...

itmx.SmallIcon = ndxOfCarAvailableIcon
You can then add code to sort the listview based on a specific column ...

Private Sub ListView1_ColumnClick(ByVal ColumnHeader As
MSComctlLib.ColumnHeader)

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

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Roy Riddex" <ro**************@blueyonder.co.uk> wrote in message
news:31*****************@news-binary.blueyonder.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.
:
:
Jul 17 '05 #5
>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-flexSelectionByRow. Thatwill 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 onfrom the Row property. Rick - MVP


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
Jul 17 '05 #6
> >Have you considered using a FlexGrid? Add a Microsoft FlexGrid Control to
your project (Projects/Components from VB's menubar), change the FixedColsto 0 (leave FixedRows at 1 and put your column header text in its cells),
FocusRect to 0-flexFocusNone and SelectionMode to 1-flexSelectionByRow. 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


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?


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.FormatString = "Header1|Header2|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.TextMatrix(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.TextMatrix(3, 2) = "Some Text Value"

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

Rick - MVP
Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by nizar.jouini | last post: by
22 posts views Thread by yang__lee | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.