Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/28/2011 in all areas

  1. Func _UnicodeToANSI($sString) #cs Local Const $SF_ANSI = 1 Local Const $SF_UTF16_LE = 2 Local Const $SF_UTF16_BE = 3 Local Const $SF_UTF8 = 4 #ce Local Const $SF_ANSI = 1, $SF_UTF8 = 4 Return BinaryToString(StringToBinary($sString, $SF_UTF8), $SF_ANSI) EndFunc ;==>_UnicodeToANSI
    2 points
  2. guinness

    Removable Drive Help

    chachew, you might want to remove the String conversion part.
    1 point
  3. Presumably, the Excel string was obtained via COM, so it's a native (~UTF-16 LE) string, not UTF-8. Even if it comes from a file, then it's probably be UTF-8 in the file, but at the time where it's read by AutoIt, it should become a native AutoIt (~UTF-16LE) string.
    1 point
  4. guinness

    Update my program ?

    MrVietA2, I don't know if you're still interested but I added the speed of the download to my two previous examples. You're very welcome.
    1 point
  5. guinness

    Update my program ?

    Using timers as suggested. I will update the code later on today* to include the speed of the download. Edit: * = or tomorrow.
    1 point
  6. guinness

    Help With Progress Bar

    And an Example using a GUI. It's slightly different to >> Also this is an example which of course can be improved upon! I hope it gives you inspiration to look into creating GUI's Function: ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetGUI ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file updating a GUICtrlCreateProgress. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetGUI: Download a file updating a GUICtrlCreateProgress. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_ ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetGUI() ; Description ...: Download a file updating a GUICtrlCreateProgress(). ; Syntax.........: _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, [$sDirectory = @ScriptDir]) ; $sURL - A valid URL that contains the filename too. ; $iLabel - ControlID of a GUICtrlCreateLabel. ; $iProgress - ControlID of a GUICtrlCreateProgress. ; $iButton - ControlID of a GUICtrlCreateButton. ; $sDirectory - [Optional] Directory of where to download to. Default = @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ; Failure - Returns downloaded filename & sets @error = 1 (@extended = 0 if internal error or @extended = 1 if cancelled was selected.) ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, $sDirectory = @ScriptDir) Local $hDownload, $iBytesRead = 0, $iError = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sRead = GUICtrlRead($iButton), $sSpeed $sFilePath = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFilePath) EndIf $sDirectory = StringRegExpReplace($sDirectory, "[\\/]+\z", "") & "\" & $sFilePath $iFileSize = InetGetSize($sURL, 1) $hDownload = InetGet($sURL, $sDirectory, 0, 1) If @error Then Return SetError(1, $iError, $sFilePath) EndIf GUICtrlSetData($iButton, "&Cancel") $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iTimer = TimerInit() While InetGetInfo($hDownload, 2) = 0 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iButton GUICtrlSetData($iLabel, "Download Cancelled!") $iError = 1 ExitLoop EndSwitch $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed GUICtrlSetData($iLabel, $sProgressText) GUICtrlSetData($iProgress, $iPercentage) If TimerDiff($iTimer) > 1000 Then $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iSpeed = $iBytesRead $iTimer = TimerInit() EndIf Sleep(100) WEnd InetClose($hDownload) GUICtrlSetData($iButton, $sRead) Return SetError($iError, $iError, $sFilePath) EndFunc ;==>_InetGetGUI ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2) Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================Example use of Function: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> _Main() Func _Main() Local $sFilePathURL = "http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe" Local $hGUI, $iButton, $iLabel, $iProgressBar, $sFilePath $hGUI = GUICreate("_InetGetGUI()", 370, 90, -1, -1) $iLabel = GUICtrlCreateLabel("Welcome to the simple Downloader!", 5, 5, 270, 40) $iButton = GUICtrlCreateButton("&Download", 275, 2.5, 90, 25) $iProgressBar = GUICtrlCreateProgress(5, 60, 360, 20) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iButton $sFilePath = _InetGetGUI($sFilePathURL, $iLabel, $iProgressBar, $iButton, @ScriptDir) If @error Then Switch @extended ; Check what the actual error was by using the @extended command. Case 0 MsgBox(64, "Error", "Check the URL or your Internet Connection!") Case 1 MsgBox(64, "Fail", "Seems the download was canecelled, but the file was >> " & $sFilePath) EndSwitch Else MsgBox(64, "Success", "Downloaded >> " & $sFilePath) EndIf EndSwitch WEnd EndFunc ;==>_Main
    1 point
  7. mattw112

    SciTE Folding

    When working in SciTE I love the ability to fold sections of code up. but every time I compile or build my script all the folds are undone... and they go back to being unfolded. Which gets really annoying when I'm doing quick things back and forth troubleshooting. Is there a way to stop this? Thanks, Terry
    1 point
  8. mattw112

    SciTE Folding

    Perfect, thanks. Terry
    1 point
×
×
  • Create New...