Freexel
Freexel

Reputation: 53

Create (file) string with classic asp VBScript

In .net (C#) I use this to create a multiple file(name) string.

if (pic == null)
   pic += "filename";
          else
   pic += "~" + "filename";

I'm unfamiliar with ASP.Classic VBScript. Can someone help me with syntax in ASP.Classic VBScript?

Upvotes: 1

Views: 709

Answers (3)

Shadow Wizard
Shadow Wizard

Reputation: 66388

Rico answer is correct as far as syntax is involved, however classic ASP does not recognize the ~ character as the web application root - this is new "feature" of ASP.NET that has no direct equivalent in classic ASP.

One way to get the root is using such function:

Function GetApplicationRoot()
    Dim pathinfo, myRegExp
    pathinfo = Request.ServerVariables("PATH_INFO")
    Set myRegExp = New RegExp
    myRegExp.IgnoreCase = True
    myRegExp.Global = True
    myRegExp.Pattern = "^(/\w*/).*" 
    GetApplicationRoot = myRegExp.Replace(pathinfo, "$1")
End Function

The above is based on the code found in this question.

Having this, the complete answer will be:

If Len(pic)=0 Then
    pic = "filename"
Else  
    pic = pic & GetApplicationRoot() & "filename"
End If

Note that in VBScript, only empty database value will return Null all other strings will just be empty, meaning zero length.

In case pic is coming from database, change the code to:

blnNullOrEmpty = False
If IsNull(pic) Then
    blnNullOrEmpty = True
Else  
    If Len(pic)=0 Then
        blnNullOrEmpty = True
    End If
End If

If blnNullOrEmpty Then
    pic = "filename"
Else  
    pic = pic & GetApplicationRoot() & "filename"
End If

Upvotes: 1

Erik Oosterwaal
Erik Oosterwaal

Reputation: 4374

Maybe this is what you want?

if pic = "" then
    pic = pic & "filename"
else
    pic = pic & "~" & "filename"
end if

Erik

Upvotes: 4

Greg.Slagell
Greg.Slagell

Reputation: 11

You could do it like this.

If IsNull(pik) Then
   pik = pik & "filename"
Else
   pik = pik & "~" & "filename"
End If

Upvotes: 1

Related Questions