-1

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ReaL_HyDRA
  • 314
  • 1
  • 18
  • Does your recordset fields contain any data? Just use `MaxLnkApp=rsTemp("Info") & ""` to assume an empty string if null. – user692942 Jan 15 '20 at 09:15

1 Answers1

1

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.

Thailo
  • 1,314
  • 7
  • 13
  • `Wrong number of validations or invalid property assignments: 'CStr'` This error is showing. Same problem with CLng – ReaL_HyDRA Jan 15 '20 at 08:44
  • Then you should pinpoint what MaxLnkApp and MaxLnkAppCount contain just before the error occurs. This might help you decide how to handle the then expected error. As I said, my answer is based on the assumption that the returned values are not empty. – Thailo Jan 15 '20 at 08:55
  • Should be using `IsNumeric()` to check the variable contains a valid numeric value before using `CInt()`, `Clng()` or `CDbl()`. – user692942 Jan 15 '20 at 09:14
  • Apologies, but I disagree this is a good question. Classic ASP has been around 20+ years and you think that asking how to convert strings to numbers hasn't been touched on already? If not Classic ASP it definitely has in VBScript. The correct course of action would be to vote to close as a duplicate. – user692942 Jan 15 '20 at 09:23
  • 1
    @Lankymart I agree with your sentiment but I think we shouldn't be to rigid with newcomers. I also agree with your IsNumeric() suggestion, but is from the same cloth as checking for possible empty/null values. – Thailo Jan 15 '20 at 10:32