code execution flow?

techknight

Well-Known Member
Licensed User
Longtime User
What is the execution flow when the program is running? Why I ask is in code, is it step-by-step or does it jump around?

my app has weird issues which ive posted on before where some code never gets executed and some code does, and its in the same exact subroutine block. I have to move code into other unrelated subroutines that get called in that sub block and the code runs...

Sometimes code will run to update labels in an activity when i havent even ran the code to load the layout yet, and in LOGICAL order the layout load code comes BEFORE the label update code. but sometimes it gets executed bass-ackwards.

Here is an example, Everything is in green comments that explain the issue:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      admin.Initialize("admin")
      serial1.Initialize("serial1")
      If admin.IsInitialized = False Then
         ToastMessageShow("Bluetooth not Installed, Device Unsupported", True)
      End If
   End If   
   Activity.Title = "RCSE ScoreAll"

   'Initialize the panels we use for the pages and put them in the container
   container.Initialize
   
   Activity.SetBackgroundImage(bmp)
   
   Activity.AddMenuItem("Connect","mnuConnect")
   Activity.AddMenuItem("Disconnect","mnuDisconnect")
   Activity.AddMenuItem("DIM", "mnuDimming")                     '<Runs Fine ONLY IF i put these statements here! If i move them at the bottom, it WONT RUN!>
   Activity.AddMenuItem("Clear Board","mnuClear")

   ReadConfig                          '<---Runs Fine
   
   SetDisplay                           '<---Runs Fine
   
   lblHome.Text = NumberFormat(Home, 2, 2)             '<----DOES NOT RUN, and not shit below this runs either....
   lblGuest.Text = NumberFormat(Guest, 2, 2)
   lblDowns.Text = Downs
   lblYds.Text = Yards
   lblTime.Text = NumberFormat(Minutes, 2, 2) & ":" & NumberFormat(Seconds, 2, 2)   '<-----DOES NOT RUN! i know it dont as i had a syntax bug here and the compiler/java did not complain about it, even though i fixed it>
   Dim I As Int
   Select Case Quarter
      Case 1
         rbQuarter0.Checked = True
      Case 2
         rbQuarter1.Checked = True
      Case 3
         rbQuarter2.Checked = True
      Case 4
         rbQuarter3.Checked = True
      Case Else
         rbQuarter0.Checked = False
         rbQuarter1.Checked = False
         rbQuarter2.Checked = False
         rbQuarter3.Checked = False
   End Select
   Select Case Possession
      Case 0
         ImgPossHome.Visible = False
         imgPossGuest.Visible = False
      Case 1
         ImgPossHome.Visible = True
         imgPossGuest.Visible = False
      Case 2
         ImgPossHome.Visible = False     '<none of this shit runs either....>
         imgPossGuest.Visible = True
   End Select

   RefreshTimer.Enabled = True       '<----- DOES NOT RUN... 

   If connected = False Then
      DisableAll                         '<...... DOES RUN... Dont ask me why.. it does. Skips the instruction before it? WTF?>
   End If   
   
End Sub

Sub DisableAll
RefreshTimer.Enabled = True           '<....DOES RUN!, now tell me why it runs here and NOT before calling this sub??????>

'<bunch of other code and things here Snipped> 
End Sub

any ideas?
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
The code runs in whatever order you tell it to. It looks as though you are doing something in SetDisplay that may be causing the code to stop (or it runs in an endless loop). Can you post both the SetDisplay and ReadConfig codes.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately you don't give enough information.
As JonPM already metioned we don't know what you are doing in the other routines.
Examples in: lblHome.Text = NumberFormat(Home, 2, 2)
You say it doesn't work, what value does Home have ?

Have you ever set breakpoints in your code to see what happens step by step ?

You could also post your project as a zip file (IDE menu Files / Export As Zip) so we could test it in the same conditions as you do.

Best regards.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I cant set breakpoints, the bluetooth serial connections blows up the IDE debugger. Besides, its not just the lblhome line, its ALL of it. the whole thing just doesnt run. But it runs routines after that... i cant explain it. i really cannot. Anyway, here is the other 2 subroutines:

B4X:
Sub ReadConfig()
   If File.Exists(File.dirinternal, "settings.ini") Then
      Dim TR As TextReader
      Dim a As String
      TR.Initialize(File.OpenInput(File.DirInternal, "settings.ini"))
      a = TR.ReadLine
      'Check to see if a password is saved.
      If a = "" Then         'if we indeed read a valid password then
         Passwordsaved = False
         MD5Password = ""
         Password = ""
      Else
         Passwordsaved = True
         MD5Password = a
      End If
      
      'Read Scoreboard Address
      BoardAddress = TR.ReadLine
      If BoardAddress = "" Then BoardAddress = "01"
      
      a = TR.Readline         
      If Left(a, 3) = "yes" Then
         Home = Val(TR.ReadLine)
         Guest = Val(TR.ReadLine)
         Yards = Val(TR.ReadLine)
         Downs = Val(TR.ReadLine)
         Quarter = Val(TR.ReadLine)
         Minutes = Val(TR.ReadLine)
         Seconds = Val(TR.ReadLine)
         Possession = Val(TR.ReadLine)
      Else
         Home = 0
         Guest = 0
         Yards = 0
         Downs = 0
         Quarter = 0
         Minutes = 0
         Seconds = 0
         Possession = 0
      End If   
   TR.Close
   Return
   Else
      'Settings.INI file doesnt exist, so lets build some parms to be saved, and put in baseball mode. 
      Home = 0
      Guest = 0
      Yards = 0
      Downs = 0
      Quarter = 0
      Minutes = 0
      Seconds = 0
      Possession = 0
      BoardAddress = "01"
   End If   
End Sub
Sub SetDisplay()

   'Add current scoreboard layout to panel 1
   pan = CreatePanel(1, "Main")
   container.AddPage(pan,"Main")
   
   'Add About layout to Panel 2
   pan = CreatePanel(2, "About")               'Show author and personalization panel
   container.AddPage(pan,"About")
   
   'Now we have a container with our panels just add it to the pager object
   pager.Initialize(container, "Pager")
   
   'Now we can add the pager to the activity   
   Activity.AddView(pager, Activity.Left, Activity.Top, Activity.Width, Activity.Height) 
   pager.BringToFront
   
End Sub
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
I am thinking its the phone. I got a much newer, but still crappy alacatel running droid 2.2 and im able to follow all my code in debug.

I was using an HTC G1 phone rooted with cyanogen 2.2 on it.
 
Upvote 0
Top