Android Question Trap in a Do while Loop

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I have this codes
B4X:
Sub Process_Globals
    Dim StTm As Byte
    Dim MaxTm As Byte
End Sub

Sub Globals
    Private SendPrg As ProgressBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ProgressTimer.Initialize("ProgressTimer", 1000)
End Sub

Sub btn_Click
    MaxTm = 3
    StTm  = 0
   
    ProgressTimer.Enabled = True
   
    Do While StTm <= MaxTm
    Loop
    ProgressTimer.Enabled = False
End Sub

Sub ProgressTimer_Tick
    StTm = StTm + 1
End Sub
Anyone knows why execution is trap in a Do While Loop on Sub btn_Click?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub btn_Click
 MaxTm = 3
 StTm = 0
 ProgressTimer.Enabled = True
End Sub
Sub ProgressTimer_Tick
 StTm = StTm + 1
  if StTim >= MaxTm then ProgressTimer.Enabled = false
End Sub
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Thanks for you replied.

Codes from you won't work, cause I need to pause execution in Sub btn_click.

Sorry, my mistake, may be this codes is more clear
B4X:
Sub btn_Click
    MaxTm = 3
    StTm  = 0
 
    ProgressTimer.Enabled = True
 
    Do While StTm <= MaxTm
    Loop
    ProgressTimer.Enabled = False
    do_another process
End Sub
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
The problem is, waiting time is not depend only for a specific time, but also depend on a variable value, where this value is assign upon an execution of a series command in a sub.

I need it to implement in RDC. Since RDC, as I know is not support transaction, I need to know when insert a large of data, for ex, 1000 data, I need to know it all data, successfully inserted.

My idea is using an integer value in jobdone. For ever success job, this value increased.

Then on a click button, wait for this value to reach 1000 for a specific time. If it reached 1000, then, no problem, but if it never reach 1000 after a specific time, then I assume there is a problem.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Ok, there are a couple of ways to do this.
Lets say RDC needs to insert 1000 records, and you are incrementing this value in JobDone. (Also remember due to the DoWhile Loop, JobDone event cannot be raised, so that would not have worked anyway).

One option is to disable the button until all the records are inserted.
Another option is to set a flag on the Button_Click saying button is clicked, and check that flag in the JobDone sub (will be a delayed click).

Still I am not sure, how your User Interaction is supposed to go, is the same button used for inserting the transacations and completing them?
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Yes, it is the same button.

My problem is, jobdone is an event, the response is not right away. Users may click the button and then close the program and assume that all data are sent without any problems.

I will try disabled the button and add progress bar, and increase its value inside jobdone.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Basically, JobDone is the event which will be fired, which will tell you your RDC inserts have completed.
You must make sure you have one button to start the inserts, add a progressbar to be updated in JobDone, and that is where you check for completion, and trigger the next code from there.
 
Upvote 0
Top