Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending items to CSV

Status
Not open for further replies.

crusader

Programmer
Apr 26, 2001
24
GB
Hi,

I'm trying to change the value of a posted form element then write this to a CSV file.

I have a form of questions which posts over to a processing page. This processing page insert the values into the CSV file.

Some of the question lead on to other question e.g "if yes then what is your choice?".

My problem is when the user chooses a radio button but the next question means that they will not choose the radio button representing "if yes then what is your choice?".

When the processing page handles this, it just skips the value and inserts the remaining values into the CSV, as a result the CSV is a column short. Some how I need to but a blank value in the missed column




here is my processing code:

dim fsoObj, sFileName, objtextFile, fieldName, fieldValue
sFileName = server.mappath("swimming_results.csv")
set fsoObj = Server.CreateObject("Scripting.FileSystemObject")
set objtextFile = fsoObj.OpenTextFile(sFileName, 8)
For ix = 1 to Request.Form.Count
'********form elements processed here*
fieldName = Request.Form.Key(ix)
response.write(fieldName&ix)&":        "
'*******form element values processed here*
fieldValue = fieldValue&Request.Form.Item(ix)&","
response.write(fieldValue)&"<br>"
Next
objTextFile.WriteLine(fieldValue)
objTextFile.Close
set objTextFile = nothing
set fsoObj = nothing


Please help!
 
I think the only way your going to manage that is to either:
a) Tweak the form to pass an empty value when an option is available (so if the radio buttons aren't available, maybe have a hidden field that passes a space or something)

or
b) Instead of looping through all the fields indiscrimately in your processing page either loop through a hard-coded array of expected field names or take the longer form and put in code for each and every possible field name so that if the value of an expected field doesn't exist you can still drop a comma in your CSV file.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Thanks for the advise Tarwn,

I set the fieldName and fieldValue to the form contents and checked to see if they had contents first, if they did not I replaced the fieldValuse with a '0'

Many Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top