Complex options for exporting to text file
I have a problem. I wrote a program that will export results from it's search into a csv file.
The program gives the user an option to export only a certian amount of information. The information the program gathers is
First Name
Last Name
Phone Number
Location
Machine Type
Dell Tag
I have a check box for each bit of information the program can grab. I want the csv file to correctly place the information in the file based on what options the user selects.
I am adding the information which is generated from a listview control to an array list.
When I open the text file if I have the options First Name , Last Name and Location check boxes marked I get output in my text file like this for each line.
MachineName,FirstName,LastName, ,Location,,
You see there are blank csv values between lastname and after location. How can I get my program to generate the results correctly in the text file? I want it to look like this
MachineName,FirstName,LastName,Location
Keep in my the order of things in the output can change based on what check boxes the user selects. I have a boolean array setup in my function that stores the value of all the check boxes so the program will know if it needs to gather that data but, I can't figure out how to get the program to correctly output the data with out having blank values in spots if the user unchecks a box.
Re: Complex options for exporting to text file
I know I could do an if statement for every possible way the data could be outputed but there must be a better way to do this.
That would be a ton of if statements
Re: Complex options for exporting to text file
Hi,
You can do it quite easily. Just increment through the array and don't add the item if there is no check.
To see what I mean, consider copying your array to another array:
j = 0
For i = 1 to firstarraycount
if firstarray(i) <> "" then
secondarray(j) = firstarray(i)
j = j+1
end if
next i
Actually, you might want to use a Trim statement to remove all padded spaces from firstarray(i).
Then try doing it without needing to use the second array.
But on a practical note, I wouldn't do this at all. If you were to then read the text file back in without the delimiting spaces, you won't know how to match the data with the fields, i.e.
Bob Jones, 121 Fluff St, Ann Arbor, , US
gives:
Name: Bob Jones
Street: 121 Fluff St
City: Ann Arbor
State:
Country: US
whereas
Bob Jones, 121 Fluff St, Ann Arbor, US
gives:
Name: Bob Jones
Street: 121 Fluff St
City: Ann Arbor
State: US
Country:
HTH
zaza