Read headings from CSV into Form in VBA?

S

Simon

Im using VBA to develop ArcGIS so that I can add added functionality
to it. Dont worry if your not familiar with the software, the
following question is irrelevant to software. Same principle if I was
using MS Word

Think this should be fairly straightforward, I have a few ideas but
would like to bounce them off u lot.

Creating a data entry system for client - nothing fancy:

1. They want to have 4 top heading categories which you can only
choose one of.

2. They then want 5 sub-heading categories (each 5 being different
depending on which top heading was chosen. Multiple sub-headings can
be selected.

3. They want these headings to be changeable - Not often changed, but
perhaps in the future they would like to tweak heading categories.


So, keeping the client out of the VBA code, I thought that perhaps
they could have a simple Excel csv file -

Header1,H1-Sub1,H1-Sub2,H1-Sub3,H1-Sub4,H1-Sub5
Header2,H2-Sub1,H2-Sub2,H2-Sub3,H2-Sub4,H2-Sub5,H2-Sub6
Header3,H3-Sub1,H3-Sub2,,H3-Sub4,
Header4,H4-Sub1,H4-Sub2,H4-Sub3,H4-Sub4,H4-Sub5

Then when in the main project, a form is presented. At the top is a
drop-down - Ive sourced the drop-down items to a text file for now
(new row in txt file is new item) - how would I alter code to read
from the CSV file?

When this drop-down is chosen, it will then read in the corresponding
5 sub choices and update 5 text label/tick box pairs with the correct
headings.

From here, the user will be seeing the correct information to enter
data against.

They choose top level from drop-down. 5 tickbox titles will change
when this happens to show correct categories. User can select multiple
tick-boxes. voila.

So. Is this do-able in VBA? I thought that I might have to split it
into two forms - First a simple tiny form with a drop down pops up -
choose top level, then based on this, will feed variables into the
second form to decide the text boxes. However it would be nice to keep
it all in one form.

Ill leave it at that for now - whadda ya think? Is this bad design,
any better ideas?
 
K

Karl E. Peterson

Simon said:
Im using VBA to develop ArcGIS so that I can add added functionality
to it. Dont worry if your not familiar with the software, the
following question is irrelevant to software. Same principle if I was
using MS Word

Granted. (I use ArcGIS, too.)
Think this should be fairly straightforward, I have a few ideas but
would like to bounce them off u lot.

Creating a data entry system for client - nothing fancy:

1. They want to have 4 top heading categories which you can only
choose one of.

2. They then want 5 sub-heading categories (each 5 being different
depending on which top heading was chosen. Multiple sub-headings can
be selected.

3. They want these headings to be changeable - Not often changed, but
perhaps in the future they would like to tweak heading categories.


So, keeping the client out of the VBA code, I thought that perhaps
they could have a simple Excel csv file -

Header1,H1-Sub1,H1-Sub2,H1-Sub3,H1-Sub4,H1-Sub5
Header2,H2-Sub1,H2-Sub2,H2-Sub3,H2-Sub4,H2-Sub5,H2-Sub6
Header3,H3-Sub1,H3-Sub2,,H3-Sub4,
Header4,H4-Sub1,H4-Sub2,H4-Sub3,H4-Sub4,H4-Sub5

Then when in the main project, a form is presented. At the top is a
drop-down - Ive sourced the drop-down items to a text file for now
(new row in txt file is new item) - how would I alter code to read
from the CSV file?

CSVs are pretty simple. If they're not huge (>1Mb), I tend to just slurp the entire
thing into a single String, Split() on vbCrLf to derive an array of lines, then
Split() each line on the separator (",") to derive an array of elements. Reading
the whole file is as simple as:

Public Function ReadFile(ByVal FileName As String) As String
Dim hFile As Long
On Error GoTo Hell
hFile = FreeFile
Open FileName For Binary As #hFile
ReadFile = Space$(LOF(hFile))
Get #hFile, , ReadFile
Close #hFile
Hell:
End Function
When this drop-down is chosen, it will then read in the corresponding
5 sub choices and update 5 text label/tick box pairs with the correct
headings.

From here, the user will be seeing the correct information to enter
data against.

They choose top level from drop-down. 5 tickbox titles will change
when this happens to show correct categories. User can select multiple
tick-boxes. voila.

So. Is this do-able in VBA?

Of course.
I thought that I might have to split it
into two forms - First a simple tiny form with a drop down pops up -
choose top level, then based on this, will feed variables into the
second form to decide the text boxes. However it would be nice to keep
it all in one form.

Ill leave it at that for now - whadda ya think? Is this bad design,
any better ideas?

All you'd need to do is fill the second list based on selection changes in the
first. Very simple. Not sure what part is causing difficulty? With a dataset this
small, the best design would be to read it all at once, and store an array of arrays
for use in filling the second list as needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top