A
Arpan De
Suppose I have the following ASP code:
<%
Dim strName
.....................
.....................
.....................
.....................
.....................
.....................
Dim strName
%>
The above code will throw an error saying Name redefined pointing to the second Dim strName. That's OK but why isn't the same
error thrown in the following case?
<%
Dim objConn
Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString
Dim strSQL
strSQL="SELECT....FROM....WHERE....ORDER BY...."
Dim objRS
Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn
Do Until(objRS.EOF)
Dim strName
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>
In the 2nd code snippet, the variable strName is Dim(med) for the 1st DB record. When the cursor comes to the 2nd record, again
strName is Dim(med). strName is yet again Dim(med) when the cursor comes to the 3rd record so on & so forth. So why isn't the Name
redefined error being thrown here? Isn't the variable strName getting Dim(med) here more than once in the same way as the variable
strName is Dim(med) more than once in the 1st code snippet? Is the variable strName destroyed & recreated after each record in the
2nd code snippet?
Thanks,
Arpan
<%
Dim strName
.....................
.....................
.....................
.....................
.....................
.....................
Dim strName
%>
The above code will throw an error saying Name redefined pointing to the second Dim strName. That's OK but why isn't the same
error thrown in the following case?
<%
Dim objConn
Set objConn=CreateObject("ADODB.CONNECTION")
'ConnectionString
Dim strSQL
strSQL="SELECT....FROM....WHERE....ORDER BY...."
Dim objRS
Set objRS=CreateObject("ADODB.RECORDSET")
objRS.Open strSQL,objConn
Do Until(objRS.EOF)
Dim strName
strName=objRS("Name")
..........................
..........................
..........................
..........................
..........................
objRS.MoveNext
Loop
%>
In the 2nd code snippet, the variable strName is Dim(med) for the 1st DB record. When the cursor comes to the 2nd record, again
strName is Dim(med). strName is yet again Dim(med) when the cursor comes to the 3rd record so on & so forth. So why isn't the Name
redefined error being thrown here? Isn't the variable strName getting Dim(med) here more than once in the same way as the variable
strName is Dim(med) more than once in the 1st code snippet? Is the variable strName destroyed & recreated after each record in the
2nd code snippet?
Thanks,
Arpan