Search code examples
asp-classic

How to convert string variable to int and vice versa in CLASSIC ASP


I am new to classic asp.

    MaxLnkApp=rsTemp("Info")

    MaxLnkAppCount=rsTemp("Count")

    if MaxLnkApp=MaxLnkAppCount then
          averageNum = 0
    end if

rsTemp("Count") is int and rsTemp("Info") is string

Even when the condition is not (like both variables equals five) satisfied.

How to convert string to integer? or Integer to string?


Solution

  • Good question, as in classic ASP everything is a variant type.

    Assuming that both rsTemp("Info") and rsTemp("Count") cannot contain NULL values (returned from the database) you can either use CStr (convert to string)

    if CStr(MaxLnkApp) = CStr(MaxLnkAppCount) then
    

    Or CLng (convert to long integer)

    if CLng(MaxLnkApp) = CLng(MaxLnkAppCount) then
    

    CLng is advised in this case (instead of CInt) because a SQL Server data type of INT is actually a long integer.