Leaderboard
Popular Content
Showing content with the highest reputation on 09/16/2015 in all areas
-
In this case you can use a * 2^i: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 319, 216, 192, 124) $Checkbox1 = GUICtrlCreateCheckbox(" 1", 48, 56, 97, 17) $Checkbox2 = GUICtrlCreateCheckbox(" 2", 48, 88, 97, 17) $Checkbox3 = GUICtrlCreateCheckbox(" 4", 48, 120, 97, 17) $Checkbox4 = GUICtrlCreateCheckbox(" 8", 216, 56, 97, 17) $Checkbox5 = GUICtrlCreateCheckbox("16", 216, 88, 97, 17) $Checkbox6 = GUICtrlCreateCheckbox(" 32", 216, 120, 97, 17) $Button1 = GUICtrlCreateButton("plus any checked boxes", 64, 160, 155, 25) GUISetState(@SW_SHOW) Global $iSum While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $Button1 $iSum = 0 For $i = 0 To 5 $iSum += BitAND(GUICtrlRead(Execute("$Checkbox" & $i + 1)), $GUI_CHECKED) * 2^$i Next MsgBox(0, "Sum", $iSum) EndSwitch WEnd1 point
-
plus
Jfish reacted to JLogan3o13 for a topic
Why needlessly complicate the process by introducing a bunch of Mouse and Caret calls, when JFish's example does just what the OP is asking for?1 point -
Character Limit?
czardas reacted to ViciousXUSMC for a topic
But you know I love walking to the lake, getting a pale of water, bringing it back. Foraging for twigs and other dry wood, starting a fire, boiling the water for a few minutes, waiting for it to cool, and then.. dying of dehydration while waiting.1 point -
I generally use ini files for my 'lightweight' apps, and have always loaded the data into an array at startup, then reference the config array throughout the application. For applications that tend to be a little larger/have more in depth config/Multiple users I opt for sqlite databases: This is just personal preference however, and not based on any issues experienced with ini files. As for ini files, I would say the approach taken should depend on how the application will be used. For example, will the app be used constantly, or opened/closed as required, If it's likely to be constantly open, then perhaps periodically updating an array with the variables would be preferably to just at startup. Anyway, enough of my ramblings, Here's an example of an ini file, how to load it into an array, and reference it . Error.ini: [1] ErrorCode=1 ErrorName=Could not connect ErrorDesc=Could not connect to the remote host, please check connectivity [2] ErrorCode=-1 ErrorName=Invalid Credentials ErrorDesc=The username or password was not recognised, Please try again [3] ErrorCode=3 ErrorName=Unrecognised ErrorDesc=is an unrecognised character! Please note that ^&*() are not supported Error.au3: #include <Array.au3> GLOBAL $aErrors,$iConnect $aErrors = _LoadIni(@ScriptDir & "\error.ini") _ArrayDisplay($aErrors) ;Visual reference of the error array $iConnect = _Connect("SomeRandomPC") ;Mock function that is destined to fail if $iConnect <> 1 then _CheckError(@error) ;Check the error code ;load the ini file func _LoadIni($sIni) local $aErrors[1][3], $aSections,$aTempArray $aErrors[0][0] = 1 $aSections = IniReadSectionNames($sIni) ;Load all section names into temporary array for $i = 1 to $aSections[0] $aTempArray = iniReadSection($sIni,$aSections[$i]) ;Read each section per loop iteration reDim $aErrors[$aErrors[0][0] + 1][3] ;Dynamically increase the error array and input ini data to main error array $aErrors[$aErrors[0][0]][0] = $aTempArray[1][1] $aErrors[$aErrors[0][0]][1] = $aTempArray[2][1] $aErrors[$aErrors[0][0]][2] = $aTempArray[3][1] $aErrors[0][0] += 1 Next return $aErrors ;Return the newly built array EndFunc ;Mock function func _Connect($sPC) if $sPC = "MyPC" then return 1 return SetError(1,0,0) ;Returns @ERROR=1 and $iConnect=0 EndFunc ;error checker Func _CheckError($sErrCode) for $i = 1 to $aErrors[0][0] - 1 ;Loop through error array if $sErrCode = $aErrors[$i][0] Then ;Check error code against error code column msgbox(0,$aErrors[$i][1],$aErrors[$i][2]) ;Output the name and description for the error return 0 elseif $i = $aErrors[0][0] - 1 ;We've reached the end of the array and not found a matching error msgbox(0,"Unhandled error","An unhandled error has ocurred, please contact IT with the following error code: " & $sErrCode) ;Output the unhandled error code EndIf Next EndFuncCheers Javi1 point
-
An easy way is to use the $ES_NUMBER style for your inputs, so it prevent users to enter something else than numbers. Edit : to answer to you question : 1 is a number, "1" is not a number, it is a string. GUICtrlRead returns a string. You can check the input to be 4 numbers with something like this : If StringRegExp( GUICtrlRead($idField1), "^\d{4}$") AND StringRegExp( GUICtrlRead($idField2), "^\d{4}$") Then ; OK1 point
-
read the string inbetween 2 strings
Sandhya reacted to ViciousXUSMC for a topic
Try something like this? #Include <File.au3> #Include <String.au3> #Include <Array.au3> $vFile = @ScriptDir & "\cmp.txt" Local $aFile Local $aFinal[0] _FileReadToArray($vFile, $aFile) For $i = 1 to $aFile[0] $sTemp = _StringBetween($aFile[$i], "All selected attributes", "Long identifier") If $sTemp <> 0 Then _ArrayAdd($aFinal, $sTemp[0]) Next _ArrayDisplay($aFinal)And I am not sure but it may be faster with RegEx #Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <StringConstants.au3> $vFile = @ScriptDir & "\cmp.txt" Local $aFile Local $aFinal[0] _FileReadToArray($vFile, $aFile) For $i = 1 to $aFile[0] ;$sTemp = _StringBetween($aFile[$i], "All selected attributes", "Long identifier") $sTemp = StringRegExp($aFile[$i], "(?i)all selected attributes (.*) long identifier", $STR_REGEXPARRAYMATCH) If $sTemp <> 0 Then _ArrayAdd($aFinal, $sTemp) Next _ArrayDisplay($aFinal)And this possibly faster yet. #Include <File.au3> #Include <String.au3> #Include <Array.au3> #Include <StringConstants.au3> $vFile = @ScriptDir & "\cmp.txt" $hFile = FileOpen($vFile) $sFile = FileRead($hFile) Local $aFinal[0] $aFinal = StringRegExp($sFile, "(?i)all selected attributes (.*) long identifier", $STR_REGEXPARRAYGLOBALMATCH) FileClose($hFile) _ArrayDisplay($aFinal) String Between.au3 String Between RegEx.au3 String Between RegEx2.au3 cmp.txt1 point -
Care to enlighten the OP what exactly happened so they can fix it.1 point
-
You can get it here temporariliy. https://www.autoitscript.com/autoit3/pkgmgr/sqlite/SQLite3_3.8.11.1.zip Download it manually though. Don't FileInstall it from the server or anything.1 point
-
FileInstall Directory Helper
hudsonhock reacted to SmOke_N for a topic
This was made for someone that was using FileInstall() wrong and asking for help. Since FileInstall() doesn't allow wildcards, and you must use a string for the source, this simply lets you choose a directory that you want to install, allows you to pick the extension to install or just use the wild card, allows you to choose the destination path, and allows you to choose the flag. It will bring everything up in the edit box, and you can use the copy button to copy the data, then paste it to your script. <snip> Feel free to add, critique, whatever... it was just thrown together quickly. Edit: Fixed version. Edit: Added the option to exclude the drive and directory from 1st parameter of FileInstall. Edit - 2014/12/02 Updated code... uses _FileListToArrayRec to allow recursive option now. Also goes to the computer location rather than homedrive. Note: Yes, there is a recursive option to get all the folders/files, however, I did not add code to check the directory paths and making sure they were created, this was a brain fart moment. But I do not have time at the moment to screw around with that, so if you want recursive and want to keep them installed in their directory paths, you may need to do each folder individually without recurse mode. <snip> Edit2 - 2014/12/02 I think I've fixed the recursion issue, added the choice of saving the hierarchy of the folder, should create the directories for you. I tried this on a huge folder of .au3 files, everything looked right. #include <GUIConstantsEx.au3> #include <File.au3> Global $sMyComputerCLSID = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Global $gsDirData = "" Global $ghMain = GUICreate('FileInstall Directory', 600, 380) Global $giOutPut = GUICtrlCreateEdit('', 10, 10, 580, 300) GUICtrlCreateLabel('Extension:', 20, 318, 50, 20, 0x001) Global $giExtension = GUICtrlCreateInput('*', 75, 315, 50, 20) GUICtrlCreateLabel('Destination Path:', 130, 318, 90, 20, 0x001) Global $giDestPath = GUICtrlCreateInput('@TempDir & "\"', 220, 315, 200, 20) GUICtrlCreateLabel('Flag:', 425, 318, 30, 20, 0x001) Global $giFlag = GUICtrlCreateCombo('', 455, 315, 40, 300) GUICtrlSetData($giFlag, '0|1|', '0') Global $giDirDrive = GUICtrlCreateCheckbox("Long Path", 500, 315) Global $giDirRecurse = GUICtrlCreateCheckbox("Dir Recurse", 500, 335) Global $giDirHierarchy = GUICtrlCreateCheckbox("Keep Hierarchy", 500, 355) Global $giGetDir = GUICtrlCreateButton('Directory Get Files', 110, 345, 150, 30) Global $giCopyData = GUICtrlCreateButton('Copy Data', 320, 345, 150, 30) GUISetState() While 1 Switch GUIGetMsg() Case - 3 Exit Case $giGetDir $gsDirData = _GetDirData(GUICtrlRead($giExtension), (GUICtrlRead($giDirDrive) <> 1), _ GUICtrlRead($giDestPath), GUICtrlRead($giFlag), GUICtrlRead($giDirRecurse), _ GUICtrlRead($giDirHierarchy) = $GUI_CHECKED) If Not @error Then GUICtrlSetData($giOutPut, '') GUICtrlSetData($giOutPut, $gsDirData) EndIf Case $giCopyData ClipPut(GUICtrlRead($giOutPut)) EndSwitch WEnd Func _GetDirData($sExt, $bExcludeLongName, $sDestPath, $nFlag, $nRecursive, $bHierarchy) Local $sDir = FileSelectFolder("Select a Directory to FileInstall", $sMyComputerCLSID) If @error Then Return SetError(1, @extended, "") EndIf $nRecursive = ($nRecursive = $GUI_CHECKED) ? 1 : 0 Local $aFiles = _FileListToArrayRec($sDir, "*." & $sExt, 1, $nRecursive, 0, 2) If Not IsArray($aFiles) Then Return SetError(2, @extended, "") EndIf Local $sTDrive, $sTDir, $sTFName, $sTExt Local $sHold = "" _GetExistStr($sDestPath, $sHold) Local $sFinstall = "" Local $sTmpDest = "" Local $sHoldStr = "" If $bHierarchy Then ; main folder searching _PathSplit($sDir, $sTDrive, $sTDir, $sTFName, $sTExt) If StringRight(StringRegExpReplace($sDestPath, "[\\/]+\z", ""), _ StringLen($sTFName)) <> $sTFName Then $sTmpDest = StringRegExpReplace($sDestPath, _ "(\&\s*(?:\x27|\x22)[\\/]+(?:\x27|\x22))", "") & ' & "\' & $sTFName & '\"' If Not StringInStr($sHoldStr, $sTDir & @LF) Then $sHoldStr &= $sTDir & @LF _GetExistStr($sTmpDest, $sHold) EndIf EndIf EndIf Local Static $sScrDir = StringRegExpReplace(@ScriptDir, "\\+\z", "") For $i = 1 To UBound($aFiles) - 1 $sTmpDest = $sDestPath _PathSplit($aFiles[$i], $sTDrive, $sTDir, $sTFName, $sTExt) If $bExcludeLongName Then If $sScrDir = StringRegExpReplace($sTDrive & $sTDir, "\\+\z", "") Then $aFiles[$i] = $sTFName & $sTExt EndIf EndIf If $bHierarchy Then $sTmpDest = StringRegExpReplace($sTmpDest, _ "(\&\s*(?:\x27|\x22)[\\/]+(?:\x27|\x22))", "") & ' & "' & $sTDir & '"' If Not StringInStr($sHoldStr, $sTDir & @LF) Then $sHoldStr &= $sTDir & @LF _GetExistStr($sTmpDest, $sHold) EndIf EndIf $sFinstall &= "FileInstall(""" & $aFiles[$i] & '", ' & $sTmpDest & ", " & $nFlag & ")" & @CRLF Next $sHold &= $sFinstall $sHold = StringTrimRight($sHold, 2) Return $sHold EndFunc Func _GetExistStr($sDestPath, ByRef $sOutData) $sOutData &= 'If Not FileExists(' & $sDestPath & ') Then' & @CRLF $sOutData &= ' Do' & @CRLF $sOutData &= ' DirCreate(' & $sDestPath & ')' & @CRLF $sOutData &= ' Until FileExists(' & $sDestPath & ')' & @CRLF $sOutData &= 'EndIf' & @CRLF EndFunc .1 point