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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
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
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
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

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
Big MontyWeb Ninja at largeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 MontyWeb Ninja at largeCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.