Constant (Const) declaration ignored !

The code below does not works (2015r1):

[code]
Sub Open()
Beep // Line for breakpoint

Const kTitle As String = “Title”
End Sub[/code]

kTitle is not displayed in the debugger, and when I step from Beep to Const …/…, the line goes directly to the End Sub line.

No error message, not a phone call, no postcard not email, nothing !

Seriously, I falled into that yesterday evening, and simply dimed the variable.

Now, after some boot and shutdown, and before lunch, I checked using the code above (in the main window).

BTW: I changed kTitle to kTit, kPC… the line is ignored. I removed As String: same result.

And the cherry above the dessert was… the infamous “This is the first time you run the application…” I get at the first run (of the day / boot) in the IDE. The Debugger does not show anything from the Open Event, only Globals and Self wMain.wMain.

constants are values which are put into placeholders in code.
They don’t appear in debugger as variables as they don’t exist in compiled code.

You know ther eis a Break statement in Xojo:

[code]Sub Open()
Break // Line for breakpoint

Const kTitle As String = “Title”
End Sub[/code]

Also, your breakpoint is in the wrong place. Even in this corrected code, you won’t see the value, because the variable doesn’t exist yet.

Sub Open()
  Beep // Line for breakpoint
  
  Const kTitle As String = "Title"
  Dim theTitle as string = kTitle    // won't appear in debugger
End Sub

While with this code, you will see the value.

Sub Open()
  Const kTitle As String = "Title"
  Dim theTitle as string = kTitle    // will appear in debugger

  Beep // Line for breakpoint
End Sub

Thank you all for your answers.

I think I now understand what happens (but your explanations are good): I replaced the Const by a Dim, because there was a problem. It does not works better, but because I had hard time, I forgot that part and keep in mind what I said about Const.

Sorry about the buz and one more thank for the explanation.

You don’t have to cast the type imho.

A simple

Const kTitle = "This long title"

will do

Thanks Alexander. I also tried that, after the first error. The error were elsewhere (in the way I built the local file name to be read). The project worked yesterday evening when I shut down the computer (and it still works now).

Then earlier today, I recall what I wrote in the first post and started to want to understand.

Alexander: you gave me an idea and, yes, the Const works fine (I just checked deleting Dim and replacing it with Const, the error was elsewhere and the Const line was highlighted (I think, I do not recall), and I run the code, check in the Debugger and saw that the Const line was skipped in the step by step process. The rest is now know.