Method is called but nothing happens

Hi everyone,

I’ve got a rather simple problem but I can’t seem to find the reason why it doesn’t work. I use the Xojo 2013 Release 1 and in a desktop project I have a “call” command but the debugger just ignores it. Here’s the code:

[code] textMessage = “Are you sure you want to continue?”
Call Show_Message(textMessage, buttons_YesNo)

If MsgBoxAnswer = msg_answer_YES Then
Career.FileName = CareerFile(Selected_Career).FileName
LoadCareerNow = true

ElseIf MsgBoxAnswer = msg_answer_NO Then
ShowDeletionMessage = true

End if

If ShowDeletionMessage Then
textMessage = “Do you really want to delete this file? Once deleted, it cannot be recovered!”
Call Show_Message(textMessage, buttons_YesNo)

If MsgBoxAnswer = msg_answer_YES then
  f = GetFolderItem(dirCareers).Child(CareerFile(Selected_Career).FileName)
  f.Delete
  
  Call Show_Careers
End If

ElseIf LoadCareerNow Then
Call Load_Career

End if
[/code]

The problem is at the very bottom of this method when I say “Call Load_Career”. The debugger ignores this line as if it were a comment and proceeds to the next line, which is the end of the method. I would expect that the method “Load_Career” is being processed but that’s not the case.

Strange things:

  1. I tried to call other methods in this place instead of the “Load_Career” but they wouldn’t be processed either.
  2. I tried calling the “Load_Career” method earlier (before the first if-clause) and it worked as expected.
  3. Instead of calling the “Load_Career” at the place you see in the code above I tried calling it instead of the “LoadCareerNow = true”-command in the first if-clause. But it wouldn’t be called there either.

Is there something in Xojo that prevents methods from being called under certain circumstances? Thank you all in advance!

What do you expect to happen? From the LR: „Use the Call statement only when you want to call a function without using the value that it returns."

P.S. Does the debugger ignore it or is the ElseIf statement false?

It ignores it. The debugger checks the elseif-statement, goes into it (the line with the call-command is being highlighted) and goes to the next statement (the “End If” line) instead of entering the “Load_Career” method, which I would expect. The debugger does it with “Show_Careers” or “Show_Message” properly.

Just tried it without the “call” but same thing.

put a breakpoint INSIDE the LOAD_CAREER procedure… I bet it IS calling it… but it is not doing what you expect

In the debugger: if you press “step inside” instead of “step next” then it should go into the LOAD_CAREER method. Does it not do that?

Perfect, thanks Dave and Markus! It does indeed step inside the procedure. However, it’s something else that causes an exception and I can’t make sense of it either.

In the “Load_Career” procedure I open a text file which I had previously written the stringvalues of three different arrays into. Code looks like this:

  1. Write something into the file with SAVE_CAREER:

[code]…opening file commands…

For i = 1 To 50
s.WriteLine ArrayNumber1(i).Stringvalue(False)
s.WriteLine ArrayNumber2(i).Stringvalue(False)
s.WriteLine ArrayNumber3(i).Stringvalue(False9
Next i

s.Close[/code]

  1. Load this file with LOAD_CAREER:

[code]…opening file commands…

For i = 1 To 50
ArrayNumber1(i).Stringvalue(False) = s.Readline
ArrayNumber2(i).Stringvalue(False) = s.Readline
ArrayNumber3(i).Stringvalue(False) = s.Readline
Next i

s.Close[/code]

Now, the problem is that in the text file I would expect 50 x 3 lines, with each line populated. However, the file has a lot more than 50 x 3 lines because sometimes there are blank lines. Sometimes it’s 1 blank line, sometimes it’s 3. I can’t find any indication why the lines are blank. What I do know though is, it messes up reading the file.

I do not have great experience with writing and reading stringvalues from arrays but I don’t understand this at all. Thank you again!

Probably time to change the title of the post… :slight_smile:

To your problem… when you write to the file, do you delete the old file first?
Your writing code should produce 150 rows, assuming no exceptions occur in that.
Are you sure that all 3 arrays have values in all 50 slots?
Do you pre-populate the array with “” values?

Have you noticed this line: Stringvalue(False9 which should end with a )
That suggests that the code you posted really isn’t the code you are running…?

What lives in the array to require .stringvalue ?
If your array is an array of strings and you convert on the way IN to the array, you wont end up with any nulls in it.

Thanks, Jeff!

I’ll try to answer your questions as good as possible.

To your problem… when you write to the file, do you delete the old file first?
I don’t. I create a brand new file which did not exist before.

Your writing code should produce 150 rows, assuming no exceptions occur in that.
Are you sure that all 3 arrays have values in all 50 slots?
Yes, all slots have values.

Do you pre-populate the array with “” values?
Nope. I didn’t find any spaces or “” values in those slots.

Have you noticed this line: Stringvalue(False9 which should end with a )
That suggests that the code you posted really isn’t the code you are running…?
Yes, you’re right. It’s a typo. It’s not exactly the code that’s running, it’s just a few lines of the whole procedure. Everything else is just other values being written to the file. There’s not a problem with those, that’s why I left them out.

What lives in the array to require .stringvalue ?
If your array is an array of strings and you convert on the way IN to the array, you wont end up with any nulls in it.
It’s some strings and some integer values in those arrays. The reason I use .stringvalue is because the arrays are not a finished product yet, they are still growing. I use .stringvalue so that I don’t have to adjust the “SAVE” and “LOAD” procedures every time I introduce a new variable into that array.

In the meantime I found that ArrayNumber3 is the problem. No issues with the other two. So I decided to move ArrayNumber3 out of this for-next-loop into a separate one but the problem still persists.

Also tried to change the contents of the arrays but regardless of their values and regardless of the position of the WriteLine command within the method, there’s always one blank line after the 10th array, one after the 11th, three after the 12th, three after the 13th, one after 23, one after 24, one after 28, one after 30, one after 31 and one after 32. I really have no idea why :frowning:

Christopher,

you use:
s.Readline

and you have empty lines…

s.Readline does return nothing here. Are-you shure you get something when s.Readline fall into a blank line (a line with no character at all) ?

There is another possibility. If the original file has mixed line endings, read line may be getting confused. For instance if some of the lines only have chr(10) while others have chr(13) + chr(10) the latter may cause the blank lines.

How I get around the possiblity of mixed line-endings (or when I don’t know what platform created the file)

dim t as textinputstream
dim s as string
dim v() as string

t=textinputstream.open(f)
s=t.readall
t.close
s=replacelineendings(s,endofline.unix)
v=split(s,endofline.unix)

Another way to do this is to encode as hex when writing, then decode on the other side. A sample line for writing:

   s.WriteLine EncodeHex( ArrayNumber1(i).Stringvalue(False).ConvertEncoding( Encodings.UTF8 ) )

To read:

   ArrayNumber1(i).Stringvalue(False) = DecodeHex( s.Readline ).DefineEncoding( Encodings.UTF8 )

This will literally double the size of your output file, but there will be no doubt that what you get back is exactly the same as what you wrote, at least in terms of content.

The problem is not reading the file. My app creates the file by writing the stringvalues of three arrays into it, so I know the details of the file.

There should not be any blank lines in that file because it’s a for-next which runs 50 times and somehow it does the same 40 times and it does something different 10 times. Somehow, the stringvalues of these 10 arrays seem to be broken.

Probably, your data contains line endings. Remove them with

s = ReplaceLineEndings(s, “”)

before you write them out.