If … ElseIF … End If troubles

This is the second time I get wrong results with the construct below:

  If PM_Type.Text = "gif" Then
// Do something
ElseIf …
etc.

If I had an Else (default) clause, it is always executed regarless of the PopupMenu value.

Fr the first time, I do not know what I have done to make it work, but later that day, something changed and it started to work as it should.

Minutes ago, I started to port that change to another portion of the project (similar feature, but different enough to must be in a different PushButton).
And I get the same wrong behavior: nothing worked. Then, because some days ellapsed snce the first one was written, I set a variable and store the PopupMenu value in it. The new construct that now works is:

  // Get the PopupMenu Contents
  File_Type = PM_Type.Text
  
  // b.add some more parameters
  If File_Type = "gif" Then
// Do Something
ElseIf   File_Type = "jpg" Then
etc.

The code build an URL with different parameters depending on the target image file type (so texts). I add a System.DebugLog to get information while the project build my html list: I had two different reports for the same meaningful error.

Of course, I cleared the Cache folder, etc.

The only explanation is either esoteric or I am in the beginning of loosing my head and better go to the Sainte Anne Hospital.

Your thoughs ?

Yes, this is far beyond my understanding.

Xojo 2015r1 (it can’t be any different than the current version),
High Sierra
Internet is active

PS: this looks like all the troubles I had years ago. The project works until I shut down (to go home) and reboot the MacBook (after breakfast)… then it crashed… (using El Capitan or lower).

Emile,

In your second example, you copied the value to a variable so you can easily see it. Good.
The other suggestion I have is to use a case statement. I find them easier to read than multiple elseifs.

1 Like

the only thing that came in mind
is that xojo used a text class and string class.
or there is a magic encoding and then the compare works.

Thanks Bob.

Sometimes lazy programming = True.

In case of trouble (after lazy programming = True), Standard programming = True.

Of course, it is easier to debug / read only once the PopupMenu.

Select Case: I have only gif/jpg and tif as different cases. If I had more (5 or more ?). And at first I had only two cases (I was not aware I could get tif files, so I do not added it until I dscover that fact (specific to that use).
And, yes Select Case is better in terms of readability (one understand in a blink of an eye…)

But that explains nothing.

Not with Xojo 2015r1.

And I do not changed my code to that when this arise the first time, some days ago.

Now, in a different application Made with Xojo (2015r1), I cannot double-Click to edit a Cell in a ListBox.

Fortunately Return (to Edit) / Tab and Arrow keys (to navigate) works fine.

I am cursed. I cannot imagine something else.

rather use a ‘select case’ statement the elseif
it’s easier to manage

you used a boolean return in other event?

I think I remember dimly there had been troubles with the evaluation of nested Elseifs in the past, but I cannot find the thread anymore nor a ticket. I know for sure that there had been some IDEs where the debugger jumped lines weirdly.

It might be you are running into a (possibly fixed) bug with a 5 years old IDE, or it might be that your code produces somewhat ambiguous results. So either change your code like proposed above, or as a series of Ifs branching to the handling routines and returning afterwards, or test it with a more recent IDE to check if you are running into an old IDE bug.

No reason for drama. It’s not the first time you are reporting troubles with your code logic regarding If/Elseifs. Do yourself a favour and change your code to make it easier to debug. The only curse I see is combining an old IDE with a hard to follow nested logic. You can lift it yourself easily.

I changed nothing since the previous boot.

So, something else is at work there.

I left High Sierra and boot under El Capitan. The applciation works fine.

Maybe the shut down / boot cleared the problem ?

PS: Bob is right. I had reading problems and noticed a bug (jpg / jpeg), so I changed from If Then Else to Select Case.

Much more clear (more lines but who cares ?) I build an application not a one liner code… :wink:

Ulrich:
Another glitch workaround was to add line before the trouble (that is all I can recall). So addng the Dim line and the attribution line may remove the trouble.

Of course, I know we are in 2021 (this version will come, one day) and I compile with 2015. :frowning:

When I am in bad time area, I do not do that; but on good days, I fire the current IDE version and run the project so I can have something like a “second opinion” (the new version may detect error(s) or flag something strange or the simple fact to do that allow me to notice an error, etc.).
Unfortunately Cmd-S is so easy to do…

At last, it is raging to be able to add a brand new feature to an application without a single trouble in less than one hour and see the smiling faces of the users (when they discover the new and apparently awaitd feature) and not been able to add a simple image type test !
The PopupMenu is a strange way to allow the user to choose the target image file type (in a html generated text file…). The html file will load files depending on the user choice of the image type (the server have gif, png, jpg and tif files and the user choose its favorite kind).

I have to compile code for an older Linux release that doesn’t have or support glibc 2.12 or whatever.
Upgrading that component on an older linux system is almost certain death for the OS.
So… I have to keep an older Xojo version (2019 R4) – to compile for that platform.
It is frustrating to run into bugs that are probably fixed on newer releases…but you have to keep building under the old release.

1 Like