Can I do inline coding for if-then-else?

HI,
How can I add inline coding for classic asp to conditional format/concatenate a string?  What would the code syntax like if that's possible?  Classic asp doesn't have code behind capability?

Thank you.
lapuccaAsked:
Who is Participating?
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
ok, I understand more what you're trying to do, essentially build out your html based off of an IF statement. try the following code:

<%
	if InStr( rsForms("fileLocation"), "http" ) > 0 then             '-- if rsForms contains http in the fileLocation field
%>
	<a href=<%=rsForms("FileLocation") %>" class="TextLinks"><%=rsForms("FormName") %></a>
	
<% else %>
	<a href="http://OurOrg.net/somefolder/somepath/<%=rsForms("FileLocation") %>" class="TextLinks">		
<%=rsForms("FormName") %></a>
<%end if %>

Open in new window


more info on the InStr() function - http://www.w3schools.com/vbscript/func_instr.asp

** edited to better format code
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Something like this:

Sql = "select * from table"
If aVar = 1 then
   Sql = sql &  " where aField = 1"
End if
0
 
dsackerContract ERP Admin/ConsultantCommented:
With good structure you can achieve code-behind with ASP. For instance, if I have the following file called main.asp:
<!--#include file="main_codebehind.asp"-->
<html>
<head>
  <title>Main Screen</title>
  <link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<h4>Main Screen -  <%=Now()%></h4>
<% Call MainProcess %>
</body>
</html>

Open in new window

And I have another file called main_codebehind.asp, which (if you noticed) I included at the top of the above main.asp:
<%
Sub Who
    Const adCmdText = 1
    Const adCmdTable = 2
    Const adLockOptimistic = 3
    Const adOpenDynamic = 2

    Dim col
    Dim ndx   
    Dim objConn
    Dim objRS
    Dim strConn
    Dim strValue
    ' --------------------------------------------------------- '
    '   Connect to the database, and run the query.		'
    ' --------------------------------------------------------- '
    Set objConn = Server.CreateObject("ADODB.Connection")
    strConn = "Provider=sqloledb;Data Source=MyServerName;" & _
              "Initial Catalog=master;Integrated Security=SSPI;"
    objConn.Open strConn
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open "SELECT * FROM SomeTable", objConn

	If objRS.EOF = True Then
	    objRS.Close
	    Set objRS = Nothing
	    Set objConn = Nothing
		Exit Sub
	End If

	Response.Write("<table>" & vbCrLf)
	Response.Write("<tr><th>Field1</th><th>Field1</th><th>Field3</th><th>Field4</th></tr>" & vbCrLf)

	Do While objRS.EOF = False
		Response.Write("  <tr>")
		Response.Write("<td>" & objRS("Field1").Value & "</td>")
		Response.Write("<td>" & objRS("Field2").Value & "</td>")
		Response.Write("<td>" & objRS("Field3").Value & "</td>")

                ' Need to concatenate, or something special
                strValue = objRS("Field4").Value
                If objRS("Field5").Value <> "" Then
                    strValue = strValue & "-" & objRS("Field5").Value
                End If

		Response.Write("<td>" & strValue & "</td>")
		Response.Write("</tr>" & vbCrLf)
		objRS.MoveNext
	Loop

	Response.Write("</table>" & vbCrLf)
	
    objRS.Close
    Set objRS = Nothing
    Set objConn = Nothing
End Sub
%>

Open in new window

I have all the flexibility in my "code behind" to format, concatenate, etc.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
lapuccaAuthor Commented:
Can I use C# with that or only VB is allowed? But I think it's less work if I use inline after examining what I have..
I'm attaching the code snipet.  I need to have a if inline code that examine the "FileLocation", if it starts with http then skip the prefix of the url.  Appreciate your help on how to do that inline, thank you.
0
 
lapuccaAuthor Commented:
Here is the code snipet
fileapth.txt
0
 
lapuccaAuthor Commented:
I'm attaching a file that below the code snipet I put down what I need to do.  Appreciate help on properly doing it for classic asp inline coding syntax.
fileapth.txt
0
 
dsackerContract ERP Admin/ConsultantCommented:
I think you can simply substitute:

=rsForms("FileLocation")
For:

=Replace(rsForms("FileLocation"), "http://", "")
No harm done if it doesn't find it.
0
 
Steve BottomsSr Network AdminCommented:
I know this isn't a direct answer, but if you will be used IF/THEN/ELSE a lot you might want to consider building yourself an IIF (Immediate IF) function, and just call your own function and pass the appropriate parameters.  Always worked for me in the past.  Just a suggestion.  :)
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
dsacker, very nice code behind idea.

>Can I use C# with that or only VB is allowed?
You can't use either.  You can only use jscript or vbscript which is not the full VB.  jscript was an old port of javascript by microsoft to run js serverside.  It runs slower than vbscript so stick with vbs.  If you do a little searching, I have seen where you can access .net classes via asp.

Quick update to BM's code.  Last line, move end if below rsForms("FormName") and closeing asp tag
<%
	if InStr( rsForms("fileLocation"), "http" ) > 0 then             '-- if rsForms contains http in the fileLocation field
%>
	<a href=<%=rsForms("FileLocation") %>" class="TextLinks">
		<%=rsForms("FormName") %></a>
	
<% else %>

	<a href="http://OurOrg.net/somefolder/somepath/<%=rsForms("FileLocation") %>" class="TextLinks">
	<%=rsForms("FormName") %></a>
	
<%end if%>	

Open in new window

0
 
lapuccaAuthor Commented:
I can't just replace "http", I have to remove the prefix of internal url link, it's a complete different external link.

Scott's code is perfectly witha tI need(missing a double quote but I found and fixed it).  

Thanks everyone for your input.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
how is Scott's code different from mine? he posted 22 min after me, and I immediately did an edit on my code right after I posted to correct the closing end if placement, so.....
0
 
lapuccaAuthor Commented:
Big Monte,
My apology, your code is exactly the same and you're earlier.  I used Scott's as a typo, as you see I gave your the credit.


Thanks everyone.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.