|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP If Then Statement Question
I'm trying to get this If Then Statement to work:
Code:
Dim Movie_Link_Statement If Movie_Link = "DNE" Then Movie_Link_Statement="<li>asdf</li>" Else Movie_Link_Statement="<li><a href=""" & Movie_Link & """>Watch the " & Product_Name & "Movie</a></li>" End If Basically, the variable Movie_Link has been retrieved from a database. If there is a Movie_Link, it is in the form of a regular web address; if not, it is entered into the database as "DNE" (does not exist). If there is a link, the variable Movie_Link_Statement will display the properly formatted link in the html of my page; if not, there will be nothing displayed. In theory, it would work fine, but for some reason, the if statement is ignored, and only the else statement is applied. Any ideas? |
|
#2
|
|||
|
|||
|
I think this might work!
Code:
If Movie_Link = "DNE" Then Movie_Link_Statement="<li>asdf</li>" Else Movie_Link_Statement="<li><a href='" & Movie_Link & "'>Watch the " & Product_Name & " Movie</a></li>" End If I hope this works! |
|
#3
|
||||
|
||||
|
If Banksie's solution doesn't work, try this. I sometimes find that when an If/Then statement doesn't work the way it should, reversing it usually does the trick.
Code:
If Movie_Link <> "DNE" Then Movie_Link_Statement="<li><a href='" & Movie_Link & "'>Watch the " & Product_Name & " Movie</a></li>" Else Movie_Link_Statement="<li>asdf</li>" End If |
|
#4
|
||||
|
||||
|
syntactically your url is good...unless you want to change to banksie example for whatever reason...
have you actually checked the value of the variable Movie_Link? (Debug)...as you may have guessed, it has to be literally a capitalized DPE...no variations of unless you use UCase...yo can also apply a quick debugging technique by hard coding the values - to make sure your actual logic is correct Code:
<%
' replace w/ your table/field names
Movie_Link = oRs("Movie_Link")
Product_Name = oRs("Product_Name")
' debug
Response.write "The value of 'Movie_Link' variable is: " & Movie_Link
Response.End
If Movie_Link = "DNE" Then
Movie_Link_Statement="<li>asdf</li>"
Else
Movie_Link_Statement="<li><a href=""" & Movie_Link & """>Watch the " & Product_Name & "Movie</a></li>"
End If
response.write Movie_Link_Statement
%>
__________________
Please give respect to those that helped solve an issue by clicking on the reputation icon
|
|
#5
|
|||||
|
|||||
|
Hmm, thanks for the suggestions, but they don't seem to be helping. I tried to isolate the problem by removing the link if Product_Link = anything but DNE and simplifying the code.
asp Code:
When I set Movie_Link to "DNE" (exactly, all caps), the output is: DNE This Does Exist When I set the Movie_Link to "googlec.om", the output is: googlec.om This Does Exist Any ideas? |
|
#6
|
||||
|
||||
|
Did you debug as per K_I_S's example?
I must admit that I disagree with the suggestion of reversing the If/End If because it means that everything by default will Exist if it doesnt equal DNE, which is not what you want. Try using CStr and Trim: Code:
Dim Movie_Link_Statement If Trim(UCase(CStr(Movie_Link))) = "DNE" Then Movie_Link_Statement="<li>asdf</li>" Else Movie_Link_Statement="<li><a href=""" & Movie_Link & """>Watch the " & Product_Name & "Movie</a></li>" End If |
|
#7
|
|||
|
|||
|
Thank you so much, adding the CStr and Trim made it work like a charm!
|
|
#8
|
||||
|
||||
|
Quote:
You're welcome, glad it helped!!! |
|
#9
|
||||
|
||||
|
...sounds like it's a manually entered value from a form then inserted into a database... if this is the case then you should check values BEFORE you insert into the database...(client side and/or server side validation) - this would have more than likely prevented this problem
good call sos ![]() |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > ASP If Then Statement Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|