Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dimming A Variable

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
Consider the following SQL query:

<%
strSQL1=&quot;SELECT ECode,EName,
(SELECT SUM(HRA) FROM ADET......) AS HRATotal,
(SELECT SUM(CCA) FROM ADET......) AS CCATotal
FROM..............................
%>

So can I declare a variable like this:

<%
Do Until(objRS.EOF)
For iCol=2 To objRS.Fields.Count-1
Dim i & objRS(iCol).Name
........................
........................
Next
objRS.MoveNext
Loop
%>

Using 'Dim i & objRS(iCol).Name', I want to declare two variables iHRATotal & iCCATotal. Can a variable be Dimmed in this way? Actually though I have shown the alias column names as HRATotal & CCATotal in the SQL query, in reality, the alias column names are getting assigned dynamically. That's precisely the reason why I am using For....Next loop.

Thanks,

Arpan
 
You cannot dynamically dim a value. I have tried. Try dimming the lights or declaring all variables before you start.
 
How about doing it like this?

<%
Do Until(objRS.EOF)
For iCol=2 To objRS.Fields.Count-1
ReDim i(objRS(iCol).Name)
.........................
.........................
Next
objRS.MoveNext
Loop
%>

I tried it out but it threw the following error:

'Type Mismatch: '[string: &quot;HRATotal&quot;]'

pointing to the line where I am ReDimming the variable. Any other suggestions??????

Thanks,

Regards,

Arpan
 
maybe try to create an array and stick your values in the array (1 or 2D). that way you can add as many or as few variables as you need.

Kris
 
How do I create the array?

Arpan
 
Do you really have to Dim it?

i know that seems like a stupid question but it is not an absolute requirement that a variable be dimmed.

any thoughts on this?
 
yup , U have to since what U want is an array variable , not a usual one.
well, it's not that hard to add only 1 line of your codes, isn't it ??

:eek:)*JJ26*:eek:)
 
Hi SerialCoder,

What you have suggested in OK but I guess you are not aware of the fact that declared variables are accessed faster than undeclared ones. Visit the following URL to read an article on declaring a variable:


Since the entire page is a big one, you might have problems in searching this particular topic. So what you can do is press Ctrl-F, type in OPTION EXPLICIT & then hit Enter. You will understand the positive aspect of dimming a variable.

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top