1

Im doing a page in .asp and im having this problem ... I have some variable constants

MENU_01="FICHEROS"
MENU_02="OPTIONS"
MENU_03="USERS"

etc ... what I need to do its a cicle where I can print each variable value by refering it by string ...

Dim i
    For i=1 to CANTMENUS 

    Response.Write "<li>"& MENU_0 & i; & "</li>"

    Next 

Something like that (obviously that do not work) I know the variable name start in MENU_0 and I want dinamicly add the next value to the variable name (the "i" value)

Its this posible to do ??

thanks for all.

2 Answers 2

3

Can be done with Response.Write "<li>"& Eval("MENU_0" & i) & "</li>" but using eval is not recommended because of it's not a reliable method.
I'd suggest the use of dictionary object.

Set MENU = Server.CreateObject("Scripting.Dictionary")
    MENU.Add "01", "FICHEROS"
    MENU.Add "02", "OPTIONS"
    MENU.Add "03", "USERS"

For Each Item In MENU.Items
    Response.Write "<li>" & Item & "</li>"
Next

Another option is using arrays.

Sign up to request clarification or add additional context in comments.

Comments

1

In fact I found a way to do this without a set or array! By using eval() func

eval("MENU_"&MENUNUMBER)

MENUNUMBER its the iteration variable and the variables with the values I want are MENU_01 MENU_02 MENU_03 etc ... and with eval("MENU_01") I get the value I need!

Thanks for all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.