B4J Question Progress bar only working at the end[SOLVED]

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All

I have a few subs that I call and the last one I make the progress bar visible then read from MySQL database, manipulate the data in Lists and then put the answers back into the MySQL database..

Firstly the progress bar and the label does not appear till the end of everything yet the console does give me all the log answers

I seem to remember something about async remote access but when I did try it , it was very slow.

Does anyone have any ideas why it would not display or have any advise.

Thank you

B4X:
 ProgressBar1.Visible=True  
     LProgress.Visible=True
    ProgressBar1.Progress=10
    Log(dtaMainCat.Value)
    Log(dtaSubCat.Value)
    Log(dtaQuestionqty.Value)
    Log(dtaDifficult.SelectedIndex)
    If Sql2.IsInitialized = False Then    'in case the connection closes
        Sql2.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://162.215.***.76:3306/*z", "******user", "*****")
  
    End If
    '-----------------------------------------------
    Dim numberofrecords As Int

  
numberofrecords=(Sql2.ExecQuerySingleResult2("Select count(*) FROM Questions_db WHERE `main_cat` LIKE ? and `subCat` LIKE ? and `difficulty` LIKE ? ",Array As String(dtaMainCat.Value, dtaSubCat.Value,dtaDifficult.SelectedIndex )))


Dim listofvalues As List
listofvalues.Initialize
  
    Dim listofquestions As List
    listofquestions.Initialize
    Dim rp As ResultSet
    rp = Sql2.ExecQuery2("Select ques_id, main_cat, subCat,question,correct_no,answer1,answer2,answer3,answer4, difficulty FROM Questions_db WHERE `main_cat` LIKE ? and `subCat` LIKE ? and `difficulty` LIKE ? ",Array As String(dtaMainCat.Value, dtaSubCat.Value,dtaDifficult.SelectedIndex ))
    Dim ListOfMaps As List
    ListOfMaps.Initialize
    Do While rp.NextRow
        Log("Question ID -"&rp.Getint("ques_id"))
      
      
    listofvalues.Add(rp.Getint("ques_id"))
    Loop
    ProgressBar1.Progress=30
    Log("List of Values size "&listofvalues.Size)
  
Dim rndQues As Int
Dim curcount As Int

    For curcount = 1 To (dtaQuestionqty.Value) 
      
        rndQues=(Rnd(0,listofvalues.Size-1))
      
        listofquestions.Add(listofvalues.Get(rndQues))
  
Log("New Random question "&listofquestions.Get(curcount-1))

Log("list of values size "&listofvalues.Size)
      
        listofvalues.RemoveAt(rndQues)
      

    Next

    Dim ProgressValue As Int
  
    ProgressValue=100-dtaQuestionqty.Value
    ProgressBar1.Progress=ProgressValue
  
  
  
    For curcount = 1 To (dtaQuestionqty.Value)
    
    Sql2.ExecNonQuery2("INSERT INTO game_ques_db VALUES (?,?,?)", Array As Object(GloGameID,curcount,listofquestions.Get(curcount-1)))
     Log("uploaded "&curcount&" of "&(dtaQuestionqty.Value))
  
        ProgressValue=100-dtaQuestionqty.Value+curcount
      
    Next
 
Last edited:

aeric

Expert
Licensed User
Longtime User
Have you tried add
B4X:
Sleep(0)

 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Have you tried add
B4X:
Sleep(0)

That did work , Thank you
I put sleep(0) just before every progress value that I wanted it to increase
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top