Progress bar maximum value

droidman

Member
Licensed User
Longtime User
so in vb and .net we have the progressbar.max, if i want my app to depend on a list size and that list size is 1000 and i only have up to 100 on basic4android, how do i get from 1 to 1000 without using percentage?
is there a method or library i dont know about? i tried max and Maximum and none worked. :sign0104:
 

droidman

Member
Licensed User
Longtime User
My answer was based on your statement

If it is going to vary, then use percentages, the calculation is quite simple:

ProgressPos=ListPos/ListSize*100

thank you very much, it works, the only problem is that the program uses the cpu of the mobile phone to grab all the contacts and it gets stuck for 2 minutes, the progressbar only appears when it is at 100%, how can i allow it to refresh smoothly?
 
Upvote 0

droidman

Member
Licensed User
Longtime User
hmmm i tried DoEvents like on the old VB6 and seems to work. does this also makes the app slower like it did with vb6 ?
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
hmmm i tried DoEvents like on the old VB6 and seems to work. does this also makes the app slower like it did with vb6 ?

I don't know the overhead for DoEvents, but 2 minutes to read the contacts seems a lot, could you post the code that you are using to read the contacts and we can see if it can be speeded up.
 
Upvote 0

droidman

Member
Licensed User
Longtime User
I don't know the overhead for DoEvents, but 2 minutes to read the contacts seems a lot, could you post the code that you are using to read the contacts and we can see if it can be speeded up.

B4X:
For i = 0 To listOfContacts.Size - 1
        myContact = listOfContacts.Get(i)
      names = myContact.Name
      emails = myContact.GetEmails
                list1.Add(Array As String (names & ", " & emails))
                ProgressBar.Progress = i/Maximo*100
      DoEvents        
    Next
less than 2 minutes to download more than 1200 contacts on an HTC magic with a 528MHz processor
 
Upvote 0

galimpic

Member
Licensed User
Longtime User
Try reducing the frequency of updating & doeventing :)

B4X:
For i = 0 To listOfContacts.Size - 1
        myContact = listOfContacts.Get(i)
      names = myContact.Name
      emails = myContact.GetEmails
                list1.Add(Array As String (names & ", " & emails))
if i mod 10 = 0 then
                ProgressBar.Progress = i/Maximo*100
      DoEvents        
end if
    Next
 
Upvote 0

droidman

Member
Licensed User
Longtime User
Try reducing the frequency of updating & doeventing :)

B4X:
For i = 0 To listOfContacts.Size - 1
        myContact = listOfContacts.Get(i)
      names = myContact.Name
      emails = myContact.GetEmails
                list1.Add(Array As String (names & ", " & emails))
if i mod 10 = 0 then
                ProgressBar.Progress = i/Maximo*100
      DoEvents        
end if
    Next

i was thinking of that but i didn't know how to make it, well now i do.
also one small fix, when the program gets to the end of the list, it must update, so
ProgressBar.Progress = i/Maximo*100
should not be inside the IF, otherwise it will not update properly and the bar will not reach 100%
is that right ?
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
As the progress bar only changes on whole numbers, you could use
B4X:
For i = 0 To listOfContacts.Size - 1
        myContact = listOfContacts.Get(i)
      names = myContact.Name
      emails = myContact.GetEmails
                list1.Add(Array As String (names & ", " & emails))
if i mod Maximo = 0 then
                ProgressBar.Progress = i/Maximo*100
      DoEvents        
end if
    Next

I would not worry about not seeing 100% if you are removing the progress bar once loading is complete, you see this happen on a lot of apps - the bar gets to 99% and then it disappears.
 
Upvote 0

droidman

Member
Licensed User
Longtime User
oh ok...
listen, i'm having one small problem...
when adding members to my list as you see here:
list1.Add(Array As String (names & ", " & emails))
members are added in one per line, and when i export to CSV like this:
su.SaveCSV2(File.DirRootExternal, "contacts.csv", ",", list1, Array As String("Name", "Email"))
they get all mess'd up.
for example, the first line gets the name, second email, and then all emails until the midle of the list where the names are.
one per line
like
name,[email protected]
and then
[email protected],
[email protected],
[email protected],
and in the end
name
name
name

this is obviously due to me being a total noob in this, i'm obviously doing something wrong.
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Do you declare emails (the variable), as
B4X:
emails = myContact.GetEmails
will return a map of email address and their types. I suspect using it as a string (or string array) is messing things up. The following may cure it
B4X:
For i = 0 To listOfContacts.Size - 1
   myContact = listOfContacts.Get(i)
   names = myContact.Name
   Dim emails As Map
   emails = myContact.GetEmails
   If emails.Size > 0 Then ' Ignore contacts with no email
      For e=0 To emails.Size-1 'step through the email addresses and add them to the list
         list1.Add(Array As String (myContact.DisplayName & ", " & emails.GetKeyAt (e)))
      Next
   End If
   If i mod Maximo = 0 Then
      ProgressBar.Progress = i/Maximo*100
      DoEvents        
   end if
Next
 
Last edited:
Upvote 0

droidman

Member
Licensed User
Longtime User
ok so all fields came this way to the CSV

or
or
Name1 - 2nd name (MyMap) {[email protected]=3, [email protected]=1}

and i have 2 fields when saving the csv
su.SaveCSV2(File.DirRootExternal, "contacts.csv", ",", list1, Array As String("Name", "Email"))

And the data only goes to the "Name" and is not separated by "," it just get's a lot of data with "{}" and "=1" or "=3" and every contact get's "(MyMap)" either they have name or not... this is confusing
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Was the above post referring to the results of my code?

If not try my version, as it gets the data from the email map.
 
Upvote 0

droidman

Member
Licensed User
Longtime User
Was the above post referring to the results of my code?

If not try my version, as it gets the data from the email map.

yes that is the result
savecsv2 saves the contents of list1. i was needing to clean that up to save more fields. my idea was to save all the fields to a csv each field in their respective place, name, mail, phone etc.
this mail part was to simplify the process and to allow the user to select if he wants to export names and mails, or everything
by the way, thank you for your help
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
We are mixing up strings and lists, try this code
B4X:
Dim names As String 
Dim list1 As List
list1.Initialize 
Dim list2 As List
list2.Initialize 
For i = 0 To listOfContacts.Size - 1
   myContact = listOfContacts.Get(i)
   names = myContact.Name
   Dim emails As Map
   emails = myContact.GetEmails
   If emails.Size > 0 Then ' Ignore contacts with no email
      For e=0 To emails.Size-1 'step through the email addresses and add them to the list
         list1.Add (Array As String (myContact.DisplayName, emails.GetKeyAt (e)))
      Next
   End If
   If i mod Maximo = 0 Then
      ProgressBar.Progress = i/Maximo*100
      DoEvents        
   end if
Next
list2.AddAll (Array As String("Name", "Email"))
su.SaveCSV2(File.DirRootExternal, "contacts.csv", ",", list1,list2 )
 
Upvote 0

droidman

Member
Licensed User
Longtime User
please ignore, i forgot to delete one if and for cycle below.i deleted it and it worked just fine. i'm now checking if the output is correct
 
Upvote 0
Top