ListBoxes, Parsing and .CSV files... (Oh My...) 
Author Message
 ListBoxes, Parsing and .CSV files... (Oh My...)

Good day all.

I have a project where I need to read from the contents of an existing, and
occasionally updated, .csv file.
I need to be able to load the 1st section of each entry into a list/combo
box, and then, when that item is clicked, have it display the rest of that
entries information in a series of textboxes.

Yes, it does sound crazy, but, currently, a 3 year old, 50k C+ application
is doing it. However, it is very ugly (GUI wise), and crashes on Win98. My
hope is to replace it with a more modern, more accessible version.

Here's an example:
-----------------------------------------------
In the .csv, here are the fields...
<company name, phone, fax, web, other  >
When the form loads, I need to  '   .additem company name '
until the listbox contains all of the entries, currently 2700 lines...

When item 1 is clicked on, for instance,
'Microsoft'
the txtphone, txtfax, txtweb text needs to equal the resulting and relevant
code.
----------------------------------------------------------------------------
----
I have tried several ways to do this, but, I usually end up with mixed up
entries, and endless loops that eventually lock up the machine (fun, but,
not client worthy <g>)

Anyway, if anyone has any ideas about alternate means of doing this, or
would like to poke fun at me for missing the obvious (preferred), please
respond.

Yours,
Scott McDaniel
McDaniel Development
www.mcdev.com  (Under eternal construction)



Sun, 03 Feb 2002 03:00:00 GMT  
 ListBoxes, Parsing and .CSV files... (Oh My...)
One alternative you might want to look at is using a data aware class (VB6).
Have a look at the
"Interacting with Data in an ASCII Text File" topic in the help file.


Quote:
> Good day all.

> I have a project where I need to read from the contents of an existing,
and
> occasionally updated, .csv file.
> I need to be able to load the 1st section of each entry into a list/combo
> box, and then, when that item is clicked, have it display the rest of that
> entries information in a series of textboxes.

> Yes, it does sound crazy, but, currently, a 3 year old, 50k C+ application
> is doing it. However, it is very ugly (GUI wise), and crashes on Win98. My
> hope is to replace it with a more modern, more accessible version.

> Here's an example:
> -----------------------------------------------
> In the .csv, here are the fields...
> <company name, phone, fax, web, other  >
> When the form loads, I need to  '   .additem company name '
> until the listbox contains all of the entries, currently 2700 lines...

> When item 1 is clicked on, for instance,
> 'Microsoft'
> the txtphone, txtfax, txtweb text needs to equal the resulting and
relevant
> code.
> --------------------------------------------------------------------------
--
> ----
> I have tried several ways to do this, but, I usually end up with mixed up
> entries, and endless loops that eventually lock up the machine (fun, but,
> not client worthy <g>)

> Anyway, if anyone has any ideas about alternate means of doing this, or
> would like to poke fun at me for missing the obvious (preferred), please
> respond.

> Yours,
> Scott McDaniel
> McDaniel Development
> www.mcdev.com  (Under eternal construction)



Sun, 03 Feb 2002 03:00:00 GMT  
 ListBoxes, Parsing and .CSV files... (Oh My...)
Consider using the ItemData Property also.  For Example:

List1.AddItem strCompany
List1.ItemData(List1.NewIndex) = lngCounter

I imagine you're populating the ListBox in a while loop <> EOF, so
throw a counter in the ItemData.

Then, a lookup can be based on the "record number"

Private Sub List1_Click ()

        lngCounter = List1.ItemData(List1.ListIndex)

        ' Now, go get the record based on lngCounter (reading the
eniter line, and parse as required

End Sub

Jeff



Sun, 03 Feb 2002 03:00:00 GMT  
 ListBoxes, Parsing and .CSV files... (Oh My...)
on second thoughts you might just want to try something like this:

' declares
' made need to change this depending on CSV format

Private Type typAddress
   Name As String
   Phone As String
   Fax As String
   Web As String
   Other As String
End Type

Dim myAddresses() As typAddress
'end declares

'call this to refresh the list.  note: you could use
' a timer to check the files lastmodified property
'and call this if it has changed
' strFile is the name (and path) of the csv file to read

Private Sub RefreshFromCSV(strFile As String)
   ReDim myAddresses(100)
   Dim i As Long, j As Long
   Dim f As Long
   f = FreeFile
   Open strFile For Input As #f
   Do Until EOF(f)
      If UBound(myAddresses) < i Then ReDim Preserve myAddresses(i + 100)
      With myAddresses(i)
      Input #1, .Name, .Phone, .Fax, .Web, .Other
      i = i + 1
      End With
   Loop
   Close #f
   List1.Clear
   For j = 0 To i - 1
     List1.AddItem (myAddresses(j).Name)
    ' using itemdata allows us to let the list sort itself
     List1.ItemData(List1.NewIndex) = j
   Next j
End Sub

Private Sub List1_Click()
   Dim i As Long
   i = List1.ItemData(List1.ListIndex)
   Text1 = myAddresses(i).Phone
   Text2 = myAddresses(i).Fax
   Text3 = myAddresses(i).Web
   Text4 = myAddresses(i).Other
End Sub


Quote:
> One alternative you might want to look at is using a data aware class
(VB6).
> Have a look at the
> "Interacting with Data in an ASCII Text File" topic in the help file.



> > Good day all.

> > I have a project where I need to read from the contents of an existing,
> and
> > occasionally updated, .csv file.
> > I need to be able to load the 1st section of each entry into a
list/combo
> > box, and then, when that item is clicked, have it display the rest of
that
> > entries information in a series of textboxes.

