Question

I have a function which sets a variable for the current user. The variable name is prefixed with the name of the module - basically, the way the application is set up, Client is a class, Server is a class, Agency is a class and so on. This is an attempt to create a system whereby we can find out any key information about a client or one of their websites, across over 200 servers, with as few clicks as possible and using live data from their DB.

The function is as follows:

public sub setVariable(varName, varValue)
    varValue = cstr(varValue)
    def = ""
    if varValue = "" then def = "1"
    response.write vbcrlf & "Variable: " & varName & " : " & varValue & vbcrlf
    if not cstr("" & getVariable(varName, def)) = cstr("" & varValue) then
        response.write vbcrlf & varName & " : " & varValue & vbcrlf
        prepend varName, "Module." & Name & "."
        response.write vbcrlf & varName & " : " & varValue & vbcrlf
        session(varName) = varValue
        Core.RunSproc "SetUserVariable", array("@name", "@value"), array(varName, cstr(varValue)), setVar
    end if
end sub

Now on line 5, where it is first output, only "ID" is output as the variable name. However 2 lines later the name is set to "Module.<module-name>.ID" (for example Module.Server.ID. 2 lines after that, after the prepend statement (which acts the same as doing varName = "something" & varName), it outputs the something + "Module.<module-name>.ID". In effect, in this case, it outputs "Module.Server.Module.Server.ID". Note that if I take anything out, it is taken out of the first Module.Server but not the 2nd. Does anyone have any idea what is causing this? It seems as though Module.Server is being prepended to the variable name between lines 5 & 7, but the only line there is an if statement. Thanks in advance.

Was it helpful?

Solution

Seems I have found the answer. It's the fact that ASP automatically assumes variables input into functions are byref. Thus, when calling getVariable, I was actually prepending "Module.Server." there too, and because it was byref the variable maintained the value.

Regards, Clarkey

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top