473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Conditional in Loop not working

I am building an application for keeping track of user permissions here at
work. I have built the interfaces, and am now working on the processing
page for inserting to the database. I am having a problem with a
conditional in my loop not working correctly, I am sure that I have been
overlooking something, but cannot pin it down.
I have pared the code down quite a bit just so that I could resolve my
issues with it. I have a page named addAIMR.asp that has about 34
checkboxes, 2 dropdowns and 2 textboxes. I am trying to something like
this,

If checkbox is checked
AccessOption1 = 1 (which is the access option number)
Else
AccessOption1 = 0
End If

Then I am trying to loop through the code to insert only the ones that <> 0.
This should be rather straight forward, but I am running into issues... I
have inserted many Response.Write's throughout the code to see the
variables, and everything looks kosher, until it gets to the loop, then it
shows that it would insert all the records.

Here is my code for processAIMR.asp,

<%
Dim AIMRDate
Dim AuthName
Dim EmpID
Dim Comments

AIMRDate = Request.Form("Date")
AuthName = Request.Form("AuthName")
EmpID = Request.Form("EmpID")
Comments = Request.Form("Comments")

Dim AccessOption1
Dim AccessOption2
Dim AccessOption3
Dim AccessOption4
Dim AccessOption5

If Request.Form("chkStandard") = "1" Then
Response.Write("1 = Checked<br>")
AccessOption1 = "1"
Else
Response.Write("1 = Not Checked<br>")
AccessOption1 = "0"
End If
If Request.Form("chkEmail") = "1" Then
Response.Write("2 = Checked<br>")
AccessOption2 = "2"
Else
Response.Write("2 = Not Checked<br>")
AccessOption2 = "0"
End If
If Request.Form("chkVPN") = "1" Then
Response.Write("3 = Checked<br>")
AccessOption3 = "3"
Else
Response.Write("3 = Not Checked<br>")
AccessOption3 = "0"
End If
If Request.Form("chkOtherNetwork") = "1" Then
Response.Write("4 = Checked<br>")
AccessOption4 = "4"
Else
Response.Write("4 = Not Checked<br>")
AccessOption4 = "0"
End If
If Request.Form("chkPRAIS") = "1" Then
Response.Write("5 = Checked<br>")
AccessOption5 = "5"
Else
Response.Write("5 = Not Checked<br>")
AccessOption5 = "0"
End If

For i = 1 to 5
If (AccessOption & i) <> "0" Then
Response.Write("AccessOption" & i & " is not empty, therefore will be
inserted<br>")
'Insert 1 record for each option checked
Else
Response.Write("AccessOption" & i & " is empty, therefore will NOT be
inserted<br>")
End If
Next
%>

If I check 2 boxes, chkStandard and chkVPN, then I get the following written
to the page,

1 = Checked
2 = Not Checked
3 = Checked
4 = Not Checked
5 = Not Checked
AccessOption1 is not empty, therefore will be inserted
AccessOption2 is not empty, therefore will be inserted
AccessOption3 is not empty, therefore will be inserted
AccessOption4 is not empty, therefore will be inserted
AccessOption5 is not empty, therefore will be inserted

Can anyone spot where I am going awry?

TIA,
Drew
Nov 7 '05 #1
8 1656
Drew wrote on 07 nov 2005 in microsoft.public.inetserver.asp.general:
AccessOption5 = "0"
End If

For i = 1 to 5
If (AccessOption & i) <> "0" Then


You cannot do this:

(AccessOption & i)
This does not make a variable name in ASP-VBS

Use an array:

dim AccessOption()

AccessOption(5) = "0"
i=5
If AccessOption(i) <> "0" Then
....

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 7 '05 #2
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242...
Drew wrote on 07 nov 2005 in microsoft.public.inetserver.asp.general:
AccessOption5 = "0"
End If

For i = 1 to 5
If (AccessOption & i) <> "0" Then


You cannot do this:

(AccessOption & i)
This does not make a variable name in ASP-VBS


But this does:

If Eval("AccessOption" & i) <> "0" Then
Nov 7 '05 #3
McKirahan wrote:
This does not make a variable name in ASP-VBS


But this does:

If Eval("AccessOption" & i) <> "0" Then


Yeah, but Eval is evil :-)
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Nov 8 '05 #4
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
McKirahan wrote:
This does not make a variable name in ASP-VBS


But this does:

If Eval("AccessOption" & i) <> "0" Then


Yeah, but Eval is evil :-)


Why?

I understand that it is deprecated in JavaScript
but this is VBScript and it solves his problem.
Nov 8 '05 #5
Really overkill here. There is no point using Eval when you can use arrays
instead for both execution efficiency and clarity...

--
Patrice

"McKirahan" <Ne**@McKirahan.com> a écrit dans le message de
news:L4********************@comcast.com...
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
McKirahan wrote:
> This does not make a variable name in ASP-VBS

But this does:

If Eval("AccessOption" & i) <> "0" Then


Yeah, but Eval is evil :-)


Why?

I understand that it is deprecated in JavaScript
but this is VBScript and it solves his problem.

Nov 8 '05 #6
McKirahan wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
McKirahan wrote:
This does not make a variable name in ASP-VBS

But this does:

If Eval("AccessOption" & i) <> "0" Then


Yeah, but Eval is evil :-)


Why?


Mainly, because it starts another compiler. Instead of a single compiler
being applied to your code, you now have two compliers being spawned to,
well, compile the code. See:
http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx

Eval has its places, but its use should be considered as an absolute last
resort. In this case, there is a much better solution available (the array),
so eval should not be considered.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Nov 8 '05 #7
Bob Barrows [MVP] wrote:
McKirahan wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
McKirahan wrote:

> This does not make a variable name in ASP-VBS

But this does:

If Eval("AccessOption" & i) <> "0" Then

Yeah, but Eval is evil :-)


Why?


Mainly, because it starts another compiler. Instead of a single
compiler being applied to your code, you now have two compliers being
spawned to, well, compile the code. See:
http://blogs.msdn.com/ericlippert/ar.../01/53329.aspx

Oh! and don't forget to look at Part 2:
http://blogs.msdn.com/ericlippert/ar.../04/53335.aspx

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Nov 8 '05 #8
Thanks for all the replies... I ended up using the array method.

Thanks,
Drew
Nov 9 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
8
by: Guy Hocking | last post by:
Hi there, I am having a few problems compiling a list box that is conditional on what is selected in another list box. What i need is a List box (lstArea) that displays one thing when the List...
8
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
1
by: Klauer | last post by:
Hello all, I'm kind of new to working with C++, and I have an issue in solving an issue that maybe someone out here can help me with. I have a piece of code in this project that I'm tasked to...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
8
jschrader
by: jschrader | last post by:
I am trying to write a conditional Statement in ASP based on dates/times in a database entry. I'm basically a ASP/web designer and try my best to get into the fun coding, so not sure as to the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.