Leaderboard
Popular Content
Showing content with the highest reputation on 12/03/2019 in all areas
-
Internet Explorer 11 startup parameters
seadoggie01 and one other reacted to Nine for a topic
All the IE parameters are there. You do know that this forum is about AutoIt, which is a programming language...2 points -
Are my AutoIt exes really infected?
Leendert-Jan reacted to JSThePatriot for a topic
If you have been using AutoIt for any length of time you will know that it is a great, and powerful scripting language. As with all powerful languages there comes a downside. Virus creation by those that are malicious. AutoIt has no virii installed on your system, and if a script you have created has been marked as a virus, (and you're not malicious) then this is a false positive. They found a set of instructions in an AutoIt EXE out there somewhere, took the general signature of the file, and now all AutoIt EXE's are marked (or most of them). This can be due to several reasons. AutoIt is packed with UPX. UPX is an open source software compression packer. It is used with many virii (to make them smaller). Malicious scripter got the AutoIt script engine recognized as a virus. And I am sure there are more ways your executable could be marked, but that covers the basics. Now I am sure you are wanting to know what you can do to get back up and running without being recognized as a virus. You have to send in a report to the offending AV company alerting them to the false positive they have made. It never hurts to send in your source code along with a compiled exe, to help them realize their mistake. You may have to wait up to 24 hours for them to release an update. The time it takes really depends on the offending AV company. Anti-Virus Links AntiVir Website Contact Avast! Website Contact McAfee Website Contact (email address) Symantec (Norton) Website Contact AVG Website Contact (It says sales or other ?'s I assume this will work) ClamWin Website Contact ClamAV Website Contact (I would only contact the ones with "virusdb maintainer or virus submission management") BitDefender Website Contact ZoneLabs Website Contact Norman Website Contact (email address) eSafe Website Contact (login required) A2 (A-Squared) Website Contact (email address) Edit: Added Website links and Contact links. I hope this helps you understand why your AutoIt executables are marked as virii. JS1 point -
This UDF introduces one or two small tweaks to the functions I posted in Snippet Dump (nothing major). Terminating the CSV with a break is now the default behaviour (although I think it's just a lazy convention). The inclusion of a new function _ArrayToSubItemCSV() got me excited. Thanks for an awesome idea Chimaera. I have included the option to sort the returned CSV formatted strings ascending using any column. ; #include-once #include <Array.au3> ; #INDEX# ======================================================================================================================= ; Title .........: CSVSplit ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: CSV related functions ; Notes .........: CSV format does not have a general standard format, however these functions allow some flexibility. ; The default behaviour of the functions applies to the most common formats used in practice. ; Author(s) .....: czardas ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_ArrayToCSV ;_ArrayToSubItemCSV ;_CSVSplit ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __GetSubstitute ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayToCSV ; Description ...: Converts a two dimensional array to CSV format ; Syntax.........: _ArrayToCSV ( $aArray [, $sDelim [, $sNewLine [, $bFinalBreak ]]] ) ; Parameters ....: $aArray - The array to convert ; $sDelim - Optional - Delimiter set to comma by default (see comments) ; $sNewLine - Optional - New Line set to @LF by default (see comments) ; $bFinalBreak - Set to true in accordance with common practice => CSV Line termination ; Return values .: Success - Returns a string in CSV format ; Failure - Sets @error to: ; |@error = 1 - First parameter is not a valid array ; |@error = 2 - Second parameter is not a valid string ; |@error = 3 - Third parameter is not a valid string ; |@error = 4 - 2nd and 3rd parameters must be different characters ; Author ........: czardas ; Comments ......; One dimensional arrays are returned as multiline text (without delimiters) ; ; Some users may need to set the second parameter to semicolon to return the prefered CSV format ; ; To convert to TSV use @TAB for the second parameter ; ; Some users may wish to set the third parameter to @CRLF ; =============================================================================================================================== Func _ArrayToCSV($aArray, $sDelim = Default, $sNewLine = Default, $bFinalBreak = True) If Not IsArray($aArray) Or Ubound($aArray, 0) > 2 Or Ubound($aArray) = 0 Then Return SetError(1, 0 ,"") If $sDelim = Default Then $sDelim = "," If $sDelim = "" Then Return SetError(2, 0 ,"") If $sNewLine = Default Then $sNewLine = @LF If $sNewLine = "" Then Return SetError(3, 0 ,"") If $sDelim = $sNewLine Then Return SetError(4, 0, "") Local $iRows = UBound($aArray), $sString = "" If Ubound($aArray, 0) = 2 Then ; Check if the array has two dimensions Local $iCols = UBound($aArray, 2) For $i = 0 To $iRows -1 For $j = 0 To $iCols -1 If StringRegExp($aArray[$i][$j], '["\r\n' & $sDelim & ']') Then $aArray[$i][$j] = '"' & StringReplace($aArray[$i][$j], '"', '""') & '"' EndIf $sString &= $aArray[$i][$j] & $sDelim Next $sString = StringTrimRight($sString, StringLen($sDelim)) & $sNewLine Next Else ; The delimiter is not needed For $i = 0 To $iRows -1 If StringRegExp($aArray[$i], '["\r\n' & $sDelim & ']') Then $aArray[$i] = '"' & StringReplace($aArray[$i], '"', '""') & '"' EndIf $sString &= $aArray[$i] & $sNewLine Next EndIf If Not $bFinalBreak Then $sString = StringTrimRight($sString, StringLen($sNewLine)) ; Delete any newline characters added to the end of the string Return $sString EndFunc ;==> _ArrayToCSV ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayToSubItemCSV ; Description ...: Converts an array to multiple CSV formated strings based on the content of the selected column ; Syntax.........: _ArrayToSubItemCSV($aCSV, $iCol [, $sDelim [, $bHeaders [, $iSortCol [, $bAlphaSort ]]]]) ; Parameters ....: $aCSV - The array to parse ; $iCol - Array column used to search for unique content ; $sDelim - Optional - Delimiter set to comma by default ; $bHeaders - Include csv column headers - Default = False ; $iSortCol - The column to sort on for each new CSV (sorts ascending) - Default = False ; $bAlphaSort - If set to true, sorting will be faster but numbers won't always appear in order of magnitude. ; Return values .: Success - Returns a two dimensional array - col 0 = subitem name, col 1 = CSV data ; Failure - Returns an empty string and sets @error to: ; |@error = 1 - First parameter is not a 2D array ; |@error = 2 - Nothing to parse ; |@error = 3 - Invalid second parameter Column number ; |@error = 4 - Invalid third parameter - Delimiter is an empty string ; |@error = 5 - Invalid fourth parameter - Sort Column number is out of range ; Author ........: czardas ; Comments ......; @CRLF is used for line breaks in the returned array of CSV strings. ; ; Data in the sorting column is automatically assumed to contain numeric values. ; ; Setting $iSortCol equal to $iCol will return csv rows in their original ordered sequence. ; =============================================================================================================================== Func _ArrayToSubItemCSV($aCSV, $iCol, $sDelim = Default, $bHeaders = Default, $iSortCol = Default, $bAlphaSort = Default) If Not IsArray($aCSV) Or UBound($aCSV, 0) <> 2 Then Return SetError(1, 0, "") ; Not a 2D array Local $iBound = UBound($aCSV), $iNumCols = UBound($aCSV, 2) If $iBound < 2 Then Return SetError(2, 0, "") ; Nothing to parse If IsInt($iCol) = 0 Or $iCol < 0 Or $iCol > $iNumCols -1 Then Return SetError(3, 0, "") ; $iCol is out of range If $sDelim = Default Then $sDelim = "," If $sDelim = "" Then Return SetError(4, 0, "") ; Delimiter can not be an empty string If $bHeaders = Default Then $bHeaders = False If $iSortCol = Default Or $iSortCol == False Then $iSortCol = -1 If IsInt($iSortCol) = 0 Or $iSortCol < -1 Or $iSortCol > $iNumCols -1 Then Return SetError(5, 0, "") ; $iSortCol is out of range If $bAlphaSort = Default Then $bAlphaSort = False Local $iStart = 0 If $bHeaders Then If $iBound = 2 Then Return SetError(2, 0, "") ; Nothing to parse $iStart = 1 EndIf Local $sTestItem, $iNewCol = 0 If $iSortCol <> -1 And ($bAlphaSort = False Or $iSortCol = $iCol) Then ; In this case we need an extra Column for sorting ReDim $aCSV [$iBound][$iNumCols +1] ; Populate column If $iSortCol = $iCol Then For $i = $iStart To $iBound -1 $aCSV[$i][$iNumCols] = $i Next Else For $i = $iStart To $iBound -1 $sTestItem = StringRegExpReplace($aCSV[$i][$iSortCol], "\A\h+", "") ; Remove leading horizontal WS If StringIsInt($sTestItem) Or StringIsFloat($sTestItem) Then $aCSV[$i][$iNumCols] = Number($sTestItem) Else $aCSV[$i][$iNumCols] = $aCSV[$i][$iSortCol] EndIf Next EndIf $iNewCol = 1 $iSortCol = $iNumCols EndIf _ArraySort($aCSV, 0, $iStart, 0, $iCol) ; Sort on the selected column Local $aSubItemCSV[$iBound][2], $iItems = 0, $aTempCSV[1][$iNumCols + $iNewCol], $iTempIndex $sTestItem = Not $aCSV[$iBound -1][$iCol] For $i = $iBound -1 To $iStart Step -1 If $sTestItem <> $aCSV[$i][$iCol] Then ; Start a new csv instance If $iItems > 0 Then ; Write to main array ReDim $aTempCSV[$iTempIndex][$iNumCols + $iNewCol] If $iSortCol <> -1 Then _ArraySort($aTempCSV, 0, $iStart, 0, $iSortCol) If $iNewCol Then ReDim $aTempCSV[$iTempIndex][$iNumCols] $aSubItemCSV[$iItems -1][0] = $sTestItem $aSubItemCSV[$iItems -1][1] = _ArrayToCSV($aTempCSV, $sDelim, @CRLF) EndIf ReDim $aTempCSV[$iBound][$iNumCols + $iNewCol] ; Create new csv template $iTempIndex = 0 $sTestItem = $aCSV[$i][$iCol] If $bHeaders Then For $j = 0 To $iNumCols -1 $aTempCSV[0][$j] = $aCSV[0][$j] Next $iTempIndex = 1 EndIf $iItems += 1 EndIf For $j = 0 To $iNumCols + $iNewCol -1 ; Continue writing to csv $aTempCSV[$iTempIndex][$j] = $aCSV[$i][$j] Next $iTempIndex += 1 Next ReDim $aTempCSV[$iTempIndex][$iNumCols + $iNewCol] If $iSortCol <> -1 Then _ArraySort($aTempCSV, 0, $iStart, 0, $iSortCol) If $iNewCol Then ReDim $aTempCSV[$iTempIndex][$iNumCols] $aSubItemCSV[$iItems -1][0] = $sTestItem $aSubItemCSV[$iItems -1][1] = _ArrayToCSV($aTempCSV, $sDelim, @CRLF) ReDim $aSubItemCSV[$iItems][2] Return $aSubItemCSV EndFunc ;==> _ArrayToSubItemCSV ; #FUNCTION# ==================================================================================================================== ; Name...........: _CSVSplit ; Description ...: Converts a string in CSV format to a two dimensional array (see comments) ; Syntax.........: CSVSplit ( $aArray [, $sDelim ] ) ; Parameters ....: $aArray - The array to convert ; $sDelim - Optional - Delimiter set to comma by default (see 2nd comment) ; Return values .: Success - Returns a two dimensional array or a one dimensional array (see 1st comment) ; Failure - Sets @error to: ; |@error = 1 - First parameter is not a valid string ; |@error = 2 - Second parameter is not a valid string ; |@error = 3 - Could not find suitable delimiter replacements ; Author ........: czardas ; Comments ......; Returns a one dimensional array if the input string does not contain the delimiter string ; ; Some CSV formats use semicolon as a delimiter instead of a comma ; ; Set the second parameter to @TAB To convert to TSV ; =============================================================================================================================== Func _CSVSplit($string, $sDelim = ",") ; Parses csv string input and returns a one or two dimensional array If Not IsString($string) Or $string = "" Then Return SetError(1, 0, 0) ; Invalid string If Not IsString($sDelim) Or $sDelim = "" Then Return SetError(2, 0, 0) ; Invalid string $string = StringRegExpReplace($string, "[\r\n]+\z", "") ; [Line Added] Remove training breaks Local $iOverride = 63743, $asDelim[3] ; $asDelim => replacements for comma, new line and double quote For $i = 0 To 2 $asDelim[$i] = __GetSubstitute($string, $iOverride) ; Choose a suitable substitution character If @error Then Return SetError(3, 0, 0) ; String contains too many unsuitable characters Next $iOverride = 0 Local $aArray = StringRegExp($string, '\A[^"]+|("+[^"]+)|"+\z', 3) ; Split string using double quotes delim - largest match $string = "" Local $iBound = UBound($aArray) For $i = 0 To $iBound -1 $iOverride += StringInStr($aArray[$i], '"', 0, -1) ; Increment by the number of adjacent double quotes per element If Mod ($iOverride +2, 2) = 0 Then ; Acts as an on/off switch $aArray[$i] = StringReplace($aArray[$i], $sDelim, $asDelim[0]) ; Replace comma delimeters $aArray[$i] = StringRegExpReplace($aArray[$i], "(\r\n)|[\r\n]", $asDelim[1]) ; Replace new line delimeters EndIf $aArray[$i] = StringReplace($aArray[$i], '""', $asDelim[2]) ; Replace double quote pairs $aArray[$i] = StringReplace($aArray[$i], '"', '') ; Delete enclosing double quotes - not paired $aArray[$i] = StringReplace($aArray[$i], $asDelim[2], '"') ; Reintroduce double quote pairs as single characters $string &= $aArray[$i] ; Rebuild the string, which includes two different delimiters Next $iOverride = 0 $aArray = StringSplit($string, $asDelim[1], 2) ; Split to get rows $iBound = UBound($aArray) Local $aCSV[$iBound][2], $aTemp For $i = 0 To $iBound -1 $aTemp = StringSplit($aArray[$i], $asDelim[0]) ; Split to get row items If Not @error Then If $aTemp[0] > $iOverride Then $iOverride = $aTemp[0] ReDim $aCSV[$iBound][$iOverride] ; Add columns to accomodate more items EndIf EndIf For $j = 1 To $aTemp[0] If StringLen($aTemp[$j]) Then If Not StringRegExp($aTemp[$j], '[^"]') Then ; Field only contains double quotes $aTemp[$j] = StringTrimLeft($aTemp[$j], 1) ; Delete enclosing double quote single char EndIf $aCSV[$i][$j -1] = $aTemp[$j] ; Populate each row EndIf Next Next If $iOverride > 1 Then Return $aCSV ; Multiple Columns Else For $i = 0 To $iBound -1 If StringLen($aArray[$i]) And (Not StringRegExp($aArray[$i], '[^"]')) Then ; Only contains double quotes $aArray[$i] = StringTrimLeft($aArray[$i], 1) ; Delete enclosing double quote single char EndIf Next Return $aArray ; Single column EndIf EndFunc ;==> _CSVSplit ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSubstitute ; Description ...: Searches for a character to be used for substitution, ie one not contained within the input string ; Syntax.........: __GetSubstitute($string, ByRef $iCountdown) ; Parameters ....: $string - The string of characters to avoid ; $iCountdown - The first code point to begin checking ; Return values .: Success - Returns a suitable substitution character not found within the first parameter ; Failure - Sets @error to 1 => No substitution character available ; Author ........: czardas ; Comments ......; This function is connected to the function _CSVSplit and was not intended for general use ; $iCountdown is returned ByRef to avoid selecting the same character on subsequent calls to this function ; Initially $iCountown should be passed with a value = 63743 ; =============================================================================================================================== Func __GetSubstitute($string, ByRef $iCountdown) If $iCountdown < 57344 Then Return SetError(1, 0, "") ; Out of options Local $sTestChar For $i = $iCountdown To 57344 Step -1 $sTestChar = ChrW($i) $iCountdown -= 1 If Not StringInStr($string, $sTestChar) Then Return $sTestChar EndIf Next Return SetError(1, 0, "") ; Out of options EndFunc ;==> __GetSubstitute ; See examples in post #8 below. ;1 point
-
No, it has zero effect, not even what certs are for. certificates verify the author (not that the file is certified clean), its the code equivalent of a pretty cursive signature. **That being said, you can whitelist things in your Enterprise AV based off any value. Cert is as valid a value in that sense as any other.1 point
-
Variable for each line in a txt file... it's possible ?
TheXman reacted to Earthshine for a topic
he said to use _FileReadToArray what did you not understand about that? read the help file https://www.autoitscript.com/autoit3/docs/libfunctions/_FileReadToArray.htm1 point -
Really Long Line - (Moved)
UnknownUser reacted to Nine for a topic
Also take a look at Opt ("ExpandVarStrings", 1). You can embed variables and macros directly into the string. It doesn't work with arrays tho.1 point -
Really Long Line - (Moved)
UnknownUser reacted to SlackerAl for a topic
; one line using continuation string Global $sLongSingleLine $sLongSingleLine = "Ideally I would like to be able to type text like this " & @CRLF & _ "so that I could read what I am writing easily " & @CRLF & _ "without having to keep scrolling to the right or " & @CRLF & _ "to the left. Scrolling is quite a pain in the neck " & @CRLF & _ "and with 5000 characters, it might even become " & @CRLF & _ "a programming showstopper." MsgBox(0, "debug", $sLongSingleLine) ; basic approach avoiding character limit in single line Global $sLongString $sLongString = "Ideally I would like to be able to type text like this " & @CRLF $sLongString &= "so that I could read what I am writing easily " & @CRLF $sLongString &= "without having to keep scrolling to the right or " & @CRLF $sLongString &= "to the left. Scrolling is quite a pain in the neck " & @CRLF $sLongString &= "and with 5000 characters, it might even become " & @CRLF $sLongString &= "a programming showstopper." MsgBox(0, "debug", $sLongString) ; keeping the same basic format with the assumption that you want to iteratively parse variables later Global $sLongStringWithVars $sLongStringWithVars = "Ideally I would like to be able to type text like this " & @CRLF $sLongStringWithVars &= "so that I could read what I am writing easily " & @CRLF $sLongStringWithVars &= "without having to keep scrolling to $aArray2[$i][0] the right or " & @CRLF $sLongStringWithVars &= "to the left. Scrolling $aArray2[$i][1] is quite a pain in the neck " & @CRLF $sLongStringWithVars &= "and with 5000 characters, it might even become " & @CRLF $sLongStringWithVars &= "a programming showstopper." ; some trivial substitutions to make Global $aArray2[2][2] = [["Mr. Bob", "Yellow"], ["Mr. Fred", "Red"]] Global $sLongStringWithVars_subs ; making the substitutions later in your code ; you can see how the search string could also be constructed by the loop, but hard coded here for clarity For $i = 0 To 1 $sLongStringWithVars_subs = StringReplace($sLongStringWithVars, "$aArray2[$i][0]", $aArray2[$i][0]) $sLongStringWithVars_subs = StringReplace($sLongStringWithVars_subs, "$aArray2[$i][1]", $aArray2[$i][1]) MsgBox(0, "debug", $sLongStringWithVars_subs) Next1 point -
Really Long Line - (Moved)
UnknownUser reacted to RTFC for a topic
This help page lists AutoIt limits and defaults; the 3rd entry specifies 4095 chars as max linelength in scripts. And welcome to the forums.1 point -
Really Long Line - (Moved)
UnknownUser reacted to seadoggie01 for a topic
Yes, you can wrap text in AutoIt with & _ and continue on the next line like this. Also, you could simply read a file that you store locally and replace specific sequences... like "|username|" with the actual user's name with StringReplace. I use water's OutlookEx UDF and do something similar with an Outlook template email. Edit: That's a ampersand, a space, and an underscore there... kind of hard to see.1 point -
A new version (v1.1.0) was just published to the Downloads section of the forum.1 point
-
Array / Ubound question, please help.
LisHawj reacted to seadoggie01 for a topic
I would suggest using an array as jugador did. That way, you can create controls on the GUI without worrying about where they are created (before/after your buttons)1 point -
You need to understand that AV softwares work in 2 ways: - they detect files that have the same signature as already detected viruses files. This is what the first post of this topic is about. It's basically a "is this file identical to this one?" process. - they use "heuristics detection systems" that inspect what the softwares are doing. It's basically a "does this software act alike what most virus are doing?" process. The problem you're having here is that since you're developping exe that install softwares and change system setting they do similar things as what real viruses are doing, so it triggers the heuristic detection system of AV. Which means even if you switch to another programming language you'll probably still encounter the same problems with AV. In other words, there is no solution to your problem that would allow you to bypass AV checks. So you need to deal with them. Easiest and fastest way is to add your exe to whitelist system, at an AV server level preferably or client level if not possible. Longer but more durable way is what we're all doing in this topic: after the fast way is ok, report the false positive to the different AV companies so that they update their signature base and heuristic detection system to work more precisely. Welcome to our world1 point
-
Refreshing excel
Nas reacted to Liquidlogic for a topic
Hello, I´ve redesigned my script. All works fine, but I need help with refresh pivot table. In my mind is workaround, after refreshing and closing, open xlsx again to refresh PT, but it is barbarian #include <Excel.au3> Local $oExcel = _Excel_Open() ; open excel Local $oWorkbook = _Excel_BookOpen($oExcel, "S:\Back Office VIP\Projekty\WB OUTBOUND\out.xlsx" ) ; open workbook $oExcel.Workbooks(1).RefreshAll ; refresh _Excel_BookClose ( $oWorkbook , True ) ; Close workbook, save _excel_close ($oExcel) ; close excel Thank you1 point -
Try this. I have not coded everything but focused on the listview. #include <GUIConstants.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GDIPlus.au3> #include <File.au3> Opt( "MustDeclareVars", 1 ) #cs ; Needed on AutoIt 3.3.10 Global Const $FLTAR_FILESFOLDERS = 0 Global Const $FLTAR_FILES = 1 Global Const $FLTAR_FOLDERS = 2 Global Const $FLTAR_NOHIDDEN = 4 Global Const $FLTAR_NOSYSTEM = 8 Global Const $FLTAR_NOLINK = 16 Global Const $FLTAR_NORECUR = 0 Global Const $FLTAR_RECUR = 1 Global Const $FLTAR_NOSORT = 0 Global Const $FLTAR_SORT = 1 Global Const $FLTAR_FASTSORT = 2 Global Const $FLTAR_NOPATH = 0 Global Const $FLTAR_RELPATH = 1 Global Const $FLTAR_FULLPATH = 2 #ce Global $hListView, $idOnLvRightClick, $idOnLvDoubleClick Example() Func Example() GUICreate( "Image Album List", 800, 650 ) Local $idListView = GUICtrlCreateListView("", 2, 2, 796, 646, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($idListView, "Image", 140) ; Must not be too small _GUICtrlListView_AddColumn($idListView, "Path", 128) _GUICtrlListView_AddColumn($idListView, "Caption", 450) $hListView = GUICtrlGetHandle( $idListView ) Local $hImage = _GUIImageList_Create(128, 128, 5, 3) _GUICtrlListView_SetImageList($hListView, $hImage, 1) $idOnLvDoubleClick = GUICtrlCreateDummy() $idOnLvRightClick = GUICtrlCreateDummy() _GDIPlus_Startup() Local $aArray = _FileListToArrayRec(".", "*.jpg;*.jpeg", $FLTAR_FILES, 1, $FLTAR_SORT,$FLTAR_FULLPATH) Local $iArray = UBound($aArray) - 1, $GDIpBmpLarge,$GDIpBmpResized,$GDIbmp,$img For $i = 1 To $iArray - 1 $GDIpBmpLarge = _GDIPlus_BitmapCreateFromMemory(Binary(FileRead($aArray[$i]))) ;GDI+ image! $GDIpBmpResized = _GDIPlus_ImageResize($GDIpBmpLarge, 128,128) ;GDI+ image $GDIbmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($GDIpBmpResized) ;GDI image! $img = _GUIImageList_Add($hImage, $GDIbmp ) _GUICtrlListView_AddItem($idListview, "", $img) _GUICtrlListView_AddSubItem($idListview, $i-1,$aArray[$i],1) _GUICtrlListView_AddSubItem($idListview, $i-1,IniRead("img.ini",$aArray[$i],"caption",""),2) _GDIPlus_BitmapDispose($GDIpBmpLarge) _GDIPlus_BitmapDispose($GDIpBmpResized) _WinAPI_DeleteObject($GDIbmp) Next _GDIPlus_Shutdown() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $idOnLvDoubleClick Local $iIndex = GUICtrlRead( $idOnLvDoubleClick ) Local $sValue = InputBox("Edit Image", "Enter your description.", ""," M100") Case $idOnLvRightClick Local $iIndex = GUICtrlRead( $idOnLvRightClick ) MsgBox(0,"IMAGE PATH",_GUICtrlListView_GetItemText($idListview, $iIndex,1)) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup GUIDelete() EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iCode, $tNMHDR, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) GUICtrlSendToDummy( $idOnLvDoubleClick, DllStructGetData($tInfo, "Index") ) Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) GUICtrlSendToDummy( $idOnLvRightClick, DllStructGetData($tInfo, "Index") ) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Images.7z1 point
-
Here an example which you can work with: #include <GUIConstantsEx.au3> #include <FileConstants.au3> #include <GDIPlus.au3> _GDIPlus_Startup() Global Const $hGUI = GUICreate("GDI+ Test", 800, 600) Global Const $iBtn_Load = GUICtrlCreateButton("Load", 10, 10, 60, 60) Global Const $iInput_Path = GUICtrlCreateInput("", 80, 28, 700, 24) Global Const $iLabel_Text = GUICtrlCreateLabel("Preview 640x480", 10, 85, 100, 12) Global Const $iPic_Preview = GUICtrlCreatePic("", 10, 100, 640, 480) Global Const $iBtn_Exit = GUICtrlCreateButton("Exit", 700, 520, 60, 60) GUISetState() Global $sFile Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iBtn_Exit GUIDelete() _GDIPlus_Shutdown() Exit Case $iBtn_Load $sFile = FileOpenDialog("Selet an GDI+ supported image", "", "Images (*.bmp;*.jpg;*.png;*.gif;*.tif)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST), "", $hGUI) If @error Then ContinueCase GUICtrlSetData($iInput_Path, $sFile) LoadAndDisplayImage($sFile, $iPic_Preview) Case $iInput_Path $sFile = GUICtrlRead($iInput_Path) If Not FileExists($sFile) Then ContinueCase LoadAndDisplayImage($sFile, $iPic_Preview) EndSwitch Until False Func LoadAndDisplayImage($sFile, $iCtrl, $bScale = False, $iW = 640, $iH = 480) If Not FileExists($sFile) Then Return SetError(1, 0, 0) Local Const $hImage = _GDIPlus_ImageLoadFromFile($sFile) If @error Then Return SetError(2, 0, 0) Local Const $iW_Img = _GDIPlus_ImageGetWidth($hImage), $iH_Img = _GDIPlus_ImageGetHeight($hImage) Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetInterpolationMode($hGfx, 7) Local $f Switch $bScale Case False If $iW_Img < $iW And $iH_Img < $iH Then ;loaded image is smaller than preview control _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, ($iW - $iW_Img) / 2, ($iH - $iH_Img) / 2, $iW_Img, $iH_Img) Else ;loaded image is larger than preview control If $iW_Img > $iH_Img Then $f = $iW / $iW_Img If Not ($iH_Img * $f < $iH) Then $f = $iH / $iH_Img Else $f = $iH / $iH_Img If Not ($iW_Img * $f < $iW) Then $f = $iW / $iW_Img EndIf _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, ($iW - $iW_Img * $f) / 2, ($iH - $iH_Img * $f) / 2, $iW_Img * $f, $iH_Img * $f) EndIf EndSwitch Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl, 0x0172, 0x0000, 0)) ;delete previous image in pic control _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl, 0x0172, 0x0000, $hHBitmap)) _WinAPI_DeleteObject($hHBitmap) EndFunc For $bScale = True the code isn't implemented yet. Br, UEZ1 point
-
Simple, quick CSV parser
BigDaddyO reacted to FichteFoll for a topic
I don't think this is related to Excel just because it can open and view such .csv files. Yeah, should be mentioned, but regarding the other examples one can imagine it also working that way. Also, I found this function pretty useful for my uses and added a few modifications. (See top lines in attached and cited script.) Deleted that line You forgot to substract UBound($CSVData,1) by 1 as arrays are 0-based. I added a few error handlings to prevent the script from crashing when the row or col param is "out of range". ; PREG-based CSV file parser. ; Copyright 2007, Ed Fletcher ; Modifications by FichteFoll, (02-2012): ; - added $cEnclose parameter for defining the enclosing character (default: ") ; - have _CSVGetColumn and _CSVGetRow use Const ByRef for the first param to save ressources ; - allow _CSVGetColumn and _CSVGetRow to use negative numbers as index (parsing backwards) ; and add some error handling for invalid parameters ; - fix use of "Die" as debug function since this is not defined ; - modified _CSVTest to accept the same parameters as _CSVReadFile ; #AutoIt3Wrapper_AU3Check_Parameters=-d -w 3 -w 4 -w 5 -w 6 #include-once ;=============================================================================== ; ; Description: Reads a CSV file into a 2D array ; Parameter(s): $sPath - Path to the CSV file to read ; $cSeparator - Separator character, default is comma (,) ; $cEnclose - Character used in enclosings, default is " ; Requirement(s): None ; Return Value(s): On Success - 2D CSV array ; On Failure - 0 and Set ; @ERROR to: 1 - File not found/openable ; 2 - File read error ; 3 - CSV format error ; Author(s): Ed Fletcher ; Note(s): Pattern based on work by Jeffrey E. F. Friedl in ; "Mastering Regular Expressions, 2nd Edition" ;=============================================================================== Func _CSVReadFile( $path, $separator = ',', $enclose = '"' ) ;; open the file and read the entire CSV dataset into one string. Local $hFile = FileOpen( $path, 0 ) If $hFile == -1 Then SetError( 1 ) Return 0 EndIf Local $sRawData = FileRead( $hFile ) If @error > 0 Then FileClose( $hFile ) SetError( 2 ) Return 0 EndIf FileClose( $hFile ) ;; parse the string into an array of matched fields Local $pattern = '(?m)' ; multi-line search mode $pattern &= 'G(?:^|[' & $separator & '])' ; start of line or start of field $pattern &= '(?:' ; one of two options: $pattern &= $enclose ; a field starting with at double quote $pattern &= StringFormat('([^%s]*+(?:%s%s[^%s]*+)*+)', $enclose, $enclose, $enclose, $enclose) ; ; (quote-pairs and any non-quote chars) $pattern &= $enclose ; a double quote ending the field $pattern &= '(r?n?)' ; (any sort of line ending here?) $pattern &= '|' ; or: $pattern &= '([^"' & $separator & 'rn]*+)' ; (a simple CSV field, no quotes or commas) $pattern &= '(r?n?)' ; (any sort of line ending here?) $pattern &= ')' ; note that we should have 4 captures per CSV element Local $aRawData = StringRegExp( $sRawData, $pattern, 4 ) If @error <> 0 Then SetError( 3 ) Return 0 EndIf $sRawData = '' ; we're done with this, and it might be large ; $aRawData is a 1D array containing every field in the CSV file. Each element ; in $aRawData is an array of 5 strings, like so: ; 0 - all of the characters consumed while matching this field ; 1 - field contents, if the field was double quoted ; 2 - a line ending, if the field was double quoted and this is the end of the line ; 3 - field contents, if the field was *not* double quoted ; 4 - a line ending, if the field was *not* double quoted and this is the end of the line ;; pass through the results once to determine the number of rows and the max number of columns Local $i, $aMatch Local $colCount = 0, $maxCols = 0 Local $rowCount = 0 For $i=0 To UBound($aRawData)-1 $aMatch = $aRawData[$i] If $colCount == 0 Then $rowCount += 1 ; we're looking at the first field on the current row EndIf $colCount += 1 If $colCount > $maxCols Then $maxCols = $colCount ; longest row so far... EndIf If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then $colCount = 0 ; row complete, we might start a new one EndIf Next ;; we now know how large to make our 2D output array Local $aCsvData[$rowCount][$maxCols] ;; finally, populate our output array Local $row = 0, $col = 0 For $i=0 To UBound($aRawData)-1 $aMatch = $aRawData[$i] If UBound($aMatch) > 3 AND $aMatch[3] <> '' Then ; It was a simple field, no processing required $aCsvData[$row][$col] = $aMatch[3] Else ; It was a quoted value, so take care of embedded double quotes $aCsvData[$row][$col] = StringReplace($aMatch[1], '""', '"') EndIf $col += 1 ; now look for a line ending that ends the current data row If $aMatch[2] <> '' OR (UBound($aMatch) > 3 AND $aMatch[4] <> '') Then $row += 1 $col = 0 EndIf Next Return $aCsvData EndFunc ;=============================================================================== ; ; Description: Pulls a single column out of a 2D array ; Parameter(s): $aCSV - 2D array to work with; Const ByRef ; $colNum - Column index, 0-based; ; Negative numbers for backwards parsing are allowed ; Requirement(s): None ; Return Value(s): On Success - An array of columnar data ; On Failure - 0 and Set ; @ERROR to: 1 - Dimension mismatch; only 2D arrays! ; 2 - $colNum is invalid ; 3 - $colNum exceeds column count ; Note(s): ; ;=============================================================================== Func _CSVGetColumn( Const ByRef $aCSV, $colNum ) ; test array dimensions If UBound($aCSV, 0) <> 2 Then SetError( 1 ) Return 0 EndIf ; test second parameter for validity $colNum = Int($colNum) ; cast strings If Not IsInt($colNum) Then SetError( 2 ) Return 0 EndIf Local $aBounds[2] = [UBound($aCSV, 1), UBound($aCSV, 2)] ; test second parameter for validity (2) If $colNum < 0 Then $colNum = $aBounds[1] + $colNum If $colNum < 0 Or $colNum > ($aBounds[1] - 1) Then SetError( 3 ) Return 0 EndIf ; start with defining the return array Local $aColumn[$aBounds[0]] Local $i For $i=0 To $aBounds[0]-1 $aColumn[$i] = $aCSV[$i][$colNum] Next Return $aColumn EndFunc ;=============================================================================== ; ; Description: Pulls a single row out of a 2D array ; Parameter(s): $aCSV - 2D array to work with; Const ByRef ; $rowNum - Row index, 0-based; ; Negative numbers for backwards parsing are allowed ; Requirement(s): None ; Return Value(s): On Success - An array of row data ; On Failure - 0 and Set ; @ERROR to: 1 - Dimension mismatch; only 2D arrays! ; 2 - $rowNum is invalid ; 3 - $rowNum exceeds column count ; Note(s): ; ;=============================================================================== Func _CSVGetRow( Const ByRef $aCSV, $rowNum ) ; test array dimensions If UBound($aCSV, 0) <> 2 Then SetError( 1 ) Return 0 EndIf ; test second parameter for validity $colNum = Int($rowNum) ; cast strings If Not IsInt($rowNum) Then SetError( 2 ) Return 0 EndIf Local $aBounds[2] = [UBound($aCSV, 1), UBound($aCSV, 2)] ; test second parameter for validity (2) If $rowNum < 0 Then $rowNum = $aBounds[0] + $rowNum If $rowNum < 0 Or $rowNum > ($aBounds[0] - 1) Then SetError( 3 ) Return 0 EndIf ; start with defining the return array Local $aRow[$aBounds[1]] Local $i For $i=0 To $aBounds[1]-1 $aRow[$i] = $aCSV[$rowNum][$i] Next Return $aRow EndFunc ;=============================================================================== ; ; Description: Test function for _CSVReadFile() ; Parameter(s): $sPath - Path to the file to read, default is 'test.csv' ; $cSeparator - Separator character, default is comma (,) ; $cEnclose - Character used in enclosings, default is " ; Requirement(s): None ; Return Value(s): None ; Note(s): Dumps out array data via ConsoleWrite() ; ;=============================================================================== Func _CSVTest( $file = "test.csv", $separator = ',', $enclose = '"' ) Local $output = _CSVReadFile( $file, $separator, $enclose ) If @error <> 0 Then ConsoleWriteError( "Error " & @error & " reading file [" & $file & "]" & @CR ) Exit EndIf Local $i, $j For $i=0 To UBound($output)-1 For $j=0 To UBound($output, 2)-1 ConsoleWrite('[' & $output[$i][$j] & ']') Next ConsoleWrite(@CR) Next EndFunc ;~ If @ScriptName == 'LibCsv2_mod.au3' Then ;~ _CSVTest("ABRS.csv") ;~ EndIf I hope this is of use to someone. LibCsv2_mod.au31 point