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!

how to create dynamic variables on the server(?).... 1

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hello all,


Question:

How can I create an unknown amount of variables when the page is being processed...to be determined by the amount of records pulled from the database?
[/color]


Problem:

I'm making a drop down menu dynamically from the records on a *.dbf file. I can pull them no problem and add every record in the dropdown select as the page processes, however, certain choices are listed several times. For example, I want it so the user can search for on of the manufacturer's for a product I.E. Intel, Microsoft, etc. But I don't want each thing listed 20 times, I figured if I can figure out how to create another variable each time a new record is found by compareing it to the other variables created, then it will list each thing only once. If anyone can help me....I'd really really appreciate it!!! Thank you!


Here is just a small bit of my select statement

response.write(&quot;<SELECT NAME='Printer' id='select'>&quot;)
response.write(&quot;<OPTION value=''>List Everything</OPTION>&quot;)
Dim i
i = 0
Do While not rs3.eof
i = i + 1
dim item(i)
item(i) = rs3(&quot;Manufact&quot;)
response.write(&quot;<OPTION VALUE='&quot; & item(i) & &quot;'>&quot; & item(i) & &quot;</OPTION>&quot;)
Loop
Response.Write(&quot;</SELECT>&quot;)


Hope this makes sense! Thanks again!
 
Code:
Dim i
Dim j
Dim item
Dim strManufact
    i = 0
    redim item(0)
    Do While not rs3.eof
        strManufact = rs3(&quot;Manufact&quot;)
        Do
            For J = 1 to I
                if strManufact = item(J) then exit do
            next
            i = i + 1
            if I > Ubound(item) then
                Redim Preserve item(2*i)
            end if 
            item(i) = strManufact
            response.write(&quot;<OPTION VALUE='&quot; & strManufact & &quot;'>&quot; & item(i) & &quot;</OPTION>&quot;)
          loop
    Loop
 
I pressed Submit instead of edit. Change the nested Loop to
Exit Do: loop
I am using the inside DO as a block, not as a DO.
Code:
Dim i
Dim j
Dim item
Dim strManufact
    i = 0
    redim item(0)
    Do While not rs3.eof
        strManufact = rs3(&quot;Manufact&quot;)
        Do
            For J = 1 to I
                if strManufact = item(J) then exit do
            next
            i = i + 1
            if I > Ubound(item) then
                Redim Preserve item(2*i)
            end if 
            item(i) = strManufact
            response.write(&quot;<OPTION VALUE='&quot; & strManufact & &quot;'>&quot; & item(i) & &quot;</OPTION>&quot;)
        Exit Do: loop
    Loop
[code] [URL unfurl="true"]WWW.VBCompare.Com[/URL]
 
Thank you for your quick response!

I tried the code you gave me, now the page doesn't load...almost like it was in an endless loop, keeps trying to load, but never gets there. You can see what I'm talking about at
Know what might be causeing that? I tried to use a for loop earlier, and it seamed to be doing the same thing. Does the same on my I.E. 5.5 as it does on NS6 Browsers.

-Ovatvvon
 
Off the top of my head........
Dim FlagNew
Dim J
Dim Item()
With rs3
If Not .EOF then
ReDim Item(0)
Item(0) = .Manufact.Value
.MoveNext
Do Until .EOF
FlagNew = True
For J = 0 To Ubound(Item)
If .Manufact.Value = Item(J) Then
FlagNew = False
Exit For
End If
Next
If FlagNew Then
ReDim Preserve Item(Ubound(Item) + 1)
Item(Ubound(Item)) = .Manufact.Value
response.write &quot;<OPTION VALUE='&quot; & item(Ubound(Item)) & &quot;'>&quot; & item(Ubound(Item)) & &quot;</OPTION>&quot;
End If
.MoveNext
Loop
End If
End With
 
P.S.
I'm not familliar with a .dbf file, but the BEST way to accomplish what you are doing here is to &quot;filter&quot; your rs.
If your using sql it might look something like this:
&quot;Select DISTINCT FieldA From MyTable&quot;. So if FieldA has &quot;Green&quot; listed 456 times in the table, the DISTINCT will return &quot;Green&quot; only once. There's several other ways to &quot;filter&quot; the rs, including Group By and Where statements, etc.
 
Tim Larkin,
Your last message for Distinct works perfectly.
Thank you!!

-Ovatvvon
-Biloxi to Cherry Point
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top