Using NOT, ISA and windows

I have a line of code that isn’t working to identify that a window is NOT a window.

If App.WindowCount >= 1 And Not App.Window(0) ISA SrchDWin And Not App.Window(0) ISA LilDWindow And Not App.Window(0) ISA MainPage Then
  App.Window(0).Show
ElseIf ...

Would someone please explain why this If statement isn’t being selected.
Outside of the Not window part it is being selected. I know this because I broke the Not section into an inner IF statement and it was selected. That code is below

If App.WindowCount >= 1 Then
     If Not App.Window(0) ISA SrchDWin And Not App.Window(0) ISA LilDWindow And Not      App.Window(0) ISA MainPage Then
             App.Window(0).Show
     End If
ElseIf ...

Hum,

the first code seems alright unless I miss something. Personally I like to use () and break a long statement on many lines, for example:

If App.WindowCount >= 1 _
   And (Not App.Window(0) ISA SrchDWin) _
   And (Not App.Window(0) ISA LilDWindow) _
   And (Not App.Window(0) ISA MainPage) Then
  App.Window(0).Show
ElseIf ...

To me this form is easier to read. The nested And clauses stop being evaluated as soon as one of hem is false. That ‘may’ explain why the If in the first snippet would never be executed. I suggest you to use () and _ to break the statement on many lines, just to see if with () that would work

I put the line down as suggested and it didn’t improve it any

If App.WindowCount >= 1 _
  And ( Not App.Window(0) ISA SrchDWin )_
  And ( Not App.Window(0) ISA LilDWindow )_ 
  And ( Not App.Window(0) ISA MainPage ) Then

It still goes to an ElseIf instead

Put the result of the several conditions in boolean variables and see which condition fails:

Var windowCountCondition As Boolean = App.WindowCount >= 1
Var srchDWinCondition As Boolean = Not App.Window(0) ISA SrchDWin 
Var lilDWindowCondition As Boolean = Not App.Window(0) ISA LilDWindow
Var mainPageCondition As Boolean = Not App.Window(0) ISA MainPage

If windowCountCondition _
  And srchDWinCondition _
  And lilDWindowCondition _ 
  And mainPageCondition Then
1 Like

if this part is true ’ I broke the Not section …and it worked properly’

Brackets feels like the answer - because it ALMOST looks like its being evaluated as a Bitwise expression

windowcount >= (1 AND somethingnumeric AND somethingnumeric)

you could try

If (App.WindowCount >= 1) And

App.Window(0) is a function call.
You could just put the result into a variant and then check the variant content.
See it in the debugger when you stop at a break point.

And also use Introspection.GetType() to query type and thus the class name to show verify for logging.

I tried both types of brackets {} and got a “syntax error” with no explanation on both.
I also tried looking up bracket in the LR and there were no obvious subject headings for them or parentheses. Grumble.

Also, I know what App.Window(0) is. (Thanks Christian) I know it is also not one of the window types.

If App.WindowCount >= 1 _
  And { Not App.Window(0) ISA SrchDWin }_
  And { Not App.Window(0) ISA LilDWindow }_ 
  And { Not App.Window(0) ISA MainPage } Then
  App.Window(0).Show
ElseIf App.WindowCount = 0 Then
  MainPage.Show
Else
  MainPage.Show
End If

This problem has become an “ego” issue. I could very easily switch to a positive statement using "OR"s but I’d really like to find out about the NOT’s

You use the round brackets ()

Xojo wouldnt recoginse those other ones

If (App.WindowCount >= 1) And  Not ( App.Window(0) ISA SrchDWin) And Not (App.Window(0) ISA LilDWindow)  And not ( App.Window(0) ISA MainPage) Then
  App.Window(0).Show
ElseIf ...

Grumble. Failed

If App.WindowCount >= 1 _
  And Not ( App.Window(0) ISA SrchDWin )_
  And Not ( App.Window(0) ISA LilDWindow )_
  And Not ( App.Window(0) ISA MainPage ) Then
  App.Window(0).Show

Did I find another weird bug?

i not understand why are you using Window(0)
i guess the first window is the start default window from app settings in inspector.

i use this to close all others before the main close

Dim n, i As Integer

n = App.WindowCount

System.DebugLog(App.WindowCount.ToText)

For i = n-1 DownTo 0
  
  If App.Window(i) IsA WindowUsers Then App.Window(i).Close
  If App.Window(i) IsA WindowFind Then App.Window(i).Close
  If App.Window(i) IsA WindowSettings Then App.Window(i).Close
  If App.Window(i) IsA WindowAbout Then App.Window(i).Close
  If App.Window(i) IsA WindowFeedback Then App.Window(i).Close
  If App.Window(i) IsA WindowChart Then App.Window(i).Close
  
Next

that a window is NOT a window.

???

I’ve not been able to replicate it here with your exact If cut and pasted into my code in Windows using 2021r2.1.

Are you able to replicate it in the new test project?

Also, what is your OS version and Xojo version?

What was the outcome of trying Stefan’s code from the lower half of Using NOT, ISA and windows - #4 by StefanA

You haven’t put the first condition in parentheses. Try

If ( App.WindowCount >= 1 ) _
  And Not ( App.Window(0) ISA SrchDWin )_
  And Not ( App.Window(0) ISA LilDWindow )_
  And Not ( App.Window(0) ISA MainPage ) Then
  App.Window(0).Show
2 Likes

My deleted post. :slight_smile:

1 Like

Grumble.
It was not window(0) that was what I was looking for. It was window(1). It has been so long since I wrote this code that I thought I had the window()s correct.
Thank you all

2 Likes

You should keep an app or global level reference to the window you want so that you can refer to it by name.

By the way, this:

I know this because I broke the Not section into an inner IF statement and it was selected.

must have been incorrect all along?

2 Likes