Friday, June 1, 2007

Pass variables by reference in ASP

Ah! Passing variables by reference. One of those interesting nuggets not often adequately explained by textbooks or professors. Obviously, it is possible with VB.NET and VB 6 when the keyword "ByRef" is used to qualify a parameter.

Remember that incoherent explanation regarding "stacks" and "heaps"? Well, neither do I.

I had to figure it out on my own. I imagine it this way. Let's assume we're going to a department store. When we enter, we check in our bags. The kind person at the counter then hands us a ticket number corresponding to the compartment where our bags are placed. The ticket is a "reference" to our bags and the square compartment can be likened to "memory".

If we were to lose our "reference" to our bags, i.e., lose our ticket, the kind person at the counter, overcome by a sense of glee, would keep our bags for himself.

When we return the ticket, the kind person at the counter looks for a compartment that matches the label on the ticket and returns our bags (Hopefully with everything still in it)

In any event, here's my solution:

<%

Dim var1, var2

MyRoutine var1, var2

Response.Write ("Values are : " & var1 & " and " & var2)

%>

<%

Sub MyRoutine(v1, v2)

v1 = "Variable 1"

v2 = "Variable 2"

End Sub

%>


Refer your friends to this blog:
http://programmingcentral.blogspot.com/

No comments: