Re: Read headings from CSV into Form in VBA?



Simon wrote:
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.
--
..NET: It's About Trust!
http://vfred.mvps.org


.



Relevant Pages

  • Re: Faster way to read UDT from disk?
    ... suggested trying to read the whole array in one fell swoop. ... Dim NumOfRecs As Long ... Public Function ReadFileEx(ByVal FileName As String) As String ... Dim hFile As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: vba code to search in a txt document
    ... If I find that string in the txt document, I have to take the line of ... Dim hFile As Long ... ReadFile = Space$) ... Then just loop through the array, using Instrto search for your desired ...
    (microsoft.public.word.vba.beginners)
  • Re: Fastest reading of large text files
    ... As I understand it, arr is an array of type Variant, which the function ... OpenTextFileToArray is populating with the contents of the named text file. ... But is it not an array in the PROGRAM? ... Dim hFile As Long ...
    (microsoft.public.excel.programming)
  • Re: Subscript out of range
    ... the lower bound for both of the dimensions in this array ... Dim hFile As Integer ... in the loop below, you start the myArray ...
    (comp.lang.basic.visual.misc)
  • Re: More about sorting text lines?
    ... then use Split to return an array with each line: ... dim hfile as long ... Is this a good way to fill an array, then Quicksort it? ... here to being a list in decending order? ...
    (comp.lang.basic.visual.misc)