Jump to content
Sign in to follow this  
SimpleC

Rounding decimal down

Recommended Posts

SimpleC

Hello everybody! 

I'm having trouble with rounding.  The program I'm using rounds decimals down. Autoit's round function rounds them up.

Example:

round(174.126, 2) = 174.13

I need that round to be 174.12.   

 

Here's the actually script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:Program FilesAutoinstallForm1.kxf
$Form1 = GUICreate("AutoCalc", 227, 200, 15, 15, $WS_EX_TOPMOST)
$Button1 = GUICtrlCreateButton("Calculate", 8, 144, 99, 25)
$Button2 = GUICtrlCreateButton("Close", 120, 144, 91, 25)
$Label4 = GUICtrlCreateLabel("", 72, 136, 4, 4)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Input", 8, 8, 209, 129)
$Label1 = GUICtrlCreateLabel("Rate", 16, 32, 27, 17)
$Label2 = GUICtrlCreateLabel("Number of Nights", 16, 64, 86, 17)
$Input1 = GUICtrlCreateInput("0.00", 112, 24, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
$Label3 = GUICtrlCreateLabel("Total", 16, 96, 45, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("1", 112, 56, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
;$Label5 = GUICtrlCreateLabel("0.00", 136, 96, 39, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
   case $Button1
   ;$val = round((((((GUICtrlRead($input1) * .1545) + GUICtrlRead($input1)) + 1.5 + .13) * GUICtrlRead($input2))), 2)
   $val = (((((GUICtrlRead($input1) * .1545) + GUICtrlRead($input1)) + 1.5 + .13) * GUICtrlRead($input2)))
   $Label5 = GUICtrlCreateLabel($val, 136, 96, 39, 28)
   case $Button2
   Exit
 EndSwitch
WEnd

Share this post


Link to post
Share on other sites
Melba23

SimpleC,

Interesting. My first thought was to use StringFormat - but that function seems to use Round too: :(

$sRet = StringFormat("%.2f", String(174.126))
MsgBox(0, "Result", $sRet)
So it seems you will need to use a wrapper function like this:

$nRet = _RoundDown(174.126, 2)
MsgBox(0, "Result", $nRet)

; Long version
Func _RoundDown($nVar, $iCount)
    ; Move the decimal point
    $nMult = $nVar * (10 ^ $iCount)
    ; Remove remaining decimals
    $iRound = Int($nMult)
    ; Move decimal point back again
    $nRoundDown = Round($iRound / (10 ^ $iCount), $iCount)
    Return $nRoundDown
EndFunc

; Short version
Func _RoundDown($nVar, $iCount)
    Return Round((Int($nVar * (10 ^ $iCount))) / (10 ^ $iCount), $iCount)
EndFunc
That seems to work, :)

 

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Starg

Try this:

Round(174.126 - 0.005 , 2)
Edit:

Melba23 was faster!

Edited by Starg

Share this post


Link to post
Share on other sites
BrewManNH

Round by definition will round the number up or down to the nearest number with the specified decimal places. If 5 or above, it will round up, if 0 to 4 will round down. The only thing I can think of would be to take the number, multiply it by 10*(the number of decimal places you want) and then use Intinstead of round, and divide by what you multiplied by. Something like this change to your code.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=C:\Program Files\Auto\install\Form1.kxf
$Form1 = GUICreate("AutoCalc", 227, 200, 15, 15, $WS_EX_TOPMOST)
$Button1 = GUICtrlCreateButton("Calculate", 8, 144, 99, 25)
$Button2 = GUICtrlCreateButton("Close", 120, 144, 91, 25)
$Label4 = GUICtrlCreateLabel("", 72, 136, 4, 4)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Group1 = GUICtrlCreateGroup("Input", 8, 8, 209, 129)
$Label1 = GUICtrlCreateLabel("Rate", 16, 32, 27, 17)
$Label2 = GUICtrlCreateLabel("Number of Nights", 16, 64, 86, 17)
$Input1 = GUICtrlCreateInput("0.00", 112, 24, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT))
$Label3 = GUICtrlCreateLabel("Total", 16, 96, 45, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("1", 112, 56, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_RIGHT))
$Label5 = GUICtrlCreateLabel("0.00", 136, 96, 39, 28)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $Tax = .1545
            $Rate = GUICtrlRead($Input1)
            $LengthStay = GUICtrlRead($Input2)
            $val = Int(((((($Rate * $Tax) + $Rate) + 1.5 + .136) * $LengthStay)) * 10 ^ 2) / 10 ^ 2
;~          $val = (((((GUICtrlRead($input1) * .1545) + GUICtrlRead($input1)) + 1.5 + .13) * GUICtrlRead($input2)))
            GUICtrlSetData($Label5, $val)
        Case $Button2
            Exit
    EndSwitch
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
SimpleC

I think Melba's is correct.  Thank you for the quick responses!  :thumbsup:

Share this post


Link to post
Share on other sites
macargu

Hello everybody! 

I'm having trouble with rounding.  The program I'm using rounds decimals down. Autoit's round function rounds them up.

Example:

round(174.126, 2) = 174.13

I need that round to be 174.12.   

 

Unless I am not understanding something here, but it would seem to me that the program is just trimming off everything after the second digit to the right of the decimal point.

To achieve that, I would do the following:

$Var = 174.126

; Splitting the number into its components, using the decimal point as separator:

$SplitVar = StringSplit($Var, ".")  ;  $SplitVar[1]= 174 ; $SplitVar[2]= 126

; Trimming the decimal component to two digits:

$SplitVar[2] = StringLeft($SplitVar[2], 2)  ;  $SplitVar[2] = 12

; Joining both components back together

$FinalVar = $SplitVar[1] & "." & $SplitVar[2])  ;  $FinalVar = 174.12

I hope I am not saying something really stupid!

Share this post


Link to post
Share on other sites
jchd

macargu

Indeed one can work on the string representation as well, and even make that a one-liner by trimming or as a regexp replacement.

But I bet that it would be more costly this way since that involves 2 costly conversions (double <==> string) plus string operation(s).

kylomas

BTW, trimming needs a bit more caution unless you already know in advance how many positions the decimal part has. Furthermore, it would fail as is on integral values.

Pffft, too many edits.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Melba23

macargu,

Welcome to the AutoIt forum. :)

Your suggestion is perfectly valid - there are often several ways of reaching the same destination. Incidentally, the new Beta allows you to do this in just one line:

$nVar = 174.126

$nRounded = StringSplit($nVar, ".")[1] & "." & StringLeft(StringSplit($nVar, ".")[2], 2)

ConsoleWrite($nRounded & @CRLF)

Pretty nifty - if a little complex at first glance. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
kylomas

@jchd - Yes, you're probably right but AutoIT handles the conversion Ok

local $a = 1.55

ConsoleWrite(stringtrimright($a,1) * 2 & @LF)

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
jchd

Of course it does!

I meant from a performance point of view. If you invoke that once in a blue moon, fine. If it's in a tight loop, it might slow things down.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
kylomas

@jchd - Understood

BTW, trimming needs a bit more caution unless you already know in advance how many positions the decimal part has. Furthermore, it would fail as is on integral values.

 

I agree, it's a kludgy solution

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
jchd

For strings either Melba's 1-liner or a regexp are fine. But if the user wants strings and a fixed 2-digit decimal part, he has to cope with integers.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
macargu

macargu,

Welcome to the AutoIt forum. :)

