|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
When 'If' stops working ...
Hope someone can make sense of this on my behalf as I appear to have hit a wall.
Form such as this: <td><SELECT name="Project"> <OPTION VALUE=0>None Selected <% For i = 1 to numProjects If Not Project(i) = "" Then Response.Write ("<OPTION VALUE=") Response.Write (i) If i = cProject Then response.write( " SELECTED" ) End If Response.Write (">") Response.Write (Project(i) & vbCrLf ) End If 'Move to the next record in the recordset Next %></SELECT></td> where cProject = request.form("Project") is specified at the top. The problem is in the If statement as it never returns true, even though cProject will always contain a value that matches one of the array indices. I've changed the statement to IF i = 10 Then and If cProject = 10 Then and both work as expected but the statement just does not work when trying to compare these two values. Any advice? As a visiter from php scripting, is there something I need to know about asp form variables or data types? |
|
#2
|
||||
|
||||
|
Post more of your code and what you are attempting to do.
You are referencing objects (Project), but we don't know where or what those objects pertain to, so we can't really help you yet. |
|
#3
|
|||
|
|||
|
The code is intended to query a database based on user selections in a number of 'SELECT' statements.
After the DB has been queried, I want the page to display all the returned data but also set the select menus tot he values previously selected in case only one of them is to be changed before the next query. Additions to the earlier code are as follows: Above original snipet - dim numProjects strSQL = "SELECT TOP 1 ProjectID FROM tblProjects ORDER BY ProjectID DESC;" rsBilling.Open strSQL, adoCon numProjects = rsBilling("ProjectID") rsBilling.Close strSQL = "SELECT ProjectID, Project FROM tblProjects WHERE Active = -1 ORDER BY ProjectID ASC;" rsBilling.Open strSQL, adoCon dim Project() redim preserve Project(numProjects) Do While not rsBilling.EOF 'Work with info num = rsBilling("ProjectID") Project( num ) = rsBIlling("Project") rsBilling.MoveNext Loop rsBilling.Close How could something outside of i and cProject be effecting the If statement seeing as their actual values have not been effected? My thanks for any assistance and apologies for the lack of info to start with. |
|
#4
|
||||
|
||||
|
Your code still doesn't make sense.
And I have no idea why you are using an array. If you are filling the dropdown from the database and want a certain record selected based on a value passed you would do something like this Code:
cProject = Trim(CInt(Request.QueryString("Project")))
Response.write("<select name='Project'>")
do until rs.eof
If IsNull(cProject) OR Len(cProject) = 0 Then
Response.write("<option value=" & rs("ProjectValue") & ">" & rs("ProjectName") & "</option">
Else
If cProject = Trim(CInt(rs("ProjectValue"))) Then
Response.write("<option value=" & rs("ProjectValue") & " Selected>" & rs("ProjectName") & "</option>")
Else
Response.write("<option value=" & rs("ProjectValue") & ">" & rs("ProjectName") & "</option">
End If
End If
rs.movenext
loop
Response.write("</select>")
|
|
#5
|
|||
|
|||
|
Thanks for your help Memnoch.
Page is working just as it's supposed to now. The line: Trim(CInt()) was the clincher. I'd actually been trying to find stuff on casting but had little success. Again, my thanks for your help, it is much appreciated. |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > When 'If' stops working ... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|