Unstable debug project

A project with a ListBox, a TextField and two PushButtons is really unstable.

Either the ContextualMenu or the MenuItems that does the same thing stays doing nothing, sometimes.

Sometimes an Exception occured.

Running the project a second time changes nothing.

That was yesterday. Today, it worked on the first run (a reboot occured in between), but I changed nothing to the code.

The project was born with API I, changed to API II solme times ago. *

I still have some work to do in the convert because some features stop on Row before the end / do not works at all (crash) because of the difference 1-based, 0-based…

Beside checking from where the exception occured (I do not remember what exception it was), do you have reached this kind of behavior / have ideas ?

What do the project when this happens ?
Essentialy looking at two columns (start date, end date), compute the ellapsed time in days and report the result in the next column.

BTW: I have two System.DebugLog “reported date” that helped me to eliminate a wrong date:
é instead of 2 or September 31, or just the year (instead of the awaited ISO 8601 date) are some examples… I am able to remove in the files I create or get and use with this project.

There is nothing here that will allow anyone to help you.

Sometimes an Exception occured.

I do not remember what exception it was

Post the project. Screenshot the next time the exception occurs.

some features stop on Row before the end / do not works at all (crash) because of the difference 1-based, 0-based

Outofbounds exception sounds most likely

3 Likes

If someone had strange behavior sometimes it may help. But you are right, it is difficult to understand.

I think so, but wuthout changing the loaded text file, the next time I loaded/asked the time area, the exception does not occured.

BTW: I used intensively GIMP this afternoon and there too I had strange things. One or two are know bugs, but some…

So, it may be my system or worst the SSD or the computer who have some wrong(s).

You do understand that this is what exceptions are all about, right? The whole point of wrapping code in a try-catch is to handle the times when you code doesn’t do what you asked, the exception to the rule.

So yes, we do need to see your code to truly help, or just wrap your code in a try-catch and handle the exception or ignore it.

1 Like

Ignore it by doing a Try…Catch without doing anything in the exception handler. :wink:

Thank you Greg, Sascha.

The project work fine with the same text file, OR get an Exception (probably OutOfBoundsException).

That is what I think the code MAY not be involved.

Next time (when ?), I will make a screen shot of the error message and try to analyze the problem (add a refresh for each Row change so I can know when in the text the crash occured but I have doubts).

Based on your very vague description, we can only assume that you are trying to write to a row (or column) that does not yet exist.

Once i do that and once it works fine: and I changed nothing ?

I think the answer is elsewhere.

I looked at my ContextualMenu Code; a part of it is below:

// b. Add an entry
Var colorSubMenu As New  MenuItem("Set Background Color")
colorSubMenu.AddMenu(New MenuItem("Red"))
colorSubMenu.AddMenu(New MenuItem("Green"))
colorSubMenu.AddMenu(New MenuItem("Blue"))
colorSubMenu.AddMenu(New MenuItem("Cyan"))
colorSubMenu.AddMenu(New MenuItem("Magenta"))
colorSubMenu.AddMenu(New MenuItem("Yellow"))
colorSubMenu.AddMenu(New MenuItem("Black"))
colorSubMenu.AddMenu(New MenuItem("Custom…"))
base.AddMenu(colorSubMenu)

I searched in the documentation why this does not appears there:

on the beginning, minutes ago, I wanted to set the Stories length having a submenu with the two entries below in the screen shot.
Then I recall that yesterday I do not saw the colors, and so I changed the search reason.

NB: this project were born with API 1.

I will change what I found to be API 2 compliant now.

Now I got them:

Next part the two Strips entries.

Where does a text file appear in this sample code?

I looked at my ContextualMenu Code;

Is that in ConstructContextualMenu() ?

And have you tried

Var colorSubMenu As New  MenuItem("Set Background Color") 

base.AddMenu(colorSubMenu)

colorSubMenu.AddMenu(New MenuItem("Red")) 

colorSubMenu.AddMenu(New MenuItem("Green")) 

colorSubMenu.AddMenu(New MenuItem("Blue")) 

colorSubMenu.AddMenu(New MenuItem("Cyan")) 

colorSubMenu.AddMenu(New MenuItem("Magenta")) 

colorSubMenu.AddMenu(New MenuItem("Yellow")) 

colorSubMenu.AddMenu(New MenuItem("Black")) 

colorSubMenu.AddMenu(New MenuItem("Custom…")) 


The problem comes when I use the ContextualMenu to fire a method who analyze a ListBox contents loaded from a text file.

This arise once more earlier today.