Your suggestion is perfectly valid - there are often several ways of reaching the same destination. Incidentally, the new Beta allows you to do this in just one line:

$nVar = 174.126

$nRounded = StringSplit($nVar, ".")[1] & "." & StringLeft(StringSplit($nVar, ".")[2], 2)

ConsoleWrite($nRounded & @CRLF)

Pretty nifty - if a little complex at first glance. ;)

M23

 

Thank you, Melba23.

I am really glad to see that an experienced coder as yourself used the exact same logic I, a beginner, did, only you did it in a sintactically compact, more efficient and elegant way. What took me 3 rows, you did in one. Very clear, very nice.

Macargu

Share this post


Link to post
Share on other sites
BrewManNH

My solution was a single line as well, and the result is the same. :D


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kylomas

@BrewmanNH - Nice!  Can you explain why this works (math illiterate)

local $a = 1.737
; 1 dec place
ConsoleWrite((int($a*10^1)/10^1) * 2 & @LF)
; 2 dec place
ConsoleWrite((int($a*10^2)/10^2) * 2 & @LF)

kylomas

edit: shopping for new fingers that can actually type

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
BrewManNH

Your first example is multiplying the number by 10, removing anything past the decimal point 1.737 * 10 = 17.37, take the integer portion of that, 17, divide by 10 to get 1.7.

The second is the same except you're multiplying  and dividing by 100 in this case, so you get 1.73.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
kylomas

@BrewmanNH - Shifting the decimal and dividing the int, of course (obvious when you see the solution). Thanks for the explanation!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
macargu

My solution was a single line as well, and the result is the same. :D

 

Yes. Very nice solution, BrewManNH.

