Command Prompt Updating in HTA and Progress Bar

Change Page: < 12 | Showing page 2 of 2, messages 21 to 30 of 30
Author Message
morpheus83uk

  • Total Posts : 738
  • Scores: 0
  • Reward points : 0
  • Joined: 8/21/2006
  • Status: offline
RE: Command Prompt Updating in HTA and Progress Bar Wednesday, October 01, 2008 9:21 AM (permalink)
0
Hey there,
 
Thats amazing thank you ever so much for all your hard work and effort :)
 
I can now figure out the code from your comments and I will try and adapt it for other things :)
 
Also just a quick question is there a way of limiting the size of the progress bar so its smaller opposed to like the entire screen?
 
I will have a play with it anyways and get my head around it so I might post some questions about the code :)
 
Many Thanks
 
James
 
#21
    morpheus83uk

    • Total Posts : 738
    • Scores: 0
    • Reward points : 0
    • Joined: 8/21/2006
    • Status: offline
    RE: Command Prompt Updating in HTA and Progress Bar Thursday, October 02, 2008 1:20 AM (permalink)
    0
    Hello,
     
    I ahve sorted my little issue now :)
     
    I am now trying to modify it for various other things so I may post questions about the code so I understand it better.
     
    Many Thanks
     
    james
     
    #22
      Fredledingue

      • Total Posts : 572
      • Scores: 2
      • Reward points : 0
      • Joined: 5/9/2005
      • Location: Europe
      • Status: offline
      RE: Command Prompt Updating in HTA and Progress Bar Thursday, October 02, 2008 7:53 AM (permalink)
      0
      I'm glad to have worked on this code and that it could help you.
      I have learned a lot of things doing so, myself.
       
      This progress bar code can be used in many ways and practicaly each script has it differently. Just the main mathematical formulaes should stay the same.
       
      The width of the progress bar is set by the variable w. But I think you know that now. Reducing this number reduce the width of the bar without affecting it relative progression.
      Fred
       
      #23
        morpheus83uk

        • Total Posts : 738
        • Scores: 0
        • Reward points : 0
        • Joined: 8/21/2006
        • Status: offline
        RE: Command Prompt Updating in HTA and Progress Bar Friday, October 03, 2008 4:01 AM (permalink)
        0
        I am glad that you have learned alot of things as I am still learning HTA and playing around with it and still learning lots of about Visual basic Script...
         
        I am currently trying to get some other code to work so I am just having a play with things at the moment to see what works what does not and what not to touch :)
         
        Many Thanks for all your help and assistance its very much appreciated
         
        James
         
        #24
          Paulus88

          • Total Posts : 5
          • Scores: 0
          • Reward points : 0
          • Joined: 12/28/2011
          • Status: offline
          RE: Command Prompt Updating in HTA and Progress Bar Wednesday, December 28, 2011 7:20 AM (permalink)
          0
          Hi,
          I have been coding HTA for about 2 weeks now and am trying to produce the same thing as the guy who started this thread.
          I already have experience in PHP, but VBS is not my strong point.

          I created a few Backup batch files with Robocopy and am trying to combine them.

          This thread along with other threads on visualbasicscript.com have helped me get as far as i am now:

          My Code:
          <html>        
           <head>        
           <title id="title">Backup</title>        
           <HTA:APPLICATION         
           SCROLL="no"        
           MAXIMIZEBUTTON="no"/>        
           <LINK href=a.css rel=stylesheet type=text/css>        
           <SCRIPT Language="VBScript">        
           Public w,x,y        
           Const M=1048576        
           Set A=CreateObject("Scripting.FileSystemObject")        
           Set B=CreateObject("wscript.shell")        
           Set K=A.CreateTextFile(2, True)        
           K.Close        
           Set K=A.CreateTextFile(3, True)        
           K.Close        
           '-- w: bar width, x: done items, y: remaining items        
           Sub Window_Onload        
           window.resizeTo 800,600        
           w=50        
           Set C=A.OpenTextFile(1, 1)        
           y=C.ReadAll        
           C.Close        
           window.setInterval "Progress", 150        
           End Sub        
           Sub Progress        
           Set C=A.GetFolder("E:\Hello")        
           x=Int((C.Size))        
           Set F=window.document.getElementById("G")        
           Set L=window.document.getElementById("A")        
           Call G()        
           F.value=G        
           F.scrollTop=F.scrollTop+F.scrollHeight        
           Call I()        
           L.value=I        
           L.scrollTop=L.scrollTop+L.scrollHeight        
           d = Round( x / (y/w) +1  ,0)        
           document.Title="Running Backup " & FormatPercent(x/y, 0)        
           document.all.ProgBarText.innerText = FormatNumber(x/M,0) & " MB" & "/" & FormatNumber(y/M,0) & " MB"        
           document.all.ProgBarDone.innerText = String(d, "_")        
           If d<w Then        
           document.all.ProgBarToDo.innerText = String(w-d, "_") & "|"        
           Else        
           document.all.ProgBarToDo.innerText = "|"        
           End If        
           If x=y Then        
           document.all.ProgBarToDo.innerText = ""        
           MsgBox "ok"        
           window.close        
           End If        
           End Sub        
           Sub H_OnClick()        
           E=A.GetTempName        
           E=B.Environment("PROCESS")("TEMP") & "\" & E        
           D=B.Run("test2.bat >" & Chr(34) & E & Chr(34), 0, True)        
           End Sub        
           Function G()        
           With A.OpenTextFile(2)        
           If Not .AtEndOfStream Then        
           G=.ReadAll        
           End If        
           .Close        
           End With
           End Function        
           Function I()        
           With A.OpenTextFile(3)        
           If Not .AtEndOfStream Then I=.ReadAll        
           .Close        
           End With
           End Function        
           </SCRIPT>        
           </head>        
           <body bgcolor="#D7D7D7">        
           <input type=button id=H value=Test Me>        
           <span id="ProgBarText"></span><br />        
           <span id="ProgBarDone" style="background-color: #3399FF"></span>        
           <font color="#FFFFFF">        
           <span id="ProgBarToDo"style="background-color: #C0C0C0"></span>        
           </font><br />        
           <textarea id=G rows="30" cols="100" bgcolor="Green"></textarea><br />        
           <textarea style=overflow:hidden; id=A cols="4" bgcolor="Green">0</textarea>        
           </body>        
           </html>


          I like to make things compacted because this is going to be used on very slow computers in a business that uses thousands of computers.
          That's why i have all my variables named A,B,C,D,E,F,G,H,I,J,K and output files 1,2,3 without .txt on the end.

          This file will not copy the files from one area but a lot of different area's on the computer.

          How it works:
          Progress bar:
          1. Before this code runs I have a batch file which counts the amount of memory the backup. (this file is invisible)
          Batch file:
          setlocal enabledelayedexpansion        
           Set A="%programfiles%\folder1"        
           Set B="%programfiles%\folder2"        
           Set C="%userprofile%\folder1"        
           Set D="%userprofile%\folder2"        
           Set M=0        
           for /R %A% %%N in (*) do (set /a M=!M!+%%~zN)        
           for /R %B% %%N in (*) do (set /a M=!M!+%%~zN)        
           for /R %C% %%N in (*) do (set /a M=!M!+%%~zN)        
           for /R %D% %%N in (*) do (set /a M=!M!+%%~zN)        
           for /R D: %%N in (*) do (set /a M=!M!+%%~zN)        
           echo %M% > 1        
           endlocal

          2. This file then puts the total memory in bytes into file '1'.
          3. Set C=A.OpenTextFile(1, 1), y=C.ReadAll, y then = the value in file '1'.
          4. Set C=A.GetFolder("E:\Hello"), x=Int((C.Size)) x then = the total size of folder Hello. (The backup will make its own folder so it will be empty at the start of the backup)

          That is the progress bar, it works through the total memory transferred from the copy location to the destination for a more accurate result.

          When button (id=H) is pressed:
          Sub H_OnClick()
          E=A.GetTempName
          E=B.Environment("PROCESS")("TEMP") & "\" & E
          D=B.Run("test2.bat >" & Chr(34) & E & Chr(34), 0, True)
          End Sub
          Function G()

          Test2.bat starts with robocopy built in, this code also allows it to run invisible
          Robocopy code:
          if exist "%programfiles%\folder1" robocopy "%programfiles%\folder1" "E:\Hello" /E /NC /NDL /NJH /NJS /LOG+:"2" /LOG:"3"

          As you can see I am updating 2 different log files, file '2' and '3', this seems to work fine.

          If you can follow me so far, what i want to do now is get one textarea to show the % progress and the other one to show the completed file through robocopy.

          Set F=window.document.getElementById("G")
          Set L=window.document.getElementById("A")
          Sub Progress Call G()
          F.value=G
          F.scrollTop=F.scrollTop+F.scrollHeight
          Call I()
          L.value=I
          L.scrollTop=L.scrollTop+L.scrollHeight
          End Sub
          Sub Function G()
          With A.OpenTextFile(2)
          If Not .AtEndOfStream Then
          G=.ReadAll
          End If
          .Close
          End With
          End Function
          Function I()
          With A.OpenTextFile(3)
          If Not .AtEndOfStream Then I=.ReadAll
          .Close
          End With
          End Function

          This is the code i have created to read files '2' and '3' and put them into textarea G and A.

          I have tried all sorts of things, SkipLine, Skip(), ReadLine with a loop but i can't seem to edit out the % values of file '2' and only have the % values in file '3'.
          Any idea?

          If you manage to understand my code and can help me it would be greatly appreciated!

          Kind regards,
          Paul Hemmens
          <message edited by Paulus88 on Wednesday, December 28, 2011 7:46 AM>
           
          #25
            Paulus88

            • Total Posts : 5
            • Scores: 0
            • Reward points : 0
            • Joined: 12/28/2011
            • Status: offline
            RE: Command Prompt Updating in HTA and Progress Bar Thursday, December 29, 2011 6:22 AM (permalink)
            0
            I have been at this all day with no solution.

            The only thing i updated in my code was removed the two Functions and just put them into the loop with the rest of the code. Also changed Robocopy back to a single log file because i need to find a way to get the same log to show two different outputs in my two textareas.

            Set G=A.OpenTextFile(2)   
             If Not G.AtEndOfStream Then U=G.ReadAll   
             U=Replace(U,"%",1)   
             G.Close   
             End If   
             F.value=U   
             F.scrollTop=F.scrollTop+F.scrollHeight   
             Set G=A.OpenTextFile(2)   
             If Not G.AtEndOfStream Then I=G.ReadAll   
             I=Replace(U,"A",1)   
             G.Close   
             L.value=I   
             L.scrollTop=L.scrollTop+L.scrollHeight


            I discovered that i can easily edit the code with a replace function, changing the output in the textarea. What i need is a Line Remove function.
            If line has "%" in it delete line.

            Robocopy shows this now:
            Log File : C:\Users\User\Documents\test\2  
             
             16    C:\Users\User\Desktop\  
             403643    Backup instructie NL.pdf   
             0%     
             32%     
             64%     
             97%     
             100%     
             403397    Backup instruction EN.pdf   
             0%     
             32%     
             64%     
             97%     
             100%


            I want textarea G to show:
            16    C:\Users\User\Desktop\
            403643    Backup instructie NL.pdf
            Nothing more, remove the % values.

            Then textarea A must only show:
            0% 
            32% 
            64% 
            97% 
            100%
            No other values, this textarea will then only show one value at a time giving the illusion that it is working like Robocopy showing the completed % of every file.

            If I can get this to work I will write a simple version for this website to answer the question at the beginning of the forum thread.

            I hope to hear from someone, all i need is code that does: If line has "%" in it delete line. From a .ReadAll text file.

            Kind regards,
            Paul
            <message edited by Paulus88 on Thursday, December 29, 2011 6:30 AM>
             
            #26
              ebgreen

              • Total Posts : 8219
              • Scores: 98
              • Reward points : 0
              • Joined: 7/12/2005
              • Status: offline
              RE: Command Prompt Updating in HTA and Progress Bar Thursday, December 29, 2011 6:41 AM (permalink)
              0
              Well to be honest with you I'm too lazy to read through your code and give you a solution specifc to your code. Instead I'll just give you some pseudo-code that should let you write what you need:
               
              Set oFSO = CreateObject("Scripting.FileSystemObject")
              Set oldFile = oFSO.OpenTextFile("PATH\TO\FILE", ForReading)
              Set newFile = oFSO.CreateTextFile("PATH\TO\SOME\TEMP\FILE")
              For Each strLine in oldFile.ReadAll()
              If Not Instr(strLine, "%") > 0 Then
              newFile.WriteLine strLine
              End If
              Next
              oldFile.Close()
              newFile.Close()
              oFSO.DeleteFile "PATH\TO\FILE"
              oFSO.MoveFile "Path\TO\SOME\TEMP\FILE", "PATH\TO\FILE"
               
               
              Again, this is not real VBScript,but that should show you the basic process.
              "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
              Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
              http://www.visualbasicscript.com/m_47117/tm.htm
               
              #27
                Paulus88

                • Total Posts : 5
                • Scores: 0
                • Reward points : 0
                • Joined: 12/28/2011
                • Status: offline
                RE: Command Prompt Updating in HTA and Progress Bar Thursday, December 29, 2011 8:47 AM (permalink)
                0
                ebgreen


                Well to be honest with you I'm too lazy to read through your code and give you a solution specifc to your code. Instead I'll just give you some pseudo-code that should let you write what you need:

                Set oFSO = CreateObject("Scripting.FileSystemObject")
                Set oldFile = oFSO.OpenTextFile("PATH\TO\FILE", ForReading)
                Set newFile = oFSO.CreateTextFile("PATH\TO\SOME\TEMP\FILE")
                For Each strLine in oldFile.ReadAll()
                If Not Instr(strLine, "%") > 0 Then
                newFile.WriteLine strLine
                End If
                Next
                oldFile.Close()
                newFile.Close()
                oFSO.DeleteFile "PATH\TO\FILE"
                oFSO.MoveFile "Path\TO\SOME\TEMP\FILE", "PATH\TO\FILE"


                Again, this is not real VBScript,but that should show you the basic process.


                Thanks for the quick reply!
                I managed to get it working!
                Was trying to avoid creating another file to write the result because that means that Robocopy makes a log then VBS makes another temp file with the edited result, and then the textarea shows the temp file.

                This process costs a little extra work for the computer and the result is less accurate sync with Robocopy if you know what i mean.

                I have tried to get it to SkipLine instead of WriteLine, that would work a lot better and no extra temp file, but I can not seem to get it working.
                If you or anyone has any ideas on that I would be happy to hear them.

                I edited one peace of the code and that was to get each line in ReadAll you must first split them i think so i added:
                arrLine=oldFile.ReadAll
                arrLine=Split(arrLine, vbCrLf)
                For Each strLine in arrLine
                If Not Instr(strLine, "%") > 0 Then
                newFile.WriteLine strLine
                End If

                It does not work perfect yet, I think i have to edit the way Robocopy makes his log, but it is going in the right direction!

                Thanks a million and once it's finished I'll put a simple/readable version on this thread.

                Kind regards,
                Paul
                <message edited by Paulus88 on Thursday, December 29, 2011 8:50 AM>
                 
                #28
                  Paulus88

                  • Total Posts : 5
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 12/28/2011
                  • Status: offline
                  RE: Command Prompt Updating in HTA and Progress Bar Monday, January 02, 2012 6:17 PM (permalink)
                  0
                  I have nearly got it working without having to right to an output file.
                   
                  Set G = A.OpenTextFile(2)
                   If Not G.AtEndOfStream Then U = G.ReadAll
                   G.Close
                   Set F = window.document.getElementById("A")
                   Set L=window.document.getElementById("B")
                   U=Replace(U,"%","%##")
                   U=Replace(U,"  0%","##0%")
                   U=Replace(U,"  0.","##0.")
                   U=Replace(U,"100%","##100%")
                   U = Split(U,"##")
                   For Each P in U
                   P=Replace(P,"  ","")
                   P=Trim(P)
                   If Not InStr(P,"%") > 0 Then
                   P = F.innerTEXT & FvbCrLf & P
                   F.innerTEXT = P
                   F.scrollTop = F.scrollTop+F.scrollHeight
                   Else
                   L.innerTEXT=P
                   L.scrollTop=L.scrollTop+L.scrollHeight
                   End If
                   Next

                   
                  This code is in the same loop as the progress bar so it.
                   
                  Code breakdown:
                  Read text file if it is not at the end of stream. (U=G.RealAll)
                  Set G = A.OpenTextFile(2)
                  If Not G.AtEndOfStream Then U = G.ReadAll
                  G.Close
                   
                  Set textarea A and B.
                  Set F = window.document.getElementById("A")
                  Set L=window.document.getElementById("B")
                   
                  Split the code were ## has been added.
                  U=Replace(U,"%","%##")
                  U=Replace(U,"  0%","##0%")
                  U=Replace(U,"  0.","##0.")
                  U=Replace(U,"100%","##100%")
                  U = Split(U,"##")
                   
                  Put each split string into P and clean it up.
                  For Each P in U
                  P=Replace(P,"  ","")
                  P=Trim(P)
                   
                  Split the string up into 2 text areas. Were there is no % line goes into A and were there is a % goes into B. A includes the text that was already in A. (P = F.innerTEXT & FvbCrLf & P)
                  If Not InStr(P,"%") > 0 Then
                  P = F.innerTEXT & FvbCrLf & P
                  F.innerTEXT = P
                  F.scrollTop = F.scrollTop+F.scrollHeight
                  Else
                  L.innerTEXT=P
                  L.scrollTop=L.scrollTop+L.scrollHeight
                  End If
                  Next
                   
                  There is one big problem with this, if the text file is .AtEndOfStream the loop starts all over again and P= The same value as what is already in the textarea till a split then P= one line which.
                   
                  I tried removing the .innerTEXT from P when its there, but sometimes the .innerTEXT is just a bit different from the new P string.
                  P=Replace(P,F.innerTEXT,"")
                  P = F.innerTEXT & FvbCrLf & P
                   
                  What i need is a way of reading the text file in the loop were it left of reading it, or a buffer were i can temp save the file too. This would be faster than writing it into a file.
                   
                  Anyone give me any ideas?
                   
                  Thanks!
                   
                  Kind regards,
                  Paul
                   
                  #29
                    Paulus88

                    • Total Posts : 5
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 12/28/2011
                    • Status: offline
                    RE: Command Prompt Updating in HTA and Progress Bar Tuesday, January 03, 2012 10:59 AM (permalink)
                    0
                    This is the only thing I need to finish the code but just cannot seem to find it anywhere.

                    U = G.ReadAll is in a loop while the text file is busy updating. Next loop it will read the whole text file again making the output in the textarea repeat itself a bit more every time.

                    If there was a way to get U=G.ReadAll & "Hello", then ReadAll after the word Hello during the next loop.

                    That would work, I have tried ReadLine and then adding lines and also tried creating a 3rd textarea as buffer (id=Z):
                    Set K=window.document.getElementById("Z")
                    Set G = A.OpenTextFile(2)
                    If Not G.AtEndOfLine Then U = G.ReadAll
                    T=Replace(U,K.innerTEXT,"")
                    K.innerTEXT = U

                    This should then remove the text from 'U' that had already been used the last time and put the result into 'T', but this only seems to work for the first few loops and then it starts repeating itself again.

                    I actually don't know why this doesn't work, I think it has something to do with U being a String and K.innerTEXT does not match up with U after the first few loops.

                    Are there any other simple commands that can solve this issue?
                    Continue .ReadAll from were .ReadAll left off before the loop.

                    Thanks,
                    Paul
                    <message edited by Paulus88 on Tuesday, January 03, 2012 11:08 AM>
                     
                    #30

                      Online Bookmarks Sharing: Share/Bookmark
                      Change Page: < 12 | Showing page 2 of 2, messages 21 to 30 of 30

                      Jump to:

                      Current active users

                      There are 0 members and 1 guests.

                      Icon Legend and Permission

                      • New Messages
                      • No New Messages
                      • Hot Topic w/ New Messages
                      • Hot Topic w/o New Messages
                      • Locked w/ New Messages
                      • Locked w/o New Messages
                      • Read Message
                      • Post New Thread
                      • Reply to message
                      • Post New Poll
                      • Submit Vote
                      • Post reward post
                      • Delete my own posts
                      • Delete my own threads
                      • Rate post

                      2000-2012 ASPPlayground.NET Forum Version 3.9