How use var to call popupmenu addrows

Hi everybody
How can i use a var to populate (addrows to different popupmenu)
i’v try to use the element of array directly… “str(idz(0)” doesn’t work
i’v try to put in var… “newdrop = str(idz(0))” doesn’t work neither so i need help

[code]Dim theScriptResult As String
Dim theScriptResultfull() As String
Dim newdrop As String
Dim idz() As String
idz = Array(“customer”, “stationerytype”)

For i As Integer = 0 To Ubound(idz)
theScriptResult =GetForm5var(idz(i))

theScriptResult=theScriptResult.replaceAll( "'","''")
theScriptResultfull=Split(theScriptResult,",")
newdrop = str(idz(0))

newdrop.addrows (theScriptResultfull) --- Error this item does not exist

Next[/code]
thanks

You have declared “newdrop” as a string and then tried to use…

newdrop.addrows

No such method exists. Use the popupmenu control to add rows.

popUpMenu1.addrow myString

i know i have to call the popupmenu name
i’v already create popupmenu call “customer”, “stationerytype”
i want to populate these popupmenu, whos name are in an array name idz()
in this example i pass each array item in a var newdrop to addrows in a loop
both ways doesn’t work

It seems you trying to add rows to popupmenus whose names are in an array. This cannot be done by using the value of a string like it appears you are trying to do. It must be done with conditionals to determine which popupmenu should have the rows added.

Do something like this instead to specify the correct popupmenu:

<snip>
newdrop = str(idz(0))

if newdrop = "customer" then
  customer.addrows theScriptResultfull
elseif newdrop = "stationerytype" then
  stationerytype.addrows theScriptResultfull
end if

next

because the big amount of popupmenu
the idea is to pass all the name in array and throw them one by one in a loop
it must have a way to convert my array string to match object (popupmenu name)
i dont want to do conditional 30 name of popumenu
i doesnt seem a good (programmiong technique)

You will need to use a dictionary then. Here is a sample project that demonstrates this.

Or use a method that scans the controls on the window for a popupmenu with that name.

Function popup(name as string) as popupmenu
   for i as integer = 0 to ControlCount-1
      if Control(i) IsA PopupMenu and PopupMenu(Control(i)).Name = name then
         return PopupMenu(Control(i))
      end
   next
End Function

Call it like

popup(idz(i)).addrows (theScriptResultfull)

Work perfectly !!!
I knew there was a (elegant) way to do it
Thanks you Tim