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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF statement inside loop

Status
Not open for further replies.

larryman

Programmer
Jun 16, 2000
63
0
0
US
Hi guys,

I have an IF statement that is not executing properly inside a FOR Next loop. This if statement executes once and doesn't execute again even when the conditions are satisfied.

Below is the code

<% @Language="VBScript"%>
<%
Option Explicit
'declare all local variables

dim dcnDB, strSQL, rsData, i, Kount 'As ADO.Connection
dim arrSomething, strNTUser
'Create the Connection Object
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
& "Data Source=f:\Aspdatabase\Database\telecoms.mdb"
dcnDB.Open



arrSomething = split(Request.Form("Ans"), ",")
strNTUser = arrSomething(1)

Kount = 0

For i = 0 to 10


If Request.Form("Q"&i&"") = arrSomething(i) Then

Kount = Kount + 1


End if
Next

%>

I need your help

Larryman

Oysterbar ride to success. Keep Riding
 
all depends on the values of your ans collection and our Q#'s

[thumbsup2]DreX
aKa - Robert
 
Trying add a print satemnt inside your loop and print the two values out in parans or something (the parans are to tell if there are trailing spaces or anything). That may help you (or us) find the problem.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Many thanks Tarwn and DreXor, i got this fixed by this code,

<% @Language="VBScript"%>
<%
Option Explicit
'declare all local variables

dim dcnDB, strSQL, rsData, i, Kount 'As ADO.Connection
dim arrSomething, strNTUser, DataValue, Formvalue
'Create the Connection Object
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
& "Data Source=f:\Aspdatabase\Database\telecoms.mdb"
dcnDB.Open



arrSomething = split(Request.Form("Ans"), ",")



Kount = 0

For i = 0 to 10

DataValue = Request.Form("Q"&i&"")
FormValue = TRIM(arrsomething(i))

If DataValue = FormValue Then
Response.Write "I am inside loop"

Kount = Kount + 1


End if

Next

Response.Write Kount

But my question is can't one do a simple comaprison(condition stm) without writing to a variable like i did because even when i was trimming the spaces it didn't work until i started putting the values in the variables and then comparing the variables.

Anyway. Grateful for ur responses.

Larryman

Oysterbar ride to success. Keep Riding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top