Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/17/2018 in all areas

  1. #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Array.au3> #include <WinAPITheme.au3> #include <GDIPlus.au3> #Region GUICtrlComboSetColors UDF Global $g__aWM_CTLCOLORLISTBOX[1][16] = [[0, 0, 0]] ; init. the Global array ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors ; Description ...: Change the colors and position/size of a ComboBox ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iBgColor = Default] [, $iFgColor = Default] [, $iExtendLeft = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iBgColor - Background RGB color ; - or "-1" to use prior color declared ; - or to remove a control by ControlID, "-2" ; - or to remove a control by ArrayIndex, "-3" ; $iFgColor - Foreground RGB color ; - or "-1" to use prior color declared ; - or "-2" to use sytem color and leave theme default ; $iExtendLeft - pixels to extend the dropdown list ; - or "-1" to use prior width declared ; - or "1" auto size, extending left ( see Remarks/AutoSize ) ; - or "2" auto size, extending right ( see Remarks/AutoSize ) ; Return values .: Success - index position in the array ; Failure - 0 ; @error - 1 : Control handle = 0 ; - 2 : GetComboBoxInfo failed ; - 3 : Control for removal not found ; @extended - 2 : Success on Control removal ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; AutoSize...: use the pertinent parameters from GUICtrlComboSetColors_SetAutoSize() ; minus the CtrlID as semicolon separated to initialize. Ex: "2;Arial;8.5;0" ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors($idCombo = 0, $iBgColor = Default, $iFgColor = Default, $iExtendLeft = Default) If Not $idCombo Then Return SetError(1, 0, 0) Local $n, $tInfo, $i = 0 If $iBgColor = -2 Or $iBgColor = -3 Then Local $m For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If ($g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo And $iBgColor = -2) Or ($g__aWM_CTLCOLORLISTBOX[$n][9] = $idCombo And $iBgColor = -3) Then _ArrayDelete($g__aWM_CTLCOLORLISTBOX, $n) $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(0, 2, $n) EndIf Next Return SetError(3, 0, 0) EndIf For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then $i = $n ExitLoop EndIf Next If Not $i Then $g__aWM_CTLCOLORLISTBOX[0][0] += 1 $i = $g__aWM_CTLCOLORLISTBOX[0][0] ; If $i >= UBound($g__aWM_CTLCOLORLISTBOX) Then ReDim $g__aWM_CTLCOLORLISTBOX[$i + 1][16] ; add extra "slots" EndIf EndIf Local $sStr = GUICtrlRead($idCombo) Local $iSetWindowTheme = 1 If $iBgColor = Default And $iFgColor = Default Then $iSetWindowTheme = 0 If $iBgColor = Default Then $iBgColor = _WinAPI_GetSysColor($COLOR_WINDOW) If $iFgColor = Default Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) If $iBgColor = -1 Then $iBgColor = $g__aWM_CTLCOLORLISTBOX[$i][10] If $iFgColor = -1 Then $iFgColor = $g__aWM_CTLCOLORLISTBOX[$i][11] $g__aWM_CTLCOLORLISTBOX[$i][11] = $iFgColor $g__aWM_CTLCOLORLISTBOX[$i][10] = $iBgColor If $iExtendLeft = Default Then $iExtendLeft = 0 $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf If $iExtendLeft = -1 Then $iExtendLeft = $g__aWM_CTLCOLORLISTBOX[$i][8] ElseIf Int($iExtendLeft) = 1 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 1 ElseIf Int($iExtendLeft) = 2 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 2 Else $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($iExtendLeft) $g__aWM_CTLCOLORLISTBOX[$i][0] = $idCombo $g__aWM_CTLCOLORLISTBOX[$i][1] = GUICtrlGetHandle($idCombo) $g__aWM_CTLCOLORLISTBOX[$i][13] = "Arial" ; default $sFont $g__aWM_CTLCOLORLISTBOX[$i][14] = 8.5 ; default $fSize $g__aWM_CTLCOLORLISTBOX[$i][15] = 0 ; default $iStyle If $g__aWM_CTLCOLORLISTBOX[$i][12] Then $f = StringSplit($iExtendLeft, ";") If UBound($f) > 1 Then $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($f[1]) If UBound($f) > 2 Then $g__aWM_CTLCOLORLISTBOX[$i][13] = $f[2] If UBound($f) > 3 Then $g__aWM_CTLCOLORLISTBOX[$i][14] = Int($f[3]) If UBound($f) > 4 Then $g__aWM_CTLCOLORLISTBOX[$i][15] = Int($f[4]) $t = TimerInit() GUICtrlComboSetColors_SetAutoSize(Int("-" & $i), $g__aWM_CTLCOLORLISTBOX[$i][12], $g__aWM_CTLCOLORLISTBOX[$i][13], $g__aWM_CTLCOLORLISTBOX[$i][14], $g__aWM_CTLCOLORLISTBOX[$i][15]) ConsoleWrite(TimerDiff($t) & @CRLF) EndIf If _GUICtrlComboBox_GetComboBoxInfo($idCombo, $tInfo) Then If $iSetWindowTheme Then If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], "", "") If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then GUICtrlSetColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iFgColor) GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iBgColor) Else GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], _WinAPI_GetSysColor($COLOR_HOTLIGHT)) _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], 0, 0) EndIf $g__aWM_CTLCOLORLISTBOX[$i][2] = DllStructGetData($tInfo, "hCombo") $g__aWM_CTLCOLORLISTBOX[$i][3] = DllStructGetData($tInfo, "hEdit") $g__aWM_CTLCOLORLISTBOX[$i][4] = DllStructGetData($tInfo, "hList") ; this is what is colored Else $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(2, 0, 0) EndIf If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) $g__aWM_CTLCOLORLISTBOX[$i][5] = 0 ; holder for "_WinAPI_CreateSolidBrush()" return value $g__aWM_CTLCOLORLISTBOX[$i][6] = BitOR(BitAND($iBgColor, 0x00FF00), BitShift(BitAND($iBgColor, 0x0000FF), -16), BitShift(BitAND($iBgColor, 0xFF0000), 16)) If $g__aWM_CTLCOLORLISTBOX[$i][11] = -2 Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) $g__aWM_CTLCOLORLISTBOX[$i][7] = BitOR(BitAND($iFgColor, 0x00FF00), BitShift(BitAND($iFgColor, 0x0000FF), -16), BitShift(BitAND($iFgColor, 0xFF0000), 16)) If Not $g__aWM_CTLCOLORLISTBOX[0][1] Then If $g__aWM_CTLCOLORLISTBOX[$i][4] Then $g__aWM_CTLCOLORLISTBOX[0][1] = GUIRegisterMsg($WM_CTLCOLORLISTBOX, "UDF_WM_CTLCOLORLISTBOX") If $g__aWM_CTLCOLORLISTBOX[0][1] Then OnAutoItExitRegister("OnAutoItExit_UDF_WM_CTLCOLORLISTBOX") EndIf EndIf $g__aWM_CTLCOLORLISTBOX[0][2] += 1 $g__aWM_CTLCOLORLISTBOX[$i][9] = $g__aWM_CTLCOLORLISTBOX[0][2] ; internal ID $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() ; to use in UDF_WM_CTLCOLORLISTBOX() $g__aWM_CTLCOLORLISTBOX[0][4] = 0 ; to use in UDF_WM_CTLCOLORLISTBOX() If $sStr Then GUICtrlSetData($idCombo, $sStr) Return SetError(0, 0, $g__aWM_CTLCOLORLISTBOX[0][2]) EndFunc ;==>GUICtrlComboSetColors Func UDF_WM_CTLCOLORLISTBOX($hWnd, $Msg, $wParam, $lParam) ConsoleWrite('+ Func UDF_WM_CTLCOLORLISTBOX(' & $hWnd & ', ' & $Msg & ', ' & $wParam & ', ' & $lParam & ')' & @CRLF) For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$i][4] = $lParam Then If TimerDiff($g__aWM_CTLCOLORLISTBOX[0][3]) > 500 Or $g__aWM_CTLCOLORLISTBOX[0][4] <> $lParam Then If $g__aWM_CTLCOLORLISTBOX[$i][12] Then GUICtrlComboSetColors_SetAutoSize("-" & $i) EndIf $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() $g__aWM_CTLCOLORLISTBOX[0][4] = $lParam If $g__aWM_CTLCOLORLISTBOX[$i][8] > 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0] - $g__aWM_CTLCOLORLISTBOX[$i][8], $aWPos[1] + $aWPos[3], $aWPos[2] + $g__aWM_CTLCOLORLISTBOX[$i][8]) ElseIf $g__aWM_CTLCOLORLISTBOX[$i][8] < 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0], $aWPos[1] + $aWPos[3], $aWPos[2] - $g__aWM_CTLCOLORLISTBOX[$i][8]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][7] >= 0 Then _WinAPI_SetTextColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][7]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][6] >= 0 Then _WinAPI_SetBkColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][6]) If Not $g__aWM_CTLCOLORLISTBOX[$i][5] Then $g__aWM_CTLCOLORLISTBOX[$i][5] = _WinAPI_CreateSolidBrush($g__aWM_CTLCOLORLISTBOX[$i][6]) Return $g__aWM_CTLCOLORLISTBOX[$i][5] EndIf Return 0 EndIf Next EndFunc ;==>UDF_WM_CTLCOLORLISTBOX ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors_SetAutoSize ; Description ...: Set autosize for a ComboBox initialized in GUICtrlComboSetColors() ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iExtendLeft = Default] [, $sFont = Default] [, $fSize = Default] [, $iStyle = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iExtendLeft - 1 = Left, 2 = Right, 0 = disable auto-sizing ; $sFont - Font name ; $fSize - Font size ; $iStyle - Font style ; Return values .: Success - widthest string in pixels ; Failure - -1 ; @error - look at the comments in the function ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; Related .......: GUICtrlComboSetColors() ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors_SetAutoSize($idCombo, $iExtendLeft = Default, $sFont = Default, $fSize = Default, $iStyle = Default) ConsoleWrite('+ Func GUICtrlComboSetColors_AutoSizeSet("' & $idCombo & '", "' & $iExtendLeft & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '")' & @CRLF) $idCombo = Int($idCombo) ; just in case the value is a string Local $n, $iArrayIndex = 0, $iCtrl = 0 If $idCombo > 0 Then For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then ; the expected value, is the ControlID $iArrayIndex = $n ExitLoop EndIf Next Return SetError(4, 0, -1) ; $iArrayIndex not found ElseIf $idCombo < 0 Then ; the expected value, is a negative of array's index .. $iArrayIndex = Int(StringTrimLeft(StringStripWS($idCombo, 8), 1)) ; .. so now is a positive value .. If $iArrayIndex < 1 Then Return SetError(3, 0, -1) ; .. else, error .. If $iArrayIndex > $g__aWM_CTLCOLORLISTBOX[0][0] Then Return SetError(2, 0, -1) ; .. as long as is not greater than expected Else Return SetError(1, 0, -1) ; could not find a usable value EndIf Switch $iExtendLeft Case 0, 1, 2 $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = $iExtendLeft EndSwitch Local $aCtrlPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][1]) If UBound($aCtrlPos) <> 4 Then Return SetError(5, 0, -1) ; could not get a usable value Local $sString = StringReplace(_GUICtrlComboBox_GetList($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][0]), "|", @CRLF) Local $aStrWidth = _GDIPlus_MeasureString($sString, $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][13], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][14], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][15]) If UBound($aStrWidth) <> 2 Then Return SetError(6, 0, -1) ; could not get a usable value If $aStrWidth[0] < $aCtrlPos[2] Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = 0 Else $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = $aStrWidth[0] - $aCtrlPos[2] If $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = 2 Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = Int("-" & $aStrWidth[0] - $aCtrlPos[2]) EndIf Return $aStrWidth[0] EndFunc ;==>GUICtrlComboSetColors_SetAutoSize Func _GDIPlus_MeasureString($sString, $sFont = "Arial", $fSize = 12, $iStyle = 0, $bRound = True) ConsoleWrite('Func _GDIPlus_MeasureString("' & $sString & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '", "' & $bRound & '")' & @CRLF) ; original code @ https://www.autoitscript.com/forum/topic/150736-gdi-wrapping-text/?do=findComment&comment=1077210 If Not $__g_iGDIPRef Then _GDIPlus_Startup() ; added by argumentum for this UDF's implementation ( AutoIt v3.3.14 ) due to the way the function is written ;~ Func _GDIPlus_Startup($sGDIPDLL = Default, $bRetDllHandle = False) ;~ $__g_iGDIPRef += 1 <-- I believe this aspect should be coded differently in "GDIPlus.au3" ;~ If $__g_iGDIPRef > 1 Then Return True Local $aSize[2] Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) If Not $hFamily Then Return SetError(1, 0, $aSize) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) $aSize[0] = $bRound ? Round($aInfo[0].Width, 0) : $aInfo[0].Width $aSize[1] = $bRound ? Round($aInfo[0].Height, 0) : $aInfo[0].Height _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return $aSize EndFunc ;==>_GDIPlus_MeasureString Func OnAutoItExit_UDF_WM_CTLCOLORLISTBOX() For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) Next If $__g_iGDIPRef Then _GDIPlus_Shutdown() EndFunc ;==>OnAutoItExit_UDF_WM_CTLCOLORLISTBOX #EndRegion GUICtrlComboSetColors UDF Example() Func Example() ; Create GUI GUICreate("ComboBox Set DROPDOWNLIST BgColor", 640, 300) Local $a_idCombo[7] = [6] $a_idCombo[1] = GUICtrlCreateCombo("", 2, 2, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[1], 0xEEEEEE, -2, Default) Example_FillTheCombo($a_idCombo[1]) GUICtrlCreateLabel("<<< change BG color, default theme && size ", 400, 4, 396, 296) $a_idCombo[2] = GUICtrlCreateCombo("", 2, 32, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[2], 0x0000FF, 0xFFFF00, 0) Example_FillTheCombo($a_idCombo[2]) GUICtrlCreateLabel("<<< change colors", 400, 34, 396, 296) $a_idCombo[3] = GUICtrlCreateCombo("", 2, 62, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[3], 0xdddddd, Default, 100) Example_FillTheCombo($a_idCombo[3]) GUICtrlCreateLabel("<<< change BG color, resize 100px. left", 400, 64, 396, 296) $a_idCombo[4] = GUICtrlCreateCombo("", 2, 92, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[4], Default, 0x0000FF, -100) Example_FillTheCombo($a_idCombo[4]) GUICtrlCreateLabel("<<< change FG color, resize 100px. right", 400, 94, 396, 296) $a_idCombo[5] = GUICtrlCreateCombo("", 2, 122, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[5], 0x00FFFF, 0x0000FF, 1) Example_FillTheCombo($a_idCombo[5]) GUICtrlCreateLabel("<<< change colors, resize auto left", 400, 124, 396, 296) $a_idCombo[6] = GUICtrlCreateCombo("", 2, 152, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($a_idCombo[6], 10, 400, 0, "Courier New") GUICtrlComboSetColors($a_idCombo[6], Default, Default, "2;Courier New;10") Example_FillTheCombo($a_idCombo[6]) GUICtrlCreateLabel("<<< default colors, resize auto right", 400, 154, 396, 296) Local $bttnArrayShow = GUICtrlCreateButton("Show array", 2, 296 - 27, 75, 25) Local $bttnStrMore = GUICtrlCreateButton("Longer str.", 102, 296 - 27, 75, 25) Local $idLorem = GUICtrlCreateLabel("", 195, 296 - 27, 50, 25) Local $bttnStrLess = GUICtrlCreateButton("Shorter str.", 252, 296 - 27, 75, 25) GUISetState(@SW_SHOW) WinActivate("ComboBox Set DROPDOWNLIST BgColor") ;~ Sleep(3500) ; you can reassign colors, size, or restore default ;~ GUICtrlComboSetColors($idCombo5, Default, Default, 300) ; this resets the Control back to default and changes $iExtendLeft ;~ GUICtrlComboSetColors($idCombo5, 0x0000FF, 0x00FFFF, -1) ; this changes the colors and keeps $iExtendLeft as it was ;~ GUICtrlComboSetColors($idCombo5, -1, -1, 300) ; using "-1" will keep the existing colors ;~ ; so in this case, only the $iExtendLeft is declared ;~ Example_FillTheCombo($idCombo5) ;~ Sleep(500) ; after removal, it will not repaint "hList", but then again, you're deleteing the control ;~ GUICtrlComboSetColors($idColors, -3) ;~ GUICtrlDelete($idCombo2) Local $iLorem = 5, $sLorem = "" Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Return Case $bttnArrayShow _ArrayDisplay($g__aWM_CTLCOLORLISTBOX, "$g__aWM_CTLCOLORLISTBOX") Case $bttnStrMore $iLorem += 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) Case $bttnStrLess $iLorem -= 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) EndSwitch WEnd EndFunc ;==>Example Func Example_FillTheCombo(ByRef $idComboCtrl) GUICtrlSetData($idComboCtrl, "") _GUICtrlComboBox_AddString($idComboCtrl, "something") _GUICtrlComboBox_AddString($idComboCtrl, "something else") _GUICtrlComboBox_AddString($idComboCtrl, "blah, blah, blah, blah") _GUICtrlComboBox_AddString($idComboCtrl, "Lorem will change") Local $a = _GUICtrlComboBox_GetListArray($idComboCtrl) GUICtrlSetData($idComboCtrl, $a[1]) EndFunc ;==>Example_FillTheCombo Func Example_LoremStr(ByRef $iLorem, ByRef $sLorem, ByRef $a_idCombo, ByRef $idLorem) Local Static $s = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat." $s &= " Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat." Local Static $i = 5, $a = StringSplit($s, " ") If $iLorem < 1 Then $iLorem = 1 If $iLorem > $a[0] Then $iLorem = $a[0] Local $x, $iLastEntry $sLorem = "" GUICtrlSetData($idLorem, $iLorem & ' words') For $x = 1 To $iLorem $sLorem &= $a[$x] & " " Next For $x = 1 To $a_idCombo[0] $iLastEntry = _GUICtrlComboBox_GetCount($a_idCombo[$x]) - 1 _GUICtrlComboBox_DeleteString($a_idCombo[$x], $iLastEntry) _GUICtrlComboBox_AddString($a_idCombo[$x], $sLorem) Next EndFunc ;==>Example_LoremStr new in v0.0.0.5: auto size the dropdown. You may also wanna take a look at ComboBox Color Background/Text subclass approach.
    1 point
  2. 1 point
  3. Why not just check if $ReadString has any text when the whitespace has been stripped. $ReadString = StringStripWS($ReadString, 8) if $ReadString then FileWrite($FileOpen, $ReadString & @CRLF)
    1 point
  4. This might be somewhat along the lines of what you're looking for. #include <MsgBoxConstants.au3> #include <File.au3> AutoItSetOption('MouseCoordMode', 0) ; setting the WINDOW RELATIVE COORDINATE MODE AutoItSetOption('SendKeyDelay', 5) ; setting the speed of typing and keys pressing to 0 (immidiately) $fileA = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_1.txt" $fileB = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_2.txt" $fileC = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_3.txt" $fileD = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_4.txt" $fileE = "D:\AutoIT\EPI\AutoIt_Parameter_Files\COPE_file_5.txt" $filenamesA = FileReadToArray($fileA) $filenamesB = FileReadToArray($fileB) $filenamesC = FileReadToArray($fileC) $filenamesD = FileReadToArray($fileD) $filenamesE = FileReadToArray($fileE) ;~ ;;;;;;;;;; READING THE TXT FILES ;;;;;;;;;; ;~ FileOpen($fileA, 0) ; opening the .txt file ;~ Global $filenamesA[_FileCountLines($fileA)] ;~ For $ii = 1 To _FileCountLines($fileA) ;~ $filenamesA[$ii - 1] = FileReadLine($fileA, $ii) ;~ Next ;~ FileClose($fileA) ; closing the .txt file ;~ FileOpen($fileB, 0) ; opening the .txt file ;~ Global $filenamesB[_FileCountLines($fileB)] ;~ For $ii = 1 To _FileCountLines($fileB) ;~ $filenamesB[$ii - 1] = FileReadLine($fileB, $ii) ;~ Next ;~ FileClose($fileB) ; closing the .txt file ;~ FileOpen($fileC, 0) ; opening the .txt file ;~ Global $filenamesC[_FileCountLines($fileC)] ;~ For $ii = 1 To _FileCountLines($fileC) ;~ $filenamesC[$ii - 1] = FileReadLine($fileC, $ii) ;~ Next ;~ FileClose($fileC) ; closing the .txt file ;~ FileOpen($fileD, 0) ; opening the .txt file ;~ Global $filenamesD[_FileCountLines($fileD)] ;~ For $ii = 1 To _FileCountLines($fileD) ;~ $filenamesD[$ii - 1] = FileReadLine($fileD, $ii) ;~ Next ;~ FileClose($fileD) ; closing the .txt file ;~ FileOpen($fileE, 0) ; opening the .txt file ;~ Global $filenamesE[_FileCountLines($fileE)] ;~ For $ii = 1 To _FileCountLines($fileE) ;~ $filenamesE[$ii - 1] = FileReadLine($fileE, $ii) ;~ Next ;~ FileClose($fileE) ; closing the .txt file ;;;;;;;;;; RUNNING THE LOOP ;;;;;;;;;; For $a = 0 To (UBound($filenamesA) - 1) ;~ For $b = 0 To (UBound($filenamesB) - 1) ;~ For $c = 0 To (UBound($filenamesC) - 1) ;~ For $d = 0 To (UBound($filenamesD) - 1) ;~ For $e = 0 To (UBound($filenamesE) - 1) Run("C:\Program Files (x86)\BrainVoyager\BrainVoyagerQX.exe") WinWait('Welcome') WinActivate('Welcome') Send('{ENTER}') ;;; open program WinWait('BrainVoyager QX') WinActivate('BrainVoyager QX') Send('{TAB DOWN}') Send('{ALT}') Send('{TAB UP}') Send('{LEFT 5}') Send('{DOWN 3}') Send('{ENTER 2}') Send($filenamesA[$a], 1) Send('{TAB}{TAB}{SPACE}') Sleep(10) WinWaitActive("COPE plugin for EPI distortion correction") Send('{TAB 6}') Send('{ENTER}') Send($filenamesB[$a], 1) Send('{TAB}{TAB}{SPACE}') Sleep(10) Send('{TAB 7}') Send('{ENTER}') Sleep(8000) Send('{RIGHT 2}') Send('{TAB 3}') Send('{ENTER}') Send($filenamesC[$a], 1) Send('{ENTER}') Send('{SHIFTDOWN}') Send('{TAB 7}') Send('{SHIFTUP}') Send('{ENTER}') Send($filenamesD[$a], 1) Send('{ENTER 2}') Send($filenamesE[$a], 1) Send('{ENTER}') Send('{TAB 3}') Send('{ENTER}') Sleep(15000) ;;; close program Send('{ESC}') Send('{CTRLDOWN}') Send('{q}') Send('{CTRLUP}') Next
    1 point
  5. Shouldn't be needed as I've changed the setup in a way we use %localappdata%\autoit3\scite to store the usersettings and you should have all rights to that directory. Jos
    1 point
  6. First, some opinions/suggestions--my apologies if the tone comes off harsh: A. Don't do anything that could be risky, whether for you personally or your employer. Test, test, test--using fake/example data/files instead of real data. B. There's some "interesting" language choices in your script you might want to change from a professionalism stand-point. C. Why are you using functions that you don't fully understand if you are concerned about risk? Secondly, some code analysis input and questions: A. The only thing I am seeing as potentially "destructive" is the FileMove operation. Could you employ FileCopy instead as to not alter the integrity or risk loss of the original file? Why is it important to rename the files in your desired manner? Is there a chance that files would be overwritten due to not unique file names, or is file overwriting a common occurance and you want to maintain "versioning"? B. One thing I am a little concerned about, but don't know what repercussions could occur is the call to _WinAPI_CreateFileEx doesn't have a follow-up closing function to clean up the handle (_WinAPI_CloseHandle). I notice that function is missing from the _WinAPI_ReadDirectoryChanges function as well, but it is referenced in the help article for _CreateFileEx; so I don't know how important it is. Having said that, nothing intrinsic about the functions is jumping out at me as being sensitive to major risk. I'd encourage you keep testing. Maybe create another script to produce mock files around the intervals you expect files to be made in production and let it run for as long as you'd expect your monitoring/renaming script to run unattended.
    1 point
  7. Just curious, have you tried running the SciTE editor as administrator? Since windows 10 I've noticed some programs aren't allowed to change their own settings unless I run them as administrator.
    1 point
  8. $exe = "C:\Users\Desktop\Micollab Status Toevoeger " & @DesktopWidth & " x " & @DesktopHeight & ".exe" If FileExists($exe) Then Run ($exe) Else MsgBox (0, "Not Supported", "Not supported") EndIf
    1 point
  9. yep. grade A disaster waiting to happen. could not be more wrong of a solution! good luck. Set up VMWare VMs for them to play in on their own network
    1 point
  10. You're just going about this totally wrong, these computers shouldn't be on the schools network they should be isolated to their own network, then give the students admin access to the computers. This way if they try to do something malicious they won't affect the school's network. Doing it any other way is just going to be a huge disaster waiting to happen.
    1 point
  11. Earthshine

    Can't compile with icon

    save this to a batch. all you really need to do is RESTART explorer, like this. This should not be done regularly, there should rarely be a need but I have seen it in all Windows operating systems. taskkill /f /im explorer.exe cd /d %userprofile%\AppData\Local del IconCache.db /a start explorer.exe I see this on VMs too when testing our product upgrades. Something happens and Windows doesn't get around to it. LOL.
    1 point
  12. SQLite json1 extension first appeared as an optional loadable module in version 3.9.0 dated 2015-10-14. It's now part of the amalgamation (a large monolithic C source with most used defaults) yet requires a compile directive to be built into the resulting DLL. It's easy to use it without messing with any compiler toolchain: current SQLite Expert version 5 offers it out of the box, so you can play with json functions right after installing it. Expert v5 is now stable enough to be used for almost any purpose, even if I have some griefs, features requests and small bugs to submit to Bogdan (the author). As a first step, familiarize yourself with the documentation and try the examples there, by using the SQL tab of Expert: http://www.sqlite.org/json1.html Once you feel comfortable with most/all json functions, confront with your actual use case(s). It works like a charm for both efficiently producing json-formatted output suitable for external consumption (e.g. to web server) or manipulating stored json data, all within SQLite fast code. A number of loadable extensions appeared alongside mainstream SQLite code, as you can see in the release history: http://www.sqlite.org/changes.html Search the page for the word "extension". Enjoy.
    1 point
  13. There is zero error checking whether the StringRegExp was successful and fail to understand what the For..Next is for. Jos
    1 point
  14. Well you don't say what the error is or why it doesn't work but there is a missing square bracket here in $codesave0] $codesave0] = StringReplace($code1[0], "src", "data-original")
    1 point
  15. I tweaked the the _GuiHole function in the _WinAPI_CreateRoundRectRgn example in the help file to produce this result. #include <winapi.au3> #include <WinAPIGdi.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0x0000) WinSetTrans($hGUI,"",100) _GuiHole($hGUI, 50, 50, 80, 30, 8, 8) GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit Wend Func _GuiHole($hWin, $iX, $iY, $iSizeW, $iSizeH, $iWidthEllipse, $iHeightEllipse) Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn, $aPos = WinGetPos($hWin) $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $aPos[2], $aPos[3]) $hInner_rgn = _WinAPI_CreateRoundRectRgn($iX, $iY, $iX + $iSizeW, $iY + $iSizeH, $iWidthEllipse, $iHeightEllipse) $hCombined_rgn = _WinAPI_CreateRoundRectRgn(0, 0, 0, 0, 0 ,0) _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF) _WinAPI_DeleteObject($hOuter_rgn) _WinAPI_DeleteObject($hInner_rgn) _WinAPI_SetWindowRgn($hWin, $hCombined_rgn) EndFunc ;==>_GuiHole
    1 point
  16. Yep if you do it that way it will add the same tooltip for all the input controls. It needs modding #Region #### Includes ################################ #include <ButtonConstants.au3> #include <ColorConstants.au3> #include <EditConstants.au3> #include <Excel.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GUIScrollbars_Ex.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #EndRegion #### Includes ################################ Opt('GUIOnEventMode', 1) HotKeySet('{ESC}', 'CloseProgram') #Region #### Globals ################################# ; these are integers that relate to where the controliDs are located in $g_aidControls. ; The control ID can be retrieved like so, $g_aidControls[$EMPPROCESS_INP] Global Enum _ ; values are 0 to 13 $FRONTMATTERGUI, _ ;_ gui 1 $BODYMATTERGUI, _ ;_ gui 2 $BACKMATTERGUI, _ ;_ gui 3 $TABCOUNT, _ ; #### IMPORTANT #### this must be after the last gui. it signifies how many tabs there will be and is used in other functions $EMPNUMBER_INP, _ ;_ employee number input id $EMPNAME_INP, _ ;_ employee name input id $EMPPROCESS_INP, _ ;_ employee process input id $AID_LBL, _ ;_ some label I don't know if you use id $AGREE_CHK, _ ;_ I agree checkbox id $ACCEPT_CHK, _ ;_ accept checkbox id $REJECT_CHK, _ ;_ reject checkbox id $LAYOUTONE_RDO, _ ;_ radio button for layout 1 selection $SUBMIT_BTN, _ ;_ submit button id $MAIN_TAB, _ ;_ main tab id $ARRAYMAX_ROWS ;_ number of rows to give the array its 0 based ; create the array to hold the remaining controlIDs. These can be referenced ; later when writing their values to the excel sheet Global $g_aidControls[$ARRAYMAX_ROWS] ; create the arrays to hold the all controlIDs that will be created on the tab guis by CreateTabGUIs() called by Draw_Tabs() function ; These can be referenced later when writing their values to the excel sheet Global _ $aid_FrontMatterGUI = '', _ $aid_BodyMatterGUI = '', _ $aid_BackMatterGUI = '' ; these are the tab names and will be used as the spreadsheet names when the report is submitted ; these have the same value as the Global Enum $FRONTMATTERGUI to $BACKMATTERGUI and are used in varios functions Global $g_asTabNames[$TABCOUNT] = [ _ ; values are 0 to 2 'Front Matter', _ 'Body Matter', _ 'Back Matter'] ; these are integers that relate to where the rows are for each set of controls in the $aid_FrontMatterGUI array etc ; they are also the same values as their matching strings index in the $g_asTabHeaderText array Global Enum _ ; values are 0 to 5 $ENTRYS_COL, _ $NA_COL, _ $NOERROR_COL, _ $WITHERROR_COL, _ $REMARKS_COL, _ $ARRAYMAX_COLS ; this is the array that holds the tab header text strings. These are written to the first row of the array that matches the tab and gui ; I.E - ; Tab = 'Front Matter' ; Array with the controlIDs = $aid_FrontMatterGUI Global $g_asTabHeaderText[$ARRAYMAX_COLS] = [ _ ; 0 based array 'Entry(s)', _ 'N/A', _ 'No Error', _ 'With Error', _ 'Remarks'] ; this keeps track of if the report layout is one or two Global $g_iMultipleSheets = 1 ; these keep track of the cells that need tweaking in the report Global _ $g_sHeaderCells = '', _ ;_ These are the strings above the inline controls such as Entry(s) N/A etc $g_sSectionCells = '', _ ;_ Sections, these are upper case strings like CATEGORY, HISTORY DATES $g_sTabNameCells = '' ;_ tab names #EndRegion #### Globals ################################# Global $hWnd_Previous Draw_GUI() While 1 ;~ $tGetMousePos = _WinAPI_GetMousePos() ;~ $hWnd = _WinAPI_WindowFromPoint($tGetMousePos) ;~ If $hWnd <> $hWnd_Previous Then ;~ $hWnd_Previous = $hWnd ;~ ConsoleWrite('ControlID: ' & _WinAPI_GetDlgCtrlID($hWnd) & @CRLF) ;~ EndIf Sleep(50) WEnd ; #### you need to fix this #### ; i have guessed the line as you are trying to use $sUserName but in the uncommented line it is used as a string ; still returns blank for me Func GetFullName($sUserName) ; I can't test this Local $strComputer = 'localhost' Local $objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\root\CIMV2') Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName & "'", "WQL", 0x10 + 0x20) If Not IsObj($colItems) Then Return SetError(1, 0, '') For $objItem In $colItems Return $objItem.FullName Next EndFunc ;==>GetFullName #Region #### CheckBox actions ######################## ; get the state of the checkbox Func CheckBox_ReturnStringState($id_ControlID) If GUICtrlRead($id_ControlID) = $GUI_CHECKED Then Return 'Checked' Return '' ;~ Return 'Unchecked' ; use this if you want it to return unchecked instead of blank EndFunc ;==>CheckBox_ReturnStringState ; inline check boxes Func NaChk_SetState() ; get the controlID of the checkbox that was clicked Local $i_ControlID = @GUI_CtrlId GUICtrlSetState(@GUI_CtrlId + 1, $GUI_UNCHECKED) ; uncheck the No Error checkbox GUICtrlSetState(@GUI_CtrlId + 2, $GUI_UNCHECKED) ; uncheck the With Error checkbox EndFunc ;==>NaChk_SetState Func NoErrorChk_SetState() ; get the controlID of the checkbox that was clicked Local $i_ControlID = @GUI_CtrlId GUICtrlSetState(@GUI_CtrlId - 1, $GUI_UNCHECKED) ; uncheck the NA checkbox GUICtrlSetState(@GUI_CtrlId + 1, $GUI_UNCHECKED) ; uncheck the With Error checkbox EndFunc ;==>NoErrorChk_SetState Func WithErrorChk_SetState() ; get the controlID of the checkbox that was clicked Local $i_ControlID = @GUI_CtrlId GUICtrlSetState(@GUI_CtrlId - 1, $GUI_UNCHECKED) ; uncheck the No Error checkbox GUICtrlSetState(@GUI_CtrlId - 2, $GUI_UNCHECKED) ; uncheck the NA checkbox EndFunc ;==>WithErrorChk_SetState ; accept, reject Func AcceptChk_Clicked() ; uncheck the reject control GUICtrlSetState($g_aidControls[$REJECT_CHK], $GUI_UNCHECKED) ; check if the submit button is to be enabled SubmitBtn_SetState() EndFunc ;==>AcceptChk_Clicked Func RejectChk_Clicked() ; uncheck the accept control GUICtrlSetState($g_aidControls[$ACCEPT_CHK], $GUI_UNCHECKED) SubmitBtn_SetState() EndFunc ;==>RejectChk_Clicked #EndRegion #### CheckBox actions ######################## #Region #### GUI Actions ############################# Func CloseProgram() Exit EndFunc ;==>CloseProgram ; create the scrolling guis and their controls that go on each of the tabs Func CreateTabGUIs(ByRef $as_Controls, ByRef $as_ToolTips, $i_ArrayRow, $h_MainGUI) ; create the gui for the controls and add it to the global controls array $g_aidControls[$i_ArrayRow] = GUICreate('', 770, 370, 23, 270, $WS_POPUP, $WS_EX_MDICHILD, $h_MainGUI) GUISetBkColor($COLOR_WHITE) ; create the temp array. This will hold all the controlIDs Local _ $aid_Temp[UBound($as_Controls)][$ARRAYMAX_COLS] = [[0]] ; this is a 0 based array with the same rows as the Local _ $s_Value = '' ; value to give the control Local _ $i_ArrayRowCount = 0 ; keeps track of number of array rows (controls rows added) Local _ ; variables for the control spacing $i_Left = 0, _ ;_ starting left position $i_Rows = 60, _ ;_ initial number of rows $i_Spacing = 60, _ ;_ control padding $i_Top = 18 ;_ initial top position For $i = 0 To UBound($aid_Temp) - 1 ; 0 to 70 rows of controls . if you add more this number will need to change ; get the value to add to the control from the array returned by InputControls_GetProperties() $s_Value = $as_Controls[$i][$i_ArrayRow] ; array is 0 based and has 53 elements filled ; don't create anymore controls if the value is blanks If Not $s_Value Then ExitLoop ; calculate additional spacing $i_Left = (Int($i / $i_Rows)) + $i_Spacing $i_Top = (30.7 * Mod($i, $i_Rows)) ; - 30 ; check if the string is upper case. Strip any none letter characters out for testing ; as digits/punctuation/whitespace will cause StringIsUpper() to return 0. If StringIsUpper(StringRegExpReplace($s_Value, '[^A-Za-z]', '')) Then ; assume its a section ; draw the input and add the controlID to the correct gui array $aid_Temp[$i][$ENTRYS_COL] = GUICtrlCreateLabel($s_Value, $i_Left - 50, $i_Top, 730, 20, $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1, 8, 800) GUICtrlSetColor(-1, $COLOR_BLACK) GUICtrlSetBkColor(-1, $COLOR_SILVER) ; set the other columns to 0 as there are no other controls being added $aid_Temp[$i][$NA_COL] = 0 $aid_Temp[$i][$NOERROR_COL] = 0 $aid_Temp[$i][$WITHERROR_COL] = 0 $aid_Temp[$i][$REMARKS_COL] = 0 Else ; assume it's a sub ; draw the input $aid_Temp[$i][$ENTRYS_COL] = GUICtrlCreateInput($s_Value, $i_Left - 50, $i_Top, 155, 20, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY), $WS_EX_TRANSPARENT) ; use an input GUICtrlSetBkColor(-1, $COLOR_WHITE) If $as_ToolTips[$i][$i_ArrayRow] <> '' Then GUICtrlSetTip(-1, $as_ToolTips[$i][$i_ArrayRow], 'Instructions:', $TIP_INFOICON) ;~ $aid_Temp[$i][0] = GUICtrlCreateLabel($s_Value, $i_Left - 50, $i_Top, 155, 40) ; use a label if you want ; draw the N/A check box $aid_Temp[$i][$NA_COL] = GUICtrlCreateCheckbox('', $i_Left + 165, $i_Top, 15, 20) GUICtrlSetOnEvent(-1, 'NaChk_SetState') ; draw the no error check box $aid_Temp[$i][$NOERROR_COL] = GUICtrlCreateCheckbox('', $i_Left + 260, $i_Top, 15, 20) GUICtrlSetOnEvent(-1, 'NoErrorChk_SetState') ; draw the with error check box $aid_Temp[$i][$WITHERROR_COL] = GUICtrlCreateCheckbox('', $i_Left + 355, $i_Top, 15, 20) GUICtrlSetOnEvent(-1, 'WithErrorChk_SetState') ; draw the edit control $aid_Temp[$i][$REMARKS_COL] = GUICtrlCreateEdit('', $i_Left + 440, $i_Top, 240, 24, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN)) EndIf $i_ArrayRowCount += 1 ; increase the number of rows added to the array Next ; add scroll bars to the current gui _GUIScrollbars_Generate($g_aidControls[$i_ArrayRow], 0, 2000) ; redim the array to remove any blanks ReDim $aid_Temp[$i_ArrayRowCount][$ARRAYMAX_COLS] ;~ _ArrayDisplay($aid_Temp, 'CreateTabGUIs ($aid_Temp)') ; for debugging ; returns a 0 based array of controlIDs Return $aid_Temp EndFunc ;==>CreateTabGUIs Func Draw_GUI() Local $h_MainGUI = GUICreate('Test Form', 820, 740, -1, -1) GUISetBkColor(0x38A7D2) GUISetOnEvent($GUI_EVENT_CLOSE, 'CloseProgram') GUICtrlCreatePic(@ScriptDir & '\Image.jpg', 690, 15, 120, 120) GUICtrlCreateLabel('Welcome: ' & GetFullName(@UserName), 17, 135, 500, 16) GUICtrlSetColor(-1, $COLOR_WHITE) GUICtrlSetFont(-1, 9, $FW_BOLD) #Region #### Main Menu ########################### Local $id_Menu = GUICtrlCreateMenu('File') GUICtrlCreateMenuItem('Close', $id_Menu) GUICtrlSetOnEvent(-1, 'CloseProgram') GUICtrlCreateMenuItem('Export', $id_Menu) GUICtrlSetOnEvent(-1, 'MainMenu_FileExport') $id_Menu = GUICtrlCreateMenu('Edit') GUICtrlSetState(-1, $GUI_DISABLE) $id_Menu = GUICtrlCreateMenu('Option') GUICtrlSetState(-1, $GUI_DISABLE) $id_Menu = GUICtrlCreateMenu('View') GUICtrlCreateMenuItem('Exit', $id_Menu) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, 'MainMenu_ViewExit') $id_Menu = GUICtrlCreateMenu('Help') GUICtrlCreateMenuItem('About', $id_Menu) GUICtrlSetOnEvent(-1, 'MainMenu_HelpAbout') #EndRegion #### Main Menu ########################### #Region #### Employee Info ####################### GUICtrlCreateGroup('Employee Information', 16, 8, 281, 121) GUICtrlCreateLabel('Emp#:', 33, 35, 35, 17) $g_aidControls[$EMPNUMBER_INP] = GUICtrlCreateInput('1234567', 72, 32, 217, 21) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel('Name:', 33, 59, 35, 17) $g_aidControls[$EMPNAME_INP] = GUICtrlCreateInput(GetFullName(@UserName), 72, 56, 217, 21) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel('Process:', 24, 83, 45, 17) $g_aidControls[$EMPPROCESS_INP] = GUICtrlCreateInput('First Process', 72, 80, 217, 21) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup('', -99, -99, 1, 1) #EndRegion #### Employee Info ####################### #Region #### whatever this is #################### GUICtrlCreateLabel('AID:', 25, 170, 25, 17) GUICtrlSetFont(-1, 10, $FW_BOLD) $g_aidControls[$AID_LBL] = GUICtrlCreateLabel('ABZ123456', 60, 170, 90, 17) ; remove this if you don't alter the text GUICtrlSetColor(-1, $COLOR_WHITE) GUICtrlSetFont(-1, 10, $FW_BOLD) #EndRegion #### whatever this is #################### #Region #### Confirmation Checkboxes ############# $g_aidControls[$AGREE_CHK] = GUICtrlCreateCheckbox(' I agree that I have checked the entry(s) above.', 25, 655, 265, 17) GUICtrlSetOnEvent(-1, 'SubmitBtn_SetState') $g_aidControls[$ACCEPT_CHK] = GUICtrlCreateCheckbox(' Accept', 25, 675, 60, 17) GUICtrlSetOnEvent(-1, 'AcceptChk_Clicked') GUICtrlCreateLabel('*', 85, 680, 40, 17) GUICtrlSetColor(-1, $COLOR_RED) GUICtrlSetFont(-1, 10, $FW_BOLD) $g_aidControls[$REJECT_CHK] = GUICtrlCreateCheckbox(' Reject', 25, 695, 60, 17) GUICtrlSetOnEvent(-1, 'RejectChk_Clicked') GUICtrlCreateLabel('*', 85, 695, 40, 17) GUICtrlSetColor(-1, $COLOR_RED) GUICtrlSetFont(-1, 10, $FW_BOLD) #EndRegion #### Confirmation Checkboxes ############# #Region #### Submit Report Group ################# $Group1 = GUICtrlCreateGroup("Submit Report", 600, 647, 200, 65) $g_aidControls[$LAYOUTONE_RDO] = GUICtrlCreateRadio("Layout 1", 615, 665, 70, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetOnEvent(-1, 'Layout1_Selected') GUICtrlCreateRadio("Layout 2", 615, 685, 70, 17) GUICtrlSetOnEvent(-1, 'Layout2_Selected') $g_aidControls[$SUBMIT_BTN] = GUICtrlCreateButton('Submit Report', 690, 667, 100, 33) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetOnEvent(-1, 'Report_Submit') GUICtrlCreateGroup("", -99, -99, 1, 1) #EndRegion #### Submit Report Group ################# #Region #### Create Tabs ######################### Draw_Tabs($h_MainGUI) #EndRegion #### Create Tabs ######################### GUISetState(@SW_SHOW, $h_MainGUI) ; show the main gui Sleep(105) ; add a sleep to try and get them to show at the same time GUISetState(@SW_SHOW, $g_aidControls[$FRONTMATTERGUI]) ; show the first tab gui EndFunc ;==>Draw_GUI ; draw the group on controls that sit above the tab guis Func Draw_TabHeaders() ; this draws the headers over the columns on the tab gui. The values are pulled from the $g_asTabHeaderText array GUICtrlCreateGroup('', 30, 215, 755, 50) GUICtrlCreateLabel($g_asTabHeaderText[$ENTRYS_COL], 50, 232, 80, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_BORDER)) GUICtrlCreateLabel($g_asTabHeaderText[$NA_COL], 238, 232, 40, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_BORDER)) GUICtrlCreateLabel($g_asTabHeaderText[$NOERROR_COL], 315, 232, 70, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_BORDER)) GUICtrlCreateLabel($g_asTabHeaderText[$WITHERROR_COL], 405, 232, 85, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_BORDER)) GUICtrlCreateLabel($g_asTabHeaderText[$REMARKS_COL], 590, 232, 90, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_BORDER)) EndFunc ;==>Draw_TabHeaders Func Draw_Tabs($h_MainGUI) ; create the main tab control and add it's ID to the control array $g_aidControls[$MAIN_TAB] = GUICtrlCreateTab(20, 190, 780, 455, $WS_EX_MDICHILD) GUICtrlSetOnEvent(-1, 'TabChange') ; do summat on tab change ; declare arrays for the input properties Local $as_Controls = 0 Local $as_ToolTips = 0 ; get the strings that will populate the gui controls from the excel sheet. These will be the "Entry{s}" ; set the range as the first column 'A', to the last column that contains the layout for the guis (currently 'C') ; ### add some error checking for InputControls_GetProperties #### InputControls_GetProperties( _ $as_Controls, _ ; load the array for the input control strings $as_ToolTips, _ ; load the array for the input controls tooltips CellRange_CreateFromInteger($FRONTMATTERGUI + 1, $TABCOUNT)) ; set the cell range to read ; loop to create the required number of tabs, guis and their controls For $i = $FRONTMATTERGUI To $TABCOUNT - 1 ; - 1 because $g_asTabNames is a 0 based array GUICtrlCreateTabItem($g_asTabNames[$i]) ; create the headers for each tab. These are listed in $g_asTabHeaderText Draw_TabHeaders() Switch $i Case $FRONTMATTERGUI ; gui 1 ; create the array containing the controlIDs. returns a 0 based array of controlIDs $aid_FrontMatterGUI = CreateTabGUIs($as_Controls, $as_ToolTips, $i, $h_MainGUI) Case $BODYMATTERGUI ; gui 2 ; create the array containing the controlIDs $aid_BodyMatterGUI = CreateTabGUIs($as_Controls, $as_ToolTips, $i, $h_MainGUI) Case $BACKMATTERGUI ; gui 3 ; create the array containing the controlIDs $aid_BackMatterGUI = CreateTabGUIs($as_Controls, $as_ToolTips, $i, $h_MainGUI) EndSwitch ; switch to the main gui and tab after creating the new guis or else the control creation gets bollocksed Up ; and the tabs or controls are not visible GUISwitch($h_MainGUI, $g_aidControls[$MAIN_TAB]) Next GUICtrlCreateTabItem('') EndFunc ;==>Draw_Tabs Func TabChange() Switch GUICtrlRead($g_aidControls[$MAIN_TAB]) Case $FRONTMATTERGUI ; Front Matter tab GUISetState(@SW_SHOW, $g_aidControls[$FRONTMATTERGUI]) GUISetState(@SW_HIDE, $g_aidControls[$BODYMATTERGUI]) GUISetState(@SW_HIDE, $g_aidControls[$BACKMATTERGUI]) Case $BODYMATTERGUI ; body Matter tab GUISetState(@SW_HIDE, $g_aidControls[$FRONTMATTERGUI]) GUISetState(@SW_SHOW, $g_aidControls[$BODYMATTERGUI]) GUISetState(@SW_HIDE, $g_aidControls[$BACKMATTERGUI]) Case $BACKMATTERGUI ; back matter tab GUISetState(@SW_HIDE, $g_aidControls[$FRONTMATTERGUI]) GUISetState(@SW_HIDE, $g_aidControls[$BODYMATTERGUI]) GUISetState(@SW_SHOW, $g_aidControls[$BACKMATTERGUI]) EndSwitch EndFunc ;==>TabChange #EndRegion #### GUI Actions ############################# #Region #### Main Menu Action ######################## Func MainMenu_FileExport() ; add commands later EndFunc ;==>MainMenu_FileExport Func MainMenu_HelpAbout() ; add commands later EndFunc ;==>MainMenu_HelpAbout Func MainMenu_ViewExit() ; add commands later EndFunc ;==>MainMenu_ViewExit #EndRegion #### Main Menu Action ######################## #Region #### Spreadsheet Actions ##################### ; create an array of values that are read from the controls on the tabs GUI ; these will be written to the spreadsheet later Func ArrayRow_SetValues(ByRef $aid_ControlID, $i_Row) Local $v_Value = '' Local $s_BoldCells = '' ; loop through the array columns For $i = $ENTRYS_COL To $REMARKS_COL ; get the value from the supplied array $v_Value = $aid_ControlID[$i_Row][$i] ; check if the value is a controlID If IsNumber($v_Value) Then If Not $v_Value Then ; it's 0 so no control to read $v_Value = '' ; set a blank string Else $v_Value = GUICtrlRead($aid_ControlID[$i_Row][$i]) ; assume it's a header or heading indentifier string If StringIsUpper(StringRegExpReplace($v_Value, '[^A-Za-z]', '')) Then $g_sSectionCells &= 'A' & $i_Row + 1 & ',' If StringInStr($v_Value, $g_asTabHeaderText[0]) Then $g_sHeaderCells &= 'A' & $i_Row + 1 & ',' EndIf Else ; assume it's a tab name $aid_ControlID[$i_Row][$i] = $v_Value If StringInStr($v_Value, $g_asTabHeaderText[0]) Then $g_sHeaderCells &= 'A' & $i_Row + 1 & ',' If StringInStr(_ArrayToString($g_asTabNames, '|'), $v_Value) Then $g_sTabNameCells &= 'A' & $i_Row + 1 & ',' ExitLoop EndIf ; do different things based on the specified control If $i = $ENTRYS_COL Or $i = $REMARKS_COL Then ; these are input controls ; write the value to the array $aid_ControlID[$i_Row][$i] = $v_Value Else ; these are checkbox controls ; get the checked state of the control $aid_ControlID[$i_Row][$i] = CheckBox_ReturnStringState($aid_ControlID[$i_Row][$i]) EndIf Next EndFunc ;==>ArrayRow_SetValues ; create an excel range from 2 numbers Func CellRange_CreateFromInteger($i_Start, $i_End = 0) ; assumes there is only one number to convert to a range If Not $i_End Then Return _Excel_ColumnToLetter($i_Start) ; convert any numbers to excel column letters Return _Excel_ColumnToLetter($i_Start) & ':' & _Excel_ColumnToLetter($i_End) EndFunc ;==>CellRange_CreateFromInteger Func CellRange_CreateFromString($s_Range, $v_AddRange) ; if $v_AddRange is a number then convert the number to a letter for the range If IsNumber($v_AddRange) Then $v_AddRange = _Excel_ColumnToLetter($v_AddRange) ; trim any leading\trailing comma symbols before splitting $s_Range = StringRegExpReplace($s_Range, "\A[,]+|[,]+\Z", "") ; split the comma delimited range Local $as_Split = StringSplit($s_Range, ',') ; loop through the array For $i = 1 To $as_Split[0] ; update the array element $as_Split[$i] = $as_Split[$i] & ':' & StringRegExpReplace($as_Split[$i], '[[:alpha:]]+', $v_AddRange) Next ; return a string that will be used as a cell range Return _ArrayToString($as_Split, ',', 1) EndFunc ;==>CellRange_CreateFromString Func CellRange_ResetGlobalValues() $g_sHeaderCells = '' $g_sSectionCells = '' $g_sTabNameCells = '' EndFunc ;==>CellRange_ResetGlobalValues Func GetEmployeeInfo() Local $as_Employee[6] = [ _ ; 0 based array 'Emp# : ' & GUICtrlRead($g_aidControls[$EMPNUMBER_INP]), _ 'Name : ' & GUICtrlRead($g_aidControls[$EMPNAME_INP]), _ 'Process: ' & GUICtrlRead($g_aidControls[$EMPPROCESS_INP]), _ 'AID : ' & GUICtrlRead($g_aidControls[$AID_LBL]), _ 'I agree that I have checked the entry(s) above.', _ 'Accepted'] ; update the last array element if the reject checkbox is checked If GUICtrlRead($g_aidControls[$REJECT_CHK]) = $GUI_CHECKED Then $as_Employee[5] = 'Rejected' ; return thte array for writing to the spreadsheet Return $as_Employee EndFunc ;==>GetEmployeeInfo Func InputControls_GetProperties(ByRef $as_Controls, ByRef $as_ToolTips, $s_Range = 'A') ; set the path to the file that has the values for the inputs Local $s_ExcelFile = @ScriptDir & '\Sample.xlsx' ; #### add some error checking for these excel functions #### Local $o_Excel = _Excel_Open(False) Local $o_WorkBook = _Excel_BookOpen($o_Excel, $s_ExcelFile) $as_Controls = _Excel_RangeRead($o_WorkBook, Default, $o_WorkBook.Sheets('Controls').Usedrange.Columns($s_Range), 2) $as_ToolTips = _Excel_RangeRead($o_WorkBook, Default, $o_WorkBook.Sheets('ToolTips').Usedrange.Columns($s_Range), 2) _Excel_Close($o_Excel) EndFunc ;==>InputControls_GetProperties ; go through the tabs and controls and write the values to a spreadsheet Func WriteArrayValuesToSpreadsheet($o_WorkBook, $i_Layout = Report_GetLayout()) Local _ ; $aa_ControlArrays is an array of arrays. The arrays have the controlIDs for the relevant tab gui controls $aa_ControlArrays[$TABCOUNT + 1] = [$TABCOUNT, $aid_FrontMatterGUI, $aid_BodyMatterGUI, $aid_BackMatterGUI], _ $as_Values = 0, _ ; the array that will hold the values of the gui controls $as_Temp = 0 ;_ a temp array for modding ; set the number of loop to perform when writing. ; If layout 1 is used, there will be a seperate spreadsheet for each tab so 3 loops ; if layout 2 is used all the tabs are written to one spreadsheet so only 1 loop is needed Local _ $i_Total = $aa_ControlArrays[0], _ ;_ set as default layout 1 and loop through the all the arrays $i_Concatenated = 0 ;_ Set the state of the array being processed 0 = multiple 1 = 1 concatenated array ; Change if the layout is 2 and just loop through the concatenated array If $i_Layout > 1 Then $i_Total = 1 ; layout 2 selected #Region #### only needed for cell outside borders if not interested the code can be deleted ### Local _ ; Excel constants not in ExcelConstants.au3 $i_xlAutomatic = -4105, _ $i_xlContinuous = 1, _ $i_xlThin = 2, _ $i_xlEdgeLeft = 7, _ $i_xlEdgeTop = 8, _ $i_xlEdgeBottom = 9, _ $i_xlEdgeRight = 10 #EndRegion #### only needed for cell outside borders if not interested the code can be deleted ### ; loop through the arrays For $i = 1 To $i_Total ; on each loop copy the nested array to a temp one, this will be filled with the values of the controls $as_Values = $aa_ControlArrays[$i] ; set a starting array _ArrayInsert($as_Values, 0, _ArrayToString($g_asTabHeaderText, '|')) ; add the headers to each array #Region #### This determines which array(s) to use for the write #### If $i_Layout = 2 Then _ArrayInsert($as_Values, 0, $g_asTabNames[0]) ; add the first tab name to the array ; loop through the remaining arrays For $j = 2 To $TABCOUNT ; $TABCOUNT = 3 $as_Temp = $aa_ControlArrays[$j] ; copy to a temp array so we can add the tab names and headet text _ArrayInsert($as_Temp, 0, $g_asTabNames[$j - 1]) ; add the next tab name to the array _ArrayInsert($as_Temp, 1, _ArrayToString($g_asTabHeaderText, '|')) ; add the next header text ; joining them $as_Values _ArrayConcatenate($as_Values, $as_Temp) Next EndIf #EndRegion #### This determines which array(s) to use for the write #### ; loop through the temp array For $j = 0 To UBound($as_Values) - 1 ; update the array row with the control values ArrayRow_SetValues($as_Values, $j) Next ; activate the sheet $o_WorkBook.Sheets($i).Activate ; write the array to an excel spreadsheet _Excel_RangeWrite($o_WorkBook, $i, $as_Values) If @error Then Return SetError(@error, @extended, 'Error Writing ' & $g_asTabNames[$i - 1] & ' to sheet') ; write the employee info If $i = 1 Then _Excel_RangeWrite($o_WorkBook, $i, GetEmployeeInfo(), CellRange_CreateFromInteger($ARRAYMAX_COLS + 2) & '1') If @error Then Return SetError(@error, @extended, 'Error Writing Employee info to sheet') ; adjust the sheet properties whilst it's active With $o_WorkBook.ActiveSheet If $g_iMultipleSheets Then ; we are writing multiple sheets ; set the sheet name .Name = $g_asTabNames[$i - 1] EndIf ; set the column letters that will auto size to fit the text .Columns(CellRange_CreateFromInteger($ENTRYS_COL + 1, $ARRAYMAX_COLS + 2)).AutoFit ; this is where the cells that have the tab names in get nodified #Region #### Tab Name Cells #### If $g_sTabNameCells Then $g_sTabNameCells = CellRange_CreateFromString($g_sTabNameCells, $ARRAYMAX_COLS) ; set the font weight as bold .Range($g_sTabNameCells).Font.FontStyle = 'Bold' ; set the tab name cells back colour .Range($g_sTabNameCells).Interior.Color = 0xBFBFBF ; merge the cells .Range($g_sTabNameCells).Merge ; centre align the cells .Range($g_sTabNameCells).HorizontalAlignment = $xlCenter EndIf #EndRegion #### Tab Name Cells #### ; this is where the cells that have Entry(s), N/A, No Error etc get modified #Region #### Header Cells #### If $g_sHeaderCells Then $g_sHeaderCells = CellRange_CreateFromString($g_sHeaderCells, $ARRAYMAX_COLS) ; set the font weight as bold .Range($g_sHeaderCells).Font.FontStyle = 'Bold' ; centre align the cells .Range($g_sHeaderCells).HorizontalAlignment = $xlCenter ; set the header cells back colour .Range($g_sHeaderCells).Interior.Color = 0xFFE6CC EndIf #EndRegion #### Header Cells #### ; this is where the cells that have the section text like CATEGORY, HISTORY DATES etc get modified #Region #### Section Cells #### If $g_sSectionCells Then $g_sSectionCells = CellRange_CreateFromString($g_sSectionCells, $ARRAYMAX_COLS) ; set the font weight as bold .Range($g_sSectionCells).Font.FontStyle = 'Bold' ; set the header cells back colour .Range($g_sSectionCells).Interior.Color = 0xDAEFE2 ; add outside borders .Range($g_sSectionCells).Borders($i_xlEdgeTop).LineStyle = $i_xlContinuous .Range($g_sSectionCells).Borders($i_xlEdgeLeft).LineStyle = $i_xlContinuous .Range($g_sSectionCells).Borders($i_xlEdgeRight).LineStyle = $i_xlContinuous .Range($g_sSectionCells).Borders($i_xlEdgeBottom).LineStyle = $i_xlContinuous EndIf #EndRegion #### Section Cells #### EndWith CellRange_ResetGlobalValues() Sleep(20) Next $o_WorkBook.Sheets(1).Activate ; activate the first sheet CellRange_ResetGlobalValues() EndFunc ;==>WriteArrayValuesToSpreadsheet #EndRegion #### Spreadsheet Actions ##################### #Region #### Submit Report Actions ################### Func Layout1_Selected() $g_iMultipleSheets = 1 EndFunc ;==>Layout1_Selected Func Layout2_Selected() $g_iMultipleSheets = 0 EndFunc ;==>Layout2_Selected ; gets the currently selected layout type for the report Func Report_GetLayout() ; return the state of the layout 1 radio button If GUICtrlRead($g_aidControls[$LAYOUTONE_RDO]) = $GUI_CHECKED Then Return 1 Return 2 EndFunc ;==>Report_GetLayout ; submit your report Func Report_Submit() SplashTextOn("submit", "Submitting report...", 300, 50, -1, -1, $DLG_NOTITLE + $DLG_TEXTVCENTER, '', '', $FW_BOLD) ;~ Local $o_WorkBook = '' ; open an excel instance Local $o_Excel = _Excel_Open(False) If @error Then Return SetError(1, _ MsgBox($MB_SYSTEMMODAL, _ '_Excel_Open', _ 'Error creating the Excel application object' & @CRLF & '@error = ' & @error & ', @extended = ' & @extended), 0) ; set the number of sheets to add when opening a new workbook Local $iSheets = $TABCOUNT If Not $g_iMultipleSheets Then $iSheets = 1 ; open a new excel book Local $o_WorkBook = _Excel_BookNew($o_Excel, $iSheets) ; $TABCOUNT is the number of tabs in your program and so the number of sheets we create for submitting If @error Then Return SetError(2, _ MsgBox($MB_SYSTEMMODAL, _ '_Excel_BookNew', _ 'Error creating new workbook' & @CRLF & '@error = ' & @error & ', @extended = ' & @extended), _Excel_Close($o_Excel)) ;~ ; this will read the control values to an array and write the array to an excel file WriteArrayValuesToSpreadsheet($o_WorkBook) If Not @error Then ; create a file path based on time. If you want to keep overwriting the files the create a definite file name ; and use the commented line Local $s_FilePath = @ScriptDir & '\Report_' & @YEAR & '-' & @MON & '-' & @MDAY & '_' & @HOUR & @MIN & @SEC & '.xlsx' ; ; save the created report and overwrite the previous ;~ _Excel_BookSaveAs($o_WorkBook, $s_FilePath, $xlWorkbookDefault, True) ; save the created report to a new file _Excel_BookSaveAs($o_WorkBook, $s_FilePath, $xlWorkbookDefault) If @error Then MsgBox($MB_SYSTEMMODAL, _ "_Excel_BookSaveAs", _ "Error saving workbook to '" & $s_FilePath & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) EndIf _Excel_Close($o_Excel) ; update the splash text ControlSetText("submit", "", "Static1", 'Opening report...') ; open the report, remove if you don't need to ShellExecute($s_FilePath) SplashOff() EndFunc ;==>Report_Submit ; enables or disables the submit report button Func SubmitBtn_SetState() If BitAND( _ ; check if two checkxoes are checked GUICtrlRead($g_aidControls[$AGREE_CHK]), _ ; if the agree checkbox GUICtrlRead($g_aidControls[$ACCEPT_CHK]), _ ; and the accept checkbox $GUI_CHECKED) = $GUI_CHECKED _ ; are checked Or _ ; they may not both be checked so check the reject checkbox BitAND( _ GUICtrlRead($g_aidControls[$AGREE_CHK]), _ ; if the agree checkbox GUICtrlRead($g_aidControls[$REJECT_CHK]), _ ; and the reject checkbox $GUI_CHECKED) = $GUI_CHECKED _ ; are checked Then ; enable the button GUICtrlSetState($g_aidControls[$SUBMIT_BTN], $GUI_ENABLE) Else ; disable the button GUICtrlSetState($g_aidControls[$SUBMIT_BTN], $GUI_DISABLE) EndIf EndFunc ;==>SubmitBtn_SetState #EndRegion #### Submit Report Actions ################### Sample.xlsx
    1 point
  17. JLogan3o13

    Excel Functions

    Moved to the appropriate forum.
    1 point
  18. water

    Excel Functions

    Something like this: #include <GUIConstantsEx.au3> #include <Excel.au3> $oExcel = _Excel_Open() Example() Func Example() GUICreate("Example", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1) $idFile = GUICtrlCreateInput("", 10, 35, 300, 20) Local $idBtn = GUICtrlCreateButton("Ok", 40, 75, 60, 20) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _Excel_Close($oExcel) ExitLoop Case $idBtn $sInput = GUICtrlRead($idFile) If StringStripWS($sInput, $STR_STRIPLEADING + $STR_STRIPTRAILING) <> "" Then _ExcelSearch($sInput) EndSwitch WEnd EndFunc ;==>Example Func _ExcelSearch($sSearchString) Local $sFilePath = "C:\temp\test.xlsx" ; "D:\Anu_WorkFolder\Components.xlsx" Local $oWorkbook = _Excel_BookOpen($oExcel, $sFilePath, Default, Default, True) Local $aResult = _Excel_RangeFind($oWorkbook, $sSearchString, Default, Default, $xlWhole) For $i = 0 To UBound($aResult, 1) - 1 ConsoleWrite("Address: " & $aResult[$i][2] & ", value: " & $aResult[$i][3] & @CRLF) ; Cell that fits the search string ConsoleWrite(" " & $oWorkbook.Activesheet.Range($aResult[$i][2]).Offset(0, 1).value & @CRLF) ; Value of the cell right to the found cell Next _Excel_BookClose($oWorkbook) EndFunc ;==>_ExcelSearch
    1 point
×
×
  • Create New...