> > Yes, it does sound crazy, but, currently, a 3 year old, 50k C+
application
> > is doing it. However, it is very ugly (GUI wise), and crashes on Win98.
My
> > hope is to replace it with a more modern, more accessible version.

> > Here's an example:
> > -----------------------------------------------
> > In the .csv, here are the fields...
> > <company name, phone, fax, web, other  >
> > When the form loads, I need to  '   .additem company name '
> > until the listbox contains all of the entries, currently 2700 lines...

> > When item 1 is clicked on, for instance,
> > 'Microsoft'
> > the txtphone, txtfax, txtweb text needs to equal the resulting and
> relevant
> > code.

> --------------------------------------------------------------------------
> --
> > ----
> > I have tried several ways to do this, but, I usually end up with mixed
up
> > entries, and endless loops that eventually lock up the machine (fun,
but,
> > not client worthy <g>)

> > Anyway, if anyone has any ideas about alternate means of doing this, or
> > would like to poke fun at me for missing the obvious (preferred), please
> > respond.

> > Yours,
> > Scott McDaniel
> > McDaniel Development
> > www.mcdev.com  (Under eternal construction)



Sun, 03 Feb 2002 03:00:00 GMT  
 ListBoxes, Parsing and .CSV files... (Oh My...)
Is the .csv file being updated WHILE a user is in your app?  Or do you only
need
to display what is in the file at the time you open it?

If you don't need 'dynamic cursor-like' functionality, why not load the
whole
.csv into a collection, and access each member by key when the user chooses
an entry in the list/cobmo box?

I know that a 2700 item collection sounds large, but I bet it isn't as cpu
intensive as constant I/O to the .csv file.

Patrice Smith, MCP


Quote:
> Good day all.

> I have a project where I need to read from the contents of an existing,
and
> occasionally updated, .csv file.
> I need to be able to load the 1st section of each entry into a list/combo
> box, and then, when that item is clicked, have it display the rest of that
> entries information in a series of textboxes.

> Yes, it does sound crazy, but, currently, a 3 year old, 50k C+ application
> is doing it. However, it is very ugly (GUI wise), and crashes on Win98. My
> hope is to replace it with a more modern, more accessible version.

> Here's an example:
> -----------------------------------------------
> In the .csv, here are the fields...
> <company name, phone, fax, web, other  >
> When the form loads, I need to  '   .additem company name '
> until the listbox contains all of the entries, currently 2700 lines...

> When item 1 is clicked on, for instance,
> 'Microsoft'
> the txtphone, txtfax, txtweb text needs to equal the resulting and
relevant
> code.
> --------------------------------------------------------------------------
--
> ----
> I have tried several ways to do this, but, I usually end up with mixed up
> entries, and endless loops that eventually lock up the machine (fun, but,
> not client worthy <g>)

> Anyway, if anyone has any ideas about alternate means of doing this, or
> would like to poke fun at me for missing the obvious (preferred), please
> respond.

> Yours,
> Scott McDaniel
> McDaniel Development
> www.mcdev.com  (Under eternal construction)



Sun, 03 Feb 2002 03:00:00 GMT  
 ListBoxes, Parsing and .CSV files... (Oh My...)
Or, um... do you have the option of putting the .csv into an .mdb file
(Access database).  Sounds like even the data store could use
a more modern, accessible version....


Quote:
> Is the .csv file being updated WHILE a user is in your app?  Or do you
only
> need
> to display what is in the file at the time you open it?

> If you don't need 'dynamic cursor-like' functionality, why not load the
> whole
> .csv into a collection, and access each member by key when the user
chooses
> an entry in the list/cobmo box?

> I know that a 2700 item collection sounds large, but I bet it isn't as cpu
> intensive as constant I/O to the .csv file.

> Patrice Smith, MCP



> > Good day all.

> > I have a project where I need to read from the contents of an existing,
> and
> > occasionally updated, .csv file.
> > I need to be able to load the 1st section of each entry into a
list/combo
> > box, and then, when that item is clicked, have it display the rest of
that
> > entries information in a series of textboxes.

> > Yes, it does sound crazy, but, currently, a 3 year old, 50k C+
application
> > is doing it. However, it is very ugly (GUI wise), and crashes on Win98.
My
> > hope is to replace it with a more modern, more accessible version.

> > Here's an example:
> > -----------------------------------------------
> > In the .csv, here are the fields...
> > <company name, phone, fax, web, other  >
> > When the form loads, I need to  '   .additem company name '
> > until the listbox contains all of the entries, currently 2700 lines...

> > When item 1 is clicked on, for instance,
> > 'Microsoft'
> > the txtphone, txtfax, txtweb text needs to equal the resulting and
> relevant
> > code.

> --------------------------------------------------------------------------
> --
> > ----
> > I have tried several ways to do this, but, I usually end up with mixed
up
> > entries, and endless loops that eventually lock up the machine (fun,
but,
> > not client worthy <g>)

> > Anyway, if anyone has any ideas about alternate means of doing this, or
> > would like to poke fun at me for missing the obvious (preferred), please
> > respond.

> > Yours,
> > Scott McDaniel
> > McDaniel Development
> > www.mcdev.com  (Under eternal construction)



Sun, 03 Feb 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. ListBoxes, Parsing and .CSV files... (Oh My...)

2. help needed parsing csv file

3. Novice Question: csv file parsing

4. newbie needs help parsing csv file

5. Parsing a csv file

6. Parsing CSV file

7. Script to parse Outlook survey results to a .CSV file

8. Need Regexp pattern to parse csv

9. Parsing a csv record - What is the quickest method

10. Oh where...oh where

11. VB6 ListView: Why oh why oh why...

12. VB6 ListView: Why oh why oh why...

 

 
Powered by phpBB® Forum Software