I get a friend visit while debugging and I let the laptop alone. After some times I saw something happens in the screen but I do not touched it not the Mouse.
A window owned by TextEdit appears at frontmost window (my project window) -1, so not frontmost, but an another window was there (the help window, I suppose.

This confirm (IMHO) that I have troubles in macOS or the SSD. I will try asap to install Tahoe on an external SSD and do what have to be done with the internal SSD / system.

Before someone chime in with that suggestion, yes I used Disk Utilities. No error was reported.

And, I still have the Stocks application that appears when I fire another application. I kill it, but it comes back when I run a project (but this is not related to Xojo; it is related to an application launch).

I checked that code because the problem arise wqhen I use a Contextual Menu / and … when I implemented the two “Strips” MenuItems, I do not took time to check how to add a MenuItem with Submenus, so today was the day to fix that (done).
I realized that I stayed with MenuItems vs API 2 (the project is meants to be API 2) everywhere else (I hope and do not want to mix both API).

Regards

My last attempt was getting a crash.

I fired the project as is, loaded the same text file, asked to add the number of days between two columns and report in a third one WITH SUCCESS (no OutOfBoundsException).

Something is wrong and I do not think at what it can be !

Bug I saved the DebugLog for later checks…

What is that exact code, and is it in an event or a method?

Code provided by Sascha (CountDaysWithOrWithoutSundays in this Forum) and it is a Method.

I was unable to get the error in the last two hours.

PS: I found another, unrelated, bug in the "Set Background Color" code: I use the SubMenu name instead of the Color Names…
I wonder how that was working in API 1…
Apparently I refactored simple entries with many colors into a SubMenu and never finished it. That is why it does not works “now”.
That is why the Case "Set Background Color" is skipped at debug time (I followed the running…

Time for some meal.

That was untested Code :slight_smile: I changed a few things this morning (after reading your reply here):

Public Function CountDaysWithOrWithoutSundays(startDate As DateTime, endDate As DateTime, Optional WithoutSundays As Boolean = False) As Integer
  // Check is startDate is before endDate
  If startDate > endDate Then
    Return 0 // or report an error, if startDate is later than endDate
  End If
  
  Var countedDays As Integer = 0
  
  If WithoutSundays Then
    
    While startDate < endDate
      // check if current day is no sunday (weekday 1 in Xojo)
      
      If WithoutSundays Then
        
        If startDate.DayOfWeek <> 1 Then countedDays = countedDays + 1
        
      End If
      
      // Advance 1 day
      startDate = startDate.AddInterval( 0, 0, 1 )
      
    Wend
    
  Else
    
    countedDays = (endDate.SecondsFrom1970 - startDate.SecondsFrom1970) / 86400
    
  End If
  
  Return countedDays
End Function

It was used (tested if you prefer) since you shared it on daily basis (Dailies, never Sundays), then I added the call to get also the number of Sundays (just a matter of True / False in the calling, but I do needed only the dailies for some times and added a call with the other value to get the number of Sundays).

To be short: your code was working.

Going to your code was having troubles. The trouble comes before the call to your shared code.

So, once more: Thank You for the sharing code.

1 Like

You are as always, welcome :green_heart:

Unfortunately, I have another troublesome on the same project, and this is not related to the Search window.

This is converted to API 2 in a (now) running Xojo 2025r2.1

  1. The trouble: I am unable to Paste a Text to the SearchField.
    Copy the Text typed in the SearchField, tried to Paste does not works (no text).

I add another DesktopSearchField in the Search Window and Paste does not worked.

Everything is DesktopXxxx (the window/ the SearchField), the Window MenuBar is correct too.

I searched in the project where there is code to my SearchField: only in MouseUp. And I checked each line.
Cmd-V hilight the Edit Menu (so the command is activated)
Even using Paste in the MenuBar does not POaste the text.

I searched in Issues and see a project (to demonstrate some other bug) and downloaded it, run it, Paste works fine in the SearchField.

  1. I created a new project, add a SearchField and run it: works fine.

  2. I Save As… / Close the project / Load it and see what happens: I get the same result.

  3. Save to XML is no more possible ! Or I really really have eye troubles too…

  4. Must I create a new project and Copy Paste the current elements to the new project ?
    Should I light a candle in my church?

I lack ideas except throw througth the window (the computer since I cannot do that with Xojo :wink: but it is not possible (these windows are locked at my local McDonald’s where I am), fortunately.

This project was started as API 1 and converted to the current version (2025r2.1), everything Desktop (I checked).

The tests were done on MBPro 13" M1 running Tahoe 26.1.

I added a TextField to the window, Copy KeyUp, Paste it in the TextEdit (Navigator), run, it works file, my Results ListBox is filled (with wrong information, but this is a work in progress).

If there are no Edit menus active at the time, shortcut keys like copy and paste may not work in a textfield

You can emulate it using Keydown event: (editted to remove superfluous case check, which was because I was thinking KeyCodes)

dim c as new Clipboard
if  key = “C” and Keyboard.AsyncMenuShortcutKey then
c.Text =me.Text
end if
c.close