User Input Opens Window

I’m currently trying to have the user type in the text field to open up the specified window as all the windows in the application. Currently, I just have a bunch of else if statements for each acronym but I was wondering if there was a better way to optimize the length of this code as I have over 50+ windows and don’t want to continue updating this search field as I add more windows. Here is what I attempted to try but I was it wasn’t working.

Try
  If TextFieldItemSelect.Text <> "" Then
    Var window As String = TextFieldItemSelect.Text + "Window"
    Var edit As New window
    edit.ShowModal
  End If
Catch
  MessageBox("The Selected Item Category is not currently available")
End Try

Unfortunately this sort of thing is not allowed in Xojo. The name of the window you want to open can’t be a string variable that you built at runtime from user input. The whole name has to be given in the source code.

You could replace these with a Select Case statement. It wouldn’t solve the problem you’re looking to solve, but it would be easier to read and update, e.g.:

Var windowname As String = TextFieldItemSelect.Text + "Window" //<---- String variable

Select Case windowname

Case "FooBarWindow" 
    Var edit as New FooBarWindow  //<---- Source code literal
    edit.ShowModal

Case  "BizBazWindow"
    Var edit as New BizBazWindow
    edit.ShowModal

// etc.

Else 
    MessageBox("The Selected Item Category is not currently available")

End Select
1 Like

I’m willing to bet that they all look more or less the same.
Might it be better to have a Window that changes mode based upon a property?
You still need a select case as part of the window, but I suspect that the controls displayed will have a lot in common.

1 Like

I do not know the context, but I can see a ListBox with a Window name by cell and a reference to that Window in the CellTag.

When the user click in one entry that window is displayed (using the Reference in the CellTag to show it…).