Choosing webContainer

I’m inserting rows as webcontainers in multiple pages. The webcontainers contain the same data but are differently shaped depending on the page it will be inserted into.

I’m trying to use one routine for the inserting, so I need to identify which container to insert. I have a variable “r” that is the row to be inserted and eventually it gets embedded and added to an array. I’m stuck. This doesn’t work of course:

select case page
case “1”
var r as container1

case “2”
var r as container2

end select

r is no longer a variable after the end select or an end if.

Any solutions?

:face_with_raised_eyebrow:

Are you talking about pasing various WebPage Objects?

Did you tried this:

Select case page.name
  case "page1"
  case "page2"
End select

Not really . . . r is a webContainer, but there’s two different containers (one for each page). So I need to declare r but in a select case of if statement, the declaration is only valid within that statement.

I’m trying to not duplicate my programming as the only difference would be which container r is.

:open_mouth: it was confusing without the formating on the code. You should read the documentation about local variables: https://documentation.xojo.com/api/code_execution/select_case.html

Dim r...

Select case page.name
r = ...
End select

r...

One way…Apply an interface to the containers and define r as the interface before the select case.

Another…

Add a class to the navigator and then set its super to WebContainer, let’s say RowContainer. Set the supers of Container1 and Container2 to RowContainer. Define r as RowContainer before the select case.

In both cases you can use IsA to determine what class they actually are and cast as necessary.