Macargu

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • chacoya121
      By chacoya121
      send("{Down Down}") sleep(1000) send("{Down Up}") just curious on the send function
      i try but doesn't work some how
    • BlazerV60
      By BlazerV60
      Hi all,
      I currently have this small script here:
      $T_INIT = TimerInit() Do Send("{DEL down}") Until TimerDiff($T_INIT) >= 2000 ;2000 miliseconds = 2 seconds, exactly how long it takes to delete one entire row in Microsoft Word Send("{DEL up}") What the above code does is hold down the delete key for 2 seconds.
      How would I make this script do the exact same thing if I had "DEL" as a variable? For example something like this: (Which by the way doesn't work)
      $ChosenKey = "DEL" $T_INIT = TimerInit() Do Send("{$ChosenKey& down}") Until TimerDiff($T_INIT) >= 2000 Send("{$ChosenKey& up}") All the parenthesis and "&" symbols and brackets make this difficult.
    • CarlD
      By CarlD
      This code is a subset of an AutoIt tool I wrote for the classic DOS word-processor XyWrite. The tool allows 7-bit Ascii encoding of XyWrite Programming Language programs, with "readability aids" that mimic the way this code looks natively on the DOS screen. This is a special 7-bit encoding that we've used for many years in the XyWrite community to discuss XPL code on the XyWrite Mailing List. But that's neither here nor there.
      The present subset consists of three utilities, which I offer here for what they're worth. The first, DVIEW.AU3, takes a binary file and displays it in the default Windows text editor, displaying only Ascii chars 32-127, the other chars being represented by ".". The command-line usage is:
      DVIEW.AU3 <file_in><Enter>
      The second, DREAD.AU3 (that's "Dee-Read", not "dread" ), provides a similar display, except that characters outside the Ascii 32-127 range are represented by "{nnn}", where "nnn" is the 3-digit decimal Ascii number. (The initial "D" in these utilities' names stands for "decimal".) The output from DREAD.AU3 can be edited to make simple patches to binary files. The output file is named DREAD.TXT. The usage is:
      DREAD.AU3 <file_in><Enter>
      The third utility, DWRITE.AU3, takes DREAD output and writes it back to disk as a binary file. So, once you edit the output from DREAD, you write it to disk with:
      DWRITE.AU3 <file_in><Enter>
      The default file_in is DREAD.TXT -- i.e., the output of DREAD.AU3. The output file is named DWRITE.BIN, which can be renamed as desired.
      You'll see that each of these scripts processes the input file character by character. If there's a faster way of doing this, for example by manipulating bit patterns, I'd be pleased to hear about it.
      Here are the three scripts. Enjoy.
      ; DVIEW.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Display a decimal view of a binary file ; ; Usage: ; DREAD.AU3 file_in ProgressOn(@ScriptName,"Working") Global $iLnLen = 0; Line length meter Local $sTmp = ""; Temp string var Local $sInFile = @ScriptDir & "\DVIEW.IN" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DVIEW.TMP" Local $sOutFile = @ScriptDir & "\DVIEW.TXT" If FileExists($sTmpFile) Then FileDelete($sTmpFile) If FileExists($sOutFile) Then FileDelete($sOutFile) Local $hWrIn = FileOpen($sInFile, 16); Handle for source file Local $sToEncode = FileRead($hWrIn); Binary (hex) string to encode FileClose($hWrIn) Global $sEncoded = ""; Encoded output (string) Local $aEncoded = HexToDec($sToEncode); Binary (hex) to decimal array Local $iAsc = ""; Decimal Ascii number of current char ; Loop through each byte of input string For $i = 1 To UBound($aEncoded) - 1 $iAsc = StringFormat("%03u", $aEncoded[$i]) $sTmp = "" If $iAsc > 31 And $iAsc < 128 Then $sTmp = Chr($aEncoded[$i]) Else $sTmp = "." EndIf $sTmp = AddCrLf($sTmp) If $iLnLen = 0 And $sTmp = "." Then $sTmp = "{046}" If $iLnLen = 0 And $sTmp = ">" Then $sTmp = "{062}" $sEncoded &= $sTmp Next ; Trim double CrLf to one; change trailing space to "{032}" If StringRight($sEncoded, 2) = @CRLF Then _ $sEncoded = StringTrimRight($sEncoded, 2) If StringRight($sEncoded, 1) = " " Then _ $sEncoded = StringTrimRight($sEncoded, 1) & "{032}" ; Add header and footer Local $sHeader = "DVIEW v1.0" & @CRLF $sEncoded = $sHeader & "b-gin [" & $sInFile & "]" & @CRLF & _ $sEncoded & @CRLF & "-nd DVIEW" & @CRLF ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sEncoded) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressSet(100, "Done") Sleep(2000) ProgressOff() ShellExecute($sOutFile) ; --------- Function DeFinitions --------- Func HexToDec($sHexIn); Convert hex string to decimal array $aHexChars = StringSplit($sHexIn, "") Local $aHexIn[UBound($aHexChars) / 2] Local $j = 0 For $i = 1 To UBound($aHexChars) Step 2 If $i + 1 <= UBound($aHexChars) Then $aHexIn[$j] = $aHexChars[$i] & $aHexChars[$i + 1] $j += 1 Else ExitLoop EndIf Next Local $aDecOut[UBound($aHexIn)] For $i = 0 To UBound($aHexIn) - 1 $aDecOut[$i] = Dec($aHexIn[$i]) Next Return $aDecOut EndFunc ;==>HexToDec Func AddCrLf($sIn); Add line breaks to output $iLnLen += StringLen($sIn) If $iLnLen > 74 Then $sIn &= @CRLF $iLnLen = 0 EndIf Return $sIn EndFunc ;==>AddCrLf ; DREAD.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Display a decimal view of a binary file ; ; Usage: ; DREAD.AU3 file_in ProgressOn(@ScriptName,"Working") Global $iLnLen = 0; Line length meter Local $sTmp = ""; Temp string var Local $sInFile = @ScriptDir & "\DREAD.IN" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DREAD.TMP" Local $sOutFile = @ScriptDir & "\DREAD.TXT" If FileExists($sTmpFile) Then FileDelete($sTmpFile) If FileExists($sOutFile) Then FileDelete($sOutFile) Local $hWrIn = FileOpen($sInFile, 16); Handle for source file Local $sToEncode = FileRead($hWrIn); Binary (hex) string to encode FileClose($hWrIn) Global $sEncoded = ""; Encoded output (string) Local $aEncoded = HexToDec($sToEncode); Binary (hex) to decimal array Local $iAsc = ""; Decimal Ascii number of current char ; Loop through each byte of input string For $i = 1 To UBound($aEncoded) - 1 $iAsc = StringFormat("%03u", $aEncoded[$i]) $sTmp = "" If $iAsc > 31 And $iAsc < 128 Then $sTmp = Chr($aEncoded[$i]) Else $sTmp = "{" & $iAsc & "}" EndIf $sTmp = AddCrLf($sTmp) If $iLnLen = 0 And $sTmp = "." Then $sTmp = "{046}" If $iLnLen = 0 And $sTmp = ">" Then $sTmp = "{062}" $sEncoded &= $sTmp Next ; Trim double CrLf to one; change trailing space to "{032}" If StringRight($sEncoded, 2) = @CRLF Then _ $sEncoded = StringTrimRight($sEncoded, 2) If StringRight($sEncoded, 1) = " " Then _ $sEncoded = StringTrimRight($sEncoded, 1) & "{032}" ; Add header and footer Local $sHeader = "DeeREAD v1.0" & @CRLF $sEncoded = $sHeader & "b-gin [" & $sInFile & "]" & @CRLF & _ $sEncoded & @CRLF & "-nd DeeREAD" & @CRLF ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sEncoded) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressSet(100, "Done") Sleep(2000) ProgressOff() ShellExecute($sOutFile) ; --------- Function DeFinitions --------- Func HexToDec($sHexIn); Convert hex string to decimal array $aHexChars = StringSplit($sHexIn, "") Local $aHexIn[UBound($aHexChars) / 2] Local $j = 0 For $i = 1 To UBound($aHexChars) Step 2 If $i + 1 <= UBound($aHexChars) Then $aHexIn[$j] = $aHexChars[$i] & $aHexChars[$i + 1] $j += 1 Else ExitLoop EndIf Next Local $aDecOut[UBound($aHexIn)] For $i = 0 To UBound($aHexIn) - 1 $aDecOut[$i] = Dec($aHexIn[$i]) Next Return $aDecOut EndFunc ;==>HexToDec Func AddCrLf($sIn); Add line breaks to output $iLnLen += StringLen($sIn) If $iLnLen > 74 Then If $sIn = " " Then $sIn = "{032}" $sIn &= @CRLF $iLnLen = 0 EndIf Return $sIn EndFunc ;==>AddCrLf ; DWRITE.AU3 -- AutoIt v3 [CarlD rev.9/27/15] ; Write DVIEW encoding as binary file ; ; Usage: ; DWRITE.AU3 file_in ; Output is sent to @ScriptDir & "DWRITE.BIN" ProgressOn(@ScriptName,"Working") Local $sInFile = @ScriptDir & "\DREAD.TXT" If $CmdLine[0] > 0 Then $sInFile = $CmdLine[1] If Not FileExists($sInFile) Then ProgressOff() MsgBox(16, @Scriptname, $sInFile & " does not exist!", 3) Exit EndIf Local $sTmpFile = @ScriptDir & "\DWRITE.TMP" Local $sOutFile = @ScriptDir & "\DWRITE.BIN" Local $hWrIn = FileOpen($sInFile); Handle for source file Local $sMaster = FileRead($hWrIn); Master string to decode FileClose($hWrIn) Local $sToDecode = "" Local $aTmp = "" ; Remove header|footer If StringLeft($sMaster, 9) = "DeeREAD v" Then _ $sMaster = StringTrimLeft($sMaster, StringInStr($sMaster, "]")) If StringRight($sMaster, 13) = "-nd DeeREAD" & @CRLF Then _ $sMaster = StringTrimRight($sMaster, 13) Local $sFinished = "" Local $iChunkSz = 512 Local $iAdd = 0 ; - - - - - - Main Loop - - - - - - While $sMaster If StringLen($sMaster) > $iChunkSz Then $sToDecode = StringLeft($sMaster, $iChunkSz) $sMaster = StringTrimLeft($sMaster, $iChunkSz) If StringRight($sToDecode, 2) <> @CRLF Then $iAdd = 1 + StringInStr($sMaster, @CRLF) $sToDecode &= StringLeft($sMaster, $iAdd) $sMaster = StringTrimLeft($sMaster, $iAdd) EndIf Else $sToDecode = $sMaster $sMaster = "" EndIf ; Strip CrLfs $sToDecode = StringReplace($sToDecode, @CRLF, "") ; "{nnn}" ==> 1-byte Ascii char; Local $aTmp = StringSplit($sToDecode, "{") Local $iAsc = -1 For $i = 1 To UBound($aTmp) - 1 $iAsc = StringLeft($aTmp[$i], 3) If StringInStr($aTmp[$i], "}") = 4 And _ StringIsDigit($iAsc) Then If $iAsc > -1 And $iAsc < 256 Then $sToDecode = StringReplace($sToDecode, "{" & _ StringLeft($aTmp[$i], 4), Chr($iAsc)) EndIf EndIf Next $sFinished &= $sToDecode $sToDecode = "" WEnd ; - - - - - End Main Loop - - - - - ; Write output file Local $hWrOut = FileOpen($sTmpFile, 2) FileWrite($sTmpFile, $sFinished) FileClose($hWrOut) FileMove($sTmpFile, $sOutFile, 1) ProgressOff() MsgBox(0, @ScriptName, "Output in " & $sOutFile, 5) ; Done
    • zelles
      By zelles
      WalletSync, Sync/Backup your crypto-currency wallets.
      **Version 0.0.0.2 has been released adding the option to sync by FTP and not just locally.
      This program will sync any wallet.dat files found in their default location, AppData/Roaming/*/wallet.dat... The program will make a copy of all the wallets in a SyncData folder found in the script directory where WalletSync is run.
      The sync runs once every minute and can be minimized to the system tray to constantly stay syncing, a backup, in the background.
      Version 0.0.0.2 Source Code:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icon.ico #AutoIt3Wrapper_Res_Comment=Keep a sync'd backup of your crypto currency wallets locally and optionally with a FTP server. #AutoIt3Wrapper_Res_Description=Keep a sync'd copy of all the crypto-currency wallet.dats found in there default locations on you PC. #AutoIt3Wrapper_Res_Fileversion=0.0.0.2 #AutoIt3Wrapper_Res_LegalCopyright=Copyright 2014 zelles #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;#NoTrayIcon #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <FTPEx.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <Misc.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <TrayConstants.au3> #include <WindowsConstants.au3> _Singleton("zellesWalletSync2") OnAutoItExitRegister("CloseSync") Opt("TrayMenuMode", 3) Global $SYNC_OPERATION = False If Not FileExists(@ScriptDir & "\WalletSync_temp") Then DirCreate(@ScriptDir & "\WalletSync_temp") FileInstall("C:\AIP\Logo.jpg", @ScriptDir & "\WalletSync_temp\Logo.jpg") If Not FileExists(@ScriptDir & "\config.ini") Then IniWriteSection(@ScriptDir & "\config.ini", "config", "speed=60") IniWrite(@ScriptDir & "\config.ini", "config", "ftpserver", "none") IniWrite(@ScriptDir & "\config.ini", "config", "ftpport", "21") IniWrite(@ScriptDir & "\config.ini", "config", "ftpusername", "none") IniWrite(@ScriptDir & "\config.ini", "config", "ftppassword", "none") EndIf Global $SYNC_SPEED = IniRead(@ScriptDir & "\config.ini", "config", "speed", "60") Global $SYNC_FTPSERVER = IniRead(@ScriptDir & "\config.ini", "config", "ftpserver", "none") Global $SYNC_FTPPORT = IniRead(@ScriptDir & "\config.ini", "config", "ftpport", "21") Global $SYNC_FTPUSER = IniRead(@ScriptDir & "\config.ini", "config", "ftpusername", "none") Global $SYNC_FTPPASS = IniRead(@ScriptDir & "\config.ini", "config", "ftppassword", "none") Global $GUI_Wallet_Sync = GUICreate("WalletSync, created by zelles", 370, 189, 245, 163) GUISetBkColor(0xFFFFFF) Global $GUI_Tab1 = GUICtrlCreateTab(5, 5, 361, 177) Global $GUI_TabSheet1 = GUICtrlCreateTabItem("Overview") Global $GUI_Logo = GUICtrlCreatePic(@ScriptDir & "\WalletSync_temp\Logo.jpg", 17, 46, 100, 100) Global $GUI_Group1 = GUICtrlCreateGroup("Sync Options", 119, 55, 233, 89) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $GUI_CheckboxLocal = GUICtrlCreateCheckbox("Local", 135, 79, 57, 17) GUICtrlSetState($GUI_CheckboxLocal, $GUI_CHECKED) GUICtrlSetState($GUI_CheckboxLocal, $GUI_DISABLE) Global $GUI_CheckboxFTP = GUICtrlCreateCheckbox("FTP", 135, 111, 57, 17) Global $GUI_CheckboxOther1 = GUICtrlCreateCheckbox("Other", 199, 79, 57, 17) GUICtrlSetState($GUI_CheckboxOther1, $GUI_DISABLE) Global $GUI_CheckboxOther2 = GUICtrlCreateCheckbox("Other", 199, 111, 57, 17) GUICtrlSetState($GUI_CheckboxOther2, $GUI_DISABLE) Global $GUI_ButtonStart = GUICtrlCreateButton("Start", 266, 75, 75, 25) Global $GUI_ButtonStop = GUICtrlCreateButton("Stop", 266, 107, 75, 25) GUICtrlSetState($GUI_ButtonStop, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GUI_TabSheet2 = GUICtrlCreateTabItem("Status") Global $GUI_Group6 = GUICtrlCreateGroup("Current Sync Status", 21, 65, 329, 73) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $GUI_SyncStatus = GUICtrlCreateLabel("Sync is turned off...", 40, 96, 294, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GUI_TabSheet3 = GUICtrlCreateTabItem("Local") Global $GUI_Group2 = GUICtrlCreateGroup("Local Output", 22, 64, 329, 73) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $GUI_InputLocalOutput = GUICtrlCreateInput(@ScriptDir & "\SyncData", 35, 92, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GUI_TabSheet4 = GUICtrlCreateTabItem("FTP") Global $GUI_Group5 = GUICtrlCreateGroup("FTP Settings", 21, 49, 329, 105) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $GUI_Label2 = GUICtrlCreateLabel("Server:", 37, 73, 38, 17) Global $GUI_Label3 = GUICtrlCreateLabel("Port:", 37, 97, 26, 17) Global $GUI_Label1 = GUICtrlCreateLabel("Username:", 189, 73, 55, 17) Global $GUI_Label4 = GUICtrlCreateLabel("Password:", 189, 97, 53, 17) Global $GUI_InputFTPServer = GUICtrlCreateInput($SYNC_FTPSERVER, 79, 70, 105, 21) Global $GUI_InputFTPPort = GUICtrlCreateInput($SYNC_FTPPORT, 79, 94, 105, 21) Global $GUI_InputFTPUsername = GUICtrlCreateInput($SYNC_FTPUSER, 247, 70, 89, 21) Global $GUI_InputFTPPassword = GUICtrlCreateInput($SYNC_FTPPASS, 247, 94, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) Global $GUI_ButtonFTPUpdate = GUICtrlCreateButton("Update", 264, 120, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $GUI_TabSheet6 = GUICtrlCreateTabItem("Scanner") Global $GUI_Group4 = GUICtrlCreateGroup("Sync Scanner", 21, 33, 329, 137) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Global $GUI_ComboSpeed = GUICtrlCreateCombo("1 minute", 40, 56, 209, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($GUI_ComboSpeed, "5 minutes|10 minutes|30 minutes|1 hour", "1 minute") Global $GUI_ButtonUpdateSpeed = GUICtrlCreateButton("Update", 256, 56, 75, 21) Global $GUI_Wallets_Found = GUICtrlCreateList("", 120, 88, 209, 69, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_VSCROLL)) Global $GUI_Label5 = GUICtrlCreateLabel("Wallets Found:", 40, 86, 75, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW, $GUI_Wallet_Sync) Global $GUI_Tray_Open = TrayCreateItem("Open WalletSync") TrayCreateItem("") Global $GUI_Tray_Exit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) Global $SyncAdded = "||" Global $SyncScan = FileFindFirstFile(@AppDataDir & "\*.*") While 1 GUI_Events() If $SYNC_OPERATION = False Then ContinueLoop Local $SyncScanResult = FileFindNextFile($SyncScan) If @error Then SyncReset() If @extended = 1 Then If FileExists(@AppDataDir & "\" & $SyncScanResult & "\wallet.dat") Then GUICtrlSetData($GUI_SyncStatus, $SyncScanResult) If Not StringInStr($SyncAdded, "||" & $SyncScanResult & "||") Then $SyncAdded &= $SyncScanResult & "||" GUICtrlSetData($GUI_Wallets_Found, $SyncScanResult) EndIf If GUICtrlRead($GUI_CheckboxLocal) = $GUI_CHECKED Then If Not FileExists(@ScriptDir & "\SyncData") Then DirCreate(@ScriptDir & "\SyncData") If Not FileExists(@ScriptDir & "\SyncData\" & $SyncScanResult) Then DirCreate(@ScriptDir & "\SyncData\" & $SyncScanResult) FileCopy(@AppDataDir & "\" & $SyncScanResult & "\wallet.dat", @ScriptDir & "\SyncData\" & $SyncScanResult & "\wallet.dat", 1) EndIf EndIf EndIf WEnd Func SyncReset() If $SYNC_OPERATION = True Then If GUICtrlRead($GUI_CheckboxFTP) = $GUI_CHECKED Then GUICtrlSetData($GUI_SyncStatus, "Sending to FTP server...") $SyncFTPOpen = _FTP_Open('FTP') $SyncFTPConn = _FTP_Connect($SyncFTPOpen, $SYNC_FTPSERVER, $SYNC_FTPUSER, $SYNC_FTPPASS, "1", $SYNC_FTPPORT) _FTP_DirPutContents($SyncFTPConn, @ScriptDir & "\SyncData", "", 1) _FTP_Close($SyncFTPOpen) _FTP_Close($SyncFTPConn) EndIf GUICtrlSetData($GUI_SyncStatus, "Sleeping...") EndIf FileClose($SyncScan) Local $SyncTimer = TimerInit() Do GUI_Events() Sleep(10) Until Round(TimerDiff($SyncTimer)/1000, 0) > $SYNC_SPEED Global $SyncScan = FileFindFirstFile(@AppDataDir & "\*.*") EndFunc Func GUI_Events() Switch TrayGetMsg() Case $GUI_Tray_Open GUISetState(@SW_SHOW, $GUI_Wallet_Sync) WinSetState($GUI_Wallet_Sync, "", @SW_RESTORE) Case $GUI_Tray_Exit CloseSync() EndSwitch Switch GUIGetMsg() Case $GUI_EVENT_CLOSE CloseSync() Case $GUI_EVENT_MINIMIZE GUISetState(@SW_Hide, $GUI_Wallet_Sync) TrayTip("WalletSync", "Minimized to the system tray...", 4) Case $GUI_ButtonStart GUICtrlSetState($GUI_ButtonStart, $GUI_DISABLE) GUICtrlSetState($GUI_ButtonStop, $GUI_ENABLE) $SYNC_OPERATION = True Case $GUI_ButtonStop GUICtrlSetState($GUI_ButtonStop, $GUI_DISABLE) GUICtrlSetState($GUI_ButtonStart, $GUI_ENABLE) GUICtrlSetData($GUI_SyncStatus, "Sync is turned off...") $SYNC_OPERATION = False Case $GUI_ButtonUpdateSpeed Switch GUICtrlRead($GUI_ComboSpeed) Case "5 minutes" $SYNC_SPEED = 300 IniDelete(@ScriptDir & "\config.ini", "config", "speed") IniWrite(@ScriptDir & "\config.ini", "config", "speed", $SYNC_SPEED) MsgBox(0, "WalletSync Response", "The speed was updated to 5 minute intervals.") Case "10 minutes" $SYNC_SPEED = 600 IniDelete(@ScriptDir & "\config.ini", "config", "speed") IniWrite(@ScriptDir & "\config.ini", "config", "speed", $SYNC_SPEED) MsgBox(0, "WalletSync Response", "The speed was updated to 10 minute intervals.") Case "30 minutes" $SYNC_SPEED = 1800 IniDelete(@ScriptDir & "\config.ini", "config", "speed") IniWrite(@ScriptDir & "\config.ini", "config", "speed", $SYNC_SPEED) MsgBox(0, "WalletSync Response", "The speed was updated to 30 minute intervals.") Case "1 hour" $SYNC_SPEED = 3600 IniDelete(@ScriptDir & "\config.ini", "config", "speed") IniWrite(@ScriptDir & "\config.ini", "config", "speed", $SYNC_SPEED) MsgBox(0, "WalletSync Response", "The speed was updated to 1 hour intervals.") Case Else $SYNC_SPEED = 60 IniDelete(@ScriptDir & "\config.ini", "config", "speed") IniWrite(@ScriptDir & "\config.ini", "config", "speed", $SYNC_SPEED) MsgBox(0, "WalletSync Response", "The speed was updated to 1 minute intervals.") EndSwitch Case $GUI_ButtonFTPUpdate $SYNC_FTPSERVER = GUICtrlRead($GUI_InputFTPServer) $SYNC_FTPPORT = GUICtrlRead($GUI_InputFTPPort) $SYNC_FTPUSER = GUICtrlRead($GUI_InputFTPUsername) $SYNC_FTPPASS = GUICtrlRead($GUI_InputFTPPassword) IniDelete(@ScriptDir & "\config.ini", "config", "ftpserver") IniDelete(@ScriptDir & "\config.ini", "config", "ftpport") IniDelete(@ScriptDir & "\config.ini", "config", "ftpusername") IniDelete(@ScriptDir & "\config.ini", "config", "ftppassword") IniWrite(@ScriptDir & "\config.ini", "config", "ftpserver", $SYNC_FTPSERVER) IniWrite(@ScriptDir & "\config.ini", "config", "ftpport", $SYNC_FTPPORT) IniWrite(@ScriptDir & "\config.ini", "config", "ftpusername", $SYNC_FTPUSER) IniWrite(@ScriptDir & "\config.ini", "config", "ftppassword", $SYNC_FTPPASS) MsgBox(0, "WalletSync Response", "The ftp credentials were updated.") EndSwitch EndFunc Func CloseSync() FileClose($SyncScan) If FileExists(@ScriptDir & "\WalletSync_temp") Then DirRemove(@ScriptDir & "\WalletSync_temp", 1) Exit EndFunc Version 0.0.0.1 Source Code:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icon.ico #AutoIt3Wrapper_Res_Comment=Backup your crypto currency wallets every minute. #AutoIt3Wrapper_Res_Description=Keep a syncd copy of all the crypto-currency wallet.dats found in there default locations on you PC. #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Res_LegalCopyright=Copyright 2014 zelles #AutoIt3Wrapper_Res_Language=1033 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;#NoTrayIcon #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <Misc.au3> #include <StaticConstants.au3> #include <TrayConstants.au3> #include <WindowsConstants.au3> _Singleton("zellesWalletSync") OnAutoItExitRegister("CloseSync") Opt("TrayMenuMode", 3) Global $GUI_Wallet_Sync = GUICreate("Wallet Sync", 162, 196, 258, 150) Global $GUI_File = GUICtrlCreateMenu("&File") Global $GUI_File_Minimize = GUICtrlCreateMenuItem("&Minimize", $GUI_File) Global $GUI_File_Exit = GUICtrlCreateMenuItem("&Exit", $GUI_File) Global $GUI_Help = GUICtrlCreateMenu("&Help") Global $GUI_Help_About = GUICtrlCreateMenuItem("&About", $GUI_Help) Local $GUI_Label1 = GUICtrlCreateLabel("Backing Up:", 8, 8, 95, 19) GUICtrlSetFont(-1, 9, 800, 0, "Arial") Global $GUI_Label2 = GUICtrlCreateLabel("Label2", 24, 32, 132, 17) Local $GUI_Label3 = GUICtrlCreateLabel("Detected Wallets:", 8, 56, 104, 19) GUICtrlSetFont(-1, 9, 800, 0, "Arial") Global $GUI_Wallets_Found = GUICtrlCreateList("", 0, 80, 161, 95, BitOR($LBS_NOTIFY,$LBS_SORT,$WS_VSCROLL)) GUISetState(@SW_SHOW, $GUI_Wallet_Sync) Global $GUI_Tray_Open = TrayCreateItem("Open WalletSync") TrayCreateItem("") Global $GUI_Tray_Exit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) Global $SyncAdded = "||" Global $SyncScan = FileFindFirstFile(@AppDataDir & "\*.*") While 1 GUI_Events() Local $SyncScanResult = FileFindNextFile($SyncScan) If @error Then SyncReset() If @extended = 1 Then If FileExists(@AppDataDir & "\" & $SyncScanResult & "\wallet.dat") Then GUICtrlSetData($GUI_Label2, $SyncScanResult) If Not StringInStr($SyncAdded, "||" & $SyncScanResult & "||") Then $SyncAdded &= $SyncScanResult & "||" GUICtrlSetData($GUI_Wallets_Found, $SyncScanResult) EndIf If Not FileExists(@ScriptDir & "\SyncData") Then DirCreate(@ScriptDir & "\SyncData") If Not FileExists(@ScriptDir & "\SyncData\" & $SyncScanResult) Then DirCreate(@ScriptDir & "\SyncData\" & $SyncScanResult) FileCopy(@AppDataDir & "\" & $SyncScanResult & "\wallet.dat", @ScriptDir & "\SyncData\" & $SyncScanResult & "\wallet.dat", 1) EndIf EndIf WEnd Func SyncReset() GUICtrlSetData($GUI_Label2, "Sleeping...") FileClose($SyncScan) Local $SyncTimer = TimerInit() Do GUI_Events() Sleep(10) Until Round(TimerDiff($SyncTimer)/1000, 0) > 60 Global $SyncScan = FileFindFirstFile(@AppDataDir & "\*.*") EndFunc Func GUI_Events() Switch TrayGetMsg() Case $GUI_Tray_Open GUISetState(@SW_SHOW, $GUI_Wallet_Sync) WinSetState($GUI_Wallet_Sync, "", @SW_RESTORE) Case $GUI_Tray_Exit CloseSync() EndSwitch Switch GUIGetMsg() Case $GUI_EVENT_CLOSE CloseSync() Case $GUI_EVENT_MINIMIZE GUISetState(@SW_Hide, $GUI_Wallet_Sync) TrayTip("WalletSync", "Minimized to the system tray...", 4) Case $GUI_File_Exit CloseSync() Case $GUI_File_Minimize GUISetState(@SW_Hide, $GUI_Wallet_Sync) TrayTip("WalletSync", "Minimized to the system tray...", 4) Case $GUI_Help_About MsgBox(0, "WalletSync", "A simple tools to sync all your crypto-currencies wallet.dat" & @CRLF & "files to a folder for backup purposes. Created by zelles") EndSwitch EndFunc Func CloseSync() FileClose($SyncScan) Exit EndFunc Version 0.0.0.1 Source Code:
      WalletSync_v_0.0.0.1_source.zip
      Version 0.0.0.1 Windows Binary:
      WalletSync_v_0.0.0.1_x86.zip
       
      New Version 0.0.0.2 with FTP:
      https://github.com/zelles/WalletSync
    • sonofalion
      By sonofalion
      DllStructCreate is so hard for newbies like me. There are many posts here and there that go about treating up/down keys in listviews but nothing does the simple thing I need.
      I need a variable that is updated with the selected/focused item of the listview every time UP or DOWN key is used to move within the listview. Any easy solutions?
      My function so far only treats clicked items:
      Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
          #forceref $hWnd, $iMsg, $wParam
          Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
          $hWndListView = $ClauseList

          If Not IsHWnd($ClauseList) Then                                                ;(NEW LINE)
              $hWndListView = GUICtrlGetHandle($ClauseList)                            ;(NEW LINE)
          EndIf                                                                        ;(NEW LINE)

          $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
          $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
          $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
          $iCode = DllStructGetData($tNMHDR, "Code")
          Switch $hWndFrom
              Case $hWndListView
                  Switch $iCode
                      Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                          $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                          $j = _GUICtrlListView_GetSelectedIndices($ClauseList) ;get index of clicked item
                          _ActiveClause(Number($j)) ;this is a function I call
                  EndSwitch
          EndSwitch
          Return $GUI_RUNDEFMSG
      EndFunc
×