At the risk of being told "If it ain't broke, don't fix it", my code works,
but is ugly.
Part of the admin site I'm working on at the moment includes a facility for
users to enter Formulations (recipes for making cosmetics etc) in 3 stages:
Stage 1: basic info such as title, method etc and number of Phases (steps in
recipe).
Stage 2: dynamically generated form containing the exact number of phases as
textboxes, depending on the number entered in stage 1. Phases are labelled
A, B, C...etc. They rarely exceed 8 in total. In each text box, the user
enters the number of ingredients per phase.
Stage 3: dynamically generated form offering the correct number of text
boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the
phase they belong to. Of course, if there is more than one ingredients per
phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients:
if len(Request.Form("IngredientsA"))>0 then
....process the data
end if
if len(Request.Form("IngredientsB"))>0 then
....process the data
end if
if len(Request.Form("IngredientsC"))>0 then
....process the data
up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a better
way of iterating through these form fields than this. Coding to cater for
up to 10 possible phases is repetitive, and is over 200 lines long.
Elegant, it ain't! Anyone got any ideas?
P 4 4265
"Paxton" <paxtonend@[no-spam]hotmail.com> wrote in message
news:M8****************@fe2.news.blueyonder.co.uk. .. At the risk of being told "If it ain't broke, don't fix it", my code
works, but is ugly.
Part of the admin site I'm working on at the moment includes a facility
for users to enter Formulations (recipes for making cosmetics etc) in 3
stages: Stage 1: basic info such as title, method etc and number of Phases (steps
in recipe). Stage 2: dynamically generated form containing the exact number of phases
as textboxes, depending on the number entered in stage 1. Phases are
labelled A, B, C...etc. They rarely exceed 8 in total. In each text box, the user enters the number of ingredients per phase. Stage 3: dynamically generated form offering the correct number of text boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the phase they belong to. Of course, if there is more than one ingredients
per phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients: if len(Request.Form("IngredientsA"))>0 then ....process the data end if if len(Request.Form("IngredientsB"))>0 then ....process the data end if if len(Request.Form("IngredientsC"))>0 then ....process the data up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a
better way of iterating through these form fields than this. Coding to cater for up to 10 possible phases is repetitive, and is over 200 lines long. Elegant, it ain't! Anyone got any ideas? http://aspfaq.com/show.asp?id=2036
"Chris Hohmann" <no****@thankyou.com> wrote in message news:<OQ**************@TK2MSFTNGP14.phx.gbl>... "Paxton" <paxtonend@[no-spam]hotmail.com> wrote in message news:M8****************@fe2.news.blueyonder.co.uk. .. At the risk of being told "If it ain't broke, don't fix it", my code works, but is ugly.
Part of the admin site I'm working on at the moment includes a facility for users to enter Formulations (recipes for making cosmetics etc) in 3 stages: Stage 1: basic info such as title, method etc and number of Phases (steps
in recipe). Stage 2: dynamically generated form containing the exact number of phases as textboxes, depending on the number entered in stage 1. Phases are labelled A, B, C...etc. They rarely exceed 8 in total. In each text box, the user enters the number of ingredients per phase. Stage 3: dynamically generated form offering the correct number of text boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the phase they belong to. Of course, if there is more than one ingredients per phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients: if len(Request.Form("IngredientsA"))>0 then ....process the data end if if len(Request.Form("IngredientsB"))>0 then ....process the data end if if len(Request.Form("IngredientsC"))>0 then ....process the data up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a better way of iterating through these form fields than this. Coding to cater for up to 10 possible phases is repetitive, and is over 200 lines long. Elegant, it ain't! Anyone got any ideas?
http://aspfaq.com/show.asp?id=2036
Thanks for the response. It's obvious that I phrased my OP poorly.
This is an example of the code I'm currently processing:
productnames=Split(Request.Form("productnameA"),", ")
inciname=Split(Request.Form("incinameA"),",")
suppliername=Split(Request.Form("supplierA"),",")
volume=Split(Request.Form("volumeA"),",")
for i = 0 to Ubound(productnames)
sqlstuff= "INSERT INTO FormulationIngredients (FormulationID, Phase,
ProductName, INCIName, Supplier, Volume) VALUES ('" &
Request.Form("FormulationID") & "','A','" & Trim(productnames(i))&
"','" & Trim(inciname(i)) & "','" & Trim(suppliername(i)) & "','" &
Trim(volume(i)) & "');"
Response.write productnames(i) & ", " & inciname(i)& ", " &
suppliername(i)&", " & volume(i)& "<br>"
oConn.execute(sqlstuff)
next
Then I have to test for the presence of Request.Form("productnameB"),
the productnameC, then D, etc etc, copying and pasting the code each
time, but changing the last character in the form field names.
As I say, I've created code to cope with all eventualities up to J,
and there's no reason why I can't continue to Z. But is there a
better way of doing this?
TIA
P
Paxtonend wrote: "Chris Hohmann" <no****@thankyou.com> wrote in message news:<OQ**************@TK2MSFTNGP14.phx.gbl>... "Paxton" <paxtonend@[no-spam]hotmail.com> wrote in message news:M8****************@fe2.news.blueyonder.co.uk. .. At the risk of being told "If it ain't broke, don't fix it", my code works, but is ugly.
Part of the admin site I'm working on at the moment includes a facility for users to enter Formulations (recipes for making cosmetics etc) in 3 stages: Stage 1: basic info such as title, method etc and number of Phases (steps
in recipe). Stage 2: dynamically generated form containing the exact number of phases as textboxes, depending on the number entered in stage 1. Phases are labelled
A, B, C...etc. They rarely exceed 8 in total. In each text box, the user enters the number of ingredients per phase. Stage 3: dynamically generated form offering the correct number of text boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the phase they belong to. Of course, if there is more than one ingredients per phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients: if len(Request.Form("IngredientsA"))>0 then ....process the data end if if len(Request.Form("IngredientsB"))>0 then ....process the data end if if len(Request.Form("IngredientsC"))>0 then ....process the data up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a better way of iterating through these form fields than this. Coding to cater for up to 10 possible phases is repetitive, and is over 200 lines long. Elegant, it ain't! Anyone got any ideas?
http://aspfaq.com/show.asp?id=2036
Thanks for the response. It's obvious that I phrased my OP poorly. This is an example of the code I'm currently processing:
productnames=Split(Request.Form("productnameA"),", ") inciname=Split(Request.Form("incinameA"),",") suppliername=Split(Request.Form("supplierA"),",") volume=Split(Request.Form("volumeA"),",") for i = 0 to Ubound(productnames) sqlstuff= "INSERT INTO FormulationIngredients (FormulationID, Phase, ProductName, INCIName, Supplier, Volume) VALUES ('" & Request.Form("FormulationID") & "','A','" & Trim(productnames(i))& "','" & Trim(inciname(i)) & "','" & Trim(suppliername(i)) & "','" & Trim(volume(i)) & "');" Response.write productnames(i) & ", " & inciname(i)& ", " & suppliername(i)&", " & volume(i)& "<br>" oConn.execute(sqlstuff) next
Then I have to test for the presence of Request.Form("productnameB"), the productnameC, then D, etc etc, copying and pasting the code each time, but changing the last character in the form field names.
As I say, I've created code to cope with all eventualities up to J, and there's no reason why I can't continue to Z. But is there a better way of doing this?
TIA P
Why not a nested loop?
for i = 65 to 90
productnames=Split(Request.Form("productname" & chr(i)),",")
inciname=Split(Request.Form("inciname" & chr(i)),",")
...
for j = 0 to Ubound(productnames)
...
next
next
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] wrote: Paxtonend wrote:
"Chris Hohmann" <no****@thankyou.com> wrote in message news:<OQ**************@TK2MSFTNGP14.phx.gbl>.. .
"Paxton" <paxtonend@[no-spam]hotmail.com> wrote in message news:M8****************@fe2.news.blueyonder.co. uk...
At the risk of being told "If it ain't broke, don't fix it", my code
works,
but is ugly.
Part of the admin site I'm working on at the moment includes a facility
for
users to enter Formulations (recipes for making cosmetics etc) in 3
stages:
Stage 1: basic info such as title, method etc and number of Phases (steps
in
recipe). Stage 2: dynamically generated form containing the exact number of phases
as
textboxes, depending on the number entered in stage 1. Phases are
labelled
A, B, C...etc. They rarely exceed 8 in total. In each text box, the user enters the number of ingredients per phase. Stage 3: dynamically generated form offering the correct number of text boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the phase they belong to. Of course, if there is more than one ingredients
per
phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients: if len(Request.Form("IngredientsA"))>0 then ....process the data end if if len(Request.Form("IngredientsB"))>0 then ....process the data end if if len(Request.Form("IngredientsC"))>0 then ....process the data up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a
better
way of iterating through these form fields than this. Coding to cater for up to 10 possible phases is repetitive, and is over 200 lines long. Elegant, it ain't! Anyone got any ideas?
http://aspfaq.com/show.asp?id=2036
Thanks for the response. It's obvious that I phrased my OP poorly. This is an example of the code I'm currently processing:
productnames=Split(Request.Form("productnameA"), ",") inciname=Split(Request.Form("incinameA"),",") suppliername=Split(Request.Form("supplierA"),"," ) volume=Split(Request.Form("volumeA"),",") for i = 0 to Ubound(productnames) sqlstuff= "INSERT INTO FormulationIngredients (FormulationID, Phase, ProductName, INCIName, Supplier, Volume) VALUES ('" & Request.Form("FormulationID") & "','A','" & Trim(productnames(i))& "','" & Trim(inciname(i)) & "','" & Trim(suppliername(i)) & "','" & Trim(volume(i)) & "');" Response.write productnames(i) & ", " & inciname(i)& ", " & suppliername(i)&", " & volume(i)& "<br>" oConn.execute(sqlstuff) next
Then I have to test for the presence of Request.Form("productnameB"), the productnameC, then D, etc etc, copying and pasting the code each time, but changing the last character in the form field names.
As I say, I've created code to cope with all eventualities up to J, and there's no reason why I can't continue to Z. But is there a better way of doing this?
TIA P
Why not a nested loop?
for i = 65 to 90 productnames=Split(Request.Form("productname" & chr(i)),",") inciname=Split(Request.Form("inciname" & chr(i)),",") ... for j = 0 to Ubound(productnames) ... next next
Bob Barrows
Since I used that method to create the names of the form fields
(appending the letter to create the field names) in the first place, it
makes perfect sense to use it to unpick them again. Many thanks.
P This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Patrick von Harsdorf |
last post by:
I want to iterate over a collection and delete all unwanted entries.
for item in collection:
del item
of course doesn´t do anything useful. Two things come to mind:
a) iterating backwards...
|
by: Agoston Bejo |
last post by:
Hi.
x1.asp:
<form method="post" action="x2.asp"> .... </form>
x2.asp:
DoSomeAdministration()
Response.Redirect "x3.asp?" & Request.Form
x3.asp: further processsing of data
|
by: mvr |
last post by:
Hi all
IIS 5.0, ASP, and https://
I have "DataEntrypage.asp" which is a data entry page(about 250
data elements includes text boxes, radio buttons, check boxes, drop down
boxes etc).
...
|
by: Kathy Burke |
last post by:
Hi,
I have an html form (created by transforming an xml doc with an xsl
stylesheet and sent as html within an asp.net page.
The doc is a set of user instructions steps. For each
of the...
|
by: Kathy Burke |
last post by:
HI. in asp.net app, I have an xmlDocument that I transform to the client
html. Using xsl I create a few textboxes to capture user input. Each of
these are related to <data> elements in the xmlDoc....
|
by: John Buchmann |
last post by:
I thought this would not be difficult, but i'm stumped!
I need to iterate through a bunch of form fields, and
read the data (value, text, etc.) from them.
(I need to iterate through them...
|
by: ronaldlee |
last post by:
I have this error in Line 89.
Collection is read-only.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more...
|
by: ronaldlee |
last post by:
I got a collection read only error, below is the error message.
Collection is read-only.
Description: An unhandled exception occurred during the execution of
the current web request. Please...
|
by: David Veeneman |
last post by:
Is there a way to iterate the components on a form?
I need to determine whether an instance of my custom component (a
System.ComponentModel component) is present in a form. I have tried...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |