473,416 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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 4474
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
7
by: nizar.jouini | last post by:
Hello. I have long text file whitch is formatted like this: nextrow4 asdf asdf
13
by: gavino | last post by:
This seems easy but I have been asking tcl and python IRC chat all day and no one gave an answer. I have 100 servers which need a new backup server added to a text file, and then the backup agent...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
0
by: hellosibba | last post by:
Hi i am trying to use text file to write a value as soon as there is any update/insert into a table. for that i am using a text file and made a linked server relation with it..... and inserting...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
22
by: yang__lee | last post by:
Hi, I hope you may help me. Please check the attached text file. Actually its a report file with some headers information and them report is in tabular format. I want to parse each row and...
0
by: JosAH | last post by:
Greetings, the last two article parts described the design and implementation of the text Processor which spoonfeeds paragraphs of text to the LibraryBuilder. The latter object organizes, cleans...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.