Jump to content

Yet another progress bar question


Recommended Posts

Ok so heres the skinny, I have tried to search for what i am looking for but nothing seems to fit (that i can place my head around, so here goes.

I have a script that i created that loads a nice little gui. in the gui i have a button that I can press that will do a few things for me, it works great! no frills no mess, it just works. when it's all done i get a msgbox saying done and i click ok.

So what exactly happens when i click the button? approx 50+ reg keys are entered in to the registry. then 3 programs are moved from the system

So here is my question. I would like to show a progress bar for each reg key added. I was able to do this, but i think that the code is pretty cumbersome

ProgressOn("Status","","")
....
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\21")
ProgressSet(99.88,"","Completed 21 of 22")
Sleep(50)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\22") 
ProgressSet(100,"","Completed 22 of 22")
Sleep(50)
ProgressOff()

There is an example of what i have, now just imagine some 50 more keys. Is there an easier way i can display a progress bar???

I'm pretty novice when it comes to coding. I know about arrays and stuff but no clue on how to implement them, or if they would even help in a situation like this?!?! Any help would greatly be appreciated to add some fluff :blink:

Link to comment
Share on other sites

Put your values in an array and try it like this:

; [n][0] = key
; [n][1] = value
; [n][2] = type
; [n][3] = data
Global $aRegWrites[10][4] = [["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\21", "Test21", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\22", "Test22", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\23", "Test23", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\24", "Test24", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\25", "Test25", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\26", "Test26", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\27", "Test27", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\28", "Test28", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\29", "Test29", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\30", "Test30", "REG_SZ", "Hello world"]]

ProgressOn("Status", "", "")
For $n = 0 To UBound($aRegWrites) - 1
    ConsoleWrite($n & ':  RegWrite(' & $aRegWrites[$n][0] & ', ' & $aRegWrites[$n][1] & ', ' & $aRegWrites[$n][2] & ', ' & $aRegWrites[$n][3] & ')' & @LF)
    $iPercent = ($n + 1) / UBound($aRegWrites) * 100
    ProgressSet($iPercent, "Completed " & $n + 1 & " of " & UBound($aRegWrites), "$iPercent = " & $iPercent)
    Sleep(500)
Next
ProgressOff()

:blink:

Edit: Fix stupid maths error.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Put your values in an array and try it like this:

; [n][0] = key
; [n][1] = value
; [n][2] = type
; [n][3] = data
Global $aRegWrites[10][4] = [["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\21", "Test21", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\22", "Test22", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\23", "Test23", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\24", "Test24", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\25", "Test25", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\26", "Test26", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\27", "Test27", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\28", "Test28", "REG_SZ", "Hello world"], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\29", "Test29", "REG_DWORD", 0xF0D1B098], _
        ["HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\30", "Test30", "REG_SZ", "Hello world"]]

ProgressOn("Status", "", "")
For $n = 0 To UBound($aRegWrites) - 1
    ProgressSet($n / UBound($aRegWrites) - 1, "", "Completed " & $n & " of " & UBound($aRegWrites) - 1)
    ConsoleWrite($n & ':  RegWrite(' & $aRegWrites[$n][0] & ', ' & $aRegWrites[$n][1] & ', ' & $aRegWrites[$n][2] & ', ' & $aRegWrites[$n][3] & ')' & @LF)
    Sleep(500)
Next
ProgressOff()

:blink:

Sooo thats how! mmm'kay! works fine, Getting a count, as exampled, 0 to 9 and counts up. though the progress doesn't seem to fill up as it proceed's from 0 of9 to 1 of 9, 2 of 9 and so on.
Link to comment
Share on other sites

Hi

Could this be used on this code also?

FileWrite($Filename & ".Html", ' <tr>')
FileWrite($Filename & ".Html", '  <td id="tdCompanyName" colspan=10 valign=top>')
FileWrite($Filename & ".Html", '  <p id="CompanyName" valign=buttom><b>' & $Read_Company & '</b></p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", '  <td id="tdSenderName" width=454 colspan=7 valign=top>')
FileWrite($Filename & ".Html", '  <p id="SenderName"><b><i>' & $Sender_CompanyName & '</i></b></p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", '  <td width=65 valign=bottom>')
FileWrite($Filename & ".Html", '  <p>E-mail</p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", '  <td width=113 valign=bottom>')
FileWrite($Filename & ".Html", '  <p align="right">my@mail.com</p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", ' </tr>')
FileWrite($Filename & ".Html", ' <tr>')
FileWrite($Filename & ".Html", '  <td width=430 colspan=10 valign=top style="border-left: 1px dotted #000000; border-right: 1px dotted #000000; border-top-width: 1px; border-bottom-width: 1px">')
FileWrite($Filename & ".Html", ' <p id="Address1"><b>' & $Read_Address1 & '</b></p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", '  <td width=454 colspan=7 valign=top>')
FileWrite($Filename & ".Html", '<p id="SenderAddr1"><i>' & $Sender_Address1 & '</i></p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", '  <td width=178 colspan=2 valign=top>')
FileWrite($Filename & ".Html", '  <p>www.myweb.com</p>')
FileWrite($Filename & ".Html", '  </td>')
FileWrite($Filename & ".Html", ' </tr>')
FileWrite($Filename & ".Html", ' <tr>')

This is a part of a 2035 line long html doc, that ends up as a freight-letter.

or is there a more simple way for me to do it?

Cheers

/Rex

Link to comment
Share on other sites

Where does the variable data come from? Assuming you can get the count initially, it would be very easy to show a progress bar while processing the items. What matters is that progress is a ration of current/total, so you need to know the total count to be worked through to do that math.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Where does the variable data come from? Assuming you can get the count initially, it would be very easy to show a progress bar while processing the items. What matters is that progress is a ration of current/total, so you need to know the total count to be worked through to do that math.

;)

Hi PsaltyDS

I read the var's from an gui i created, i know the total of html it either 584 lines or 1141 or 856 or 2035 depending on user input.

But the vars are already set when i write the html so i think that it's only for the file write the progress needs to be shown maby :blink:

i do have a part where i call some functions that reads/checks user input and puts it into an array (this is where i set my var's) :P

Cheers

/Rex

Link to comment
Share on other sites

sry ;) i tent to blabber :blink:

I want/need a way to show the user how long the filewrite process has left thing, that's why i fell over this post searching the forum.

What i have is a script that do a filewrite creating a html doc containing 1,2,3 or 4 pages (584, 1141, 856 or 2035 lines)

hope that it makes sense now :P

Cheers

/Rex

Link to comment
Share on other sites

This is how I understood you: You're writing that block of HTML once for each of the items. There are many such blocks to write, but you know how many there are. So in the loop that steps through the items, you can use the method given in this topic to update a progress bar showing how far along the script is in writing all the blocks.

All that appears to be answered already. What remains to be done?

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Ok so heres the skinny, I have tried to search for what i am looking for but nothing seems to fit (that i can place my head around, so here goes.

I have a script that i created that loads a nice little gui. in the gui i have a button that I can press that will do a few things for me, it works great! no frills no mess, it just works. when it's all done i get a msgbox saying done and i click ok.

So what exactly happens when i click the button? approx 50+ reg keys are entered in to the registry. then 3 programs are moved from the system

So here is my question. I would like to show a progress bar for each reg key added. I was able to do this, but i think that the code is pretty cumbersome

ProgressOn("Status","","")
....
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\21")
ProgressSet(99.88,"","Completed 21 of 22")
Sleep(50)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\test\22") 
ProgressSet(100,"","Completed 22 of 22")
Sleep(50)
ProgressOff()

There is an example of what i have, now just imagine some 50 more keys. Is there an easier way i can display a progress bar???

I'm pretty novice when it comes to coding. I know about arrays and stuff but no clue on how to implement them, or if they would even help in a situation like this?!?! Any help would greatly be appreciated to add some fluff :blink:

Look here. No point reinventing the wheel. This tool I use all the time. It will do just what you need

#812672

Link to comment
Share on other sites

This is how I understood you: You're writing that block of HTML once for each of the items. There are many such blocks to write, but you know how many there are. So in the loop that steps through the items, you can use the method given in this topic to update a progress bar showing how far along the script is in writing all the blocks.

All that appears to be answered already. What remains to be done?

;)

sry i should had asked a another way :blink:

Can i use this progress bar way in my code when i also have var's in my code (can i have var's in array).

I did try to convert my code like this

Global $aRegWrites[1450] = [['<html>'], _
[''], _
['<head>'], _
['<title>Booking</title>'], _
['<style type="text/css">'], _
['@media print {'], _
[''], _
['  @font-face {'], _
['      font-family: "Arial";'], _
['      src: url(arial.ttf);'], _
['  }'], _
....
[' </tr>'], _
['</table>'], _
['</body>'], _
['</html>']]

ProgressOn("Status", "", "")
For $n = 0 To UBound($aRegWrites) - 1
    fileWrite("C:\TEST.TEST", $n & $aRegWrites[$n] & ')' & @crLF)
    $iPercent = ($n + 1) / UBound($aRegWrites) * 100
    ProgressSet($iPercent, "Completed " & $n + 1 & " of " & UBound($aRegWrites), "$iPercent = " & $iPercent)
    Sleep(10)
Next
ProgressOff()

but i keep geting an error "wrong nesting in initializer" :>

Doohh Rex U'r :P first lerarn to create an array then ask the Q. :

Error fixed :nuke:

Cheers

/Rex

:Edit TypO

:Edit2 Strikeout

Edited by Rex
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...