Jump to content
Sign in to follow this  
Jags

TreeView Populated from Excel or Array

Recommended Posts

Jags

Looking to build a TreeView dynamically from an Array (Array built from excel sheet)

Have not made the excel sheet yet, so I'm open to suggestions on layout so as to make it easiest as possible to get it into a treeview.

Thinking each row could be a item to add with the columns defining the placement in the trees, Like:

Cells(1,1) = "Level 1 Parent Name"

Cells(1,2) = "Level 2 Parent Name"

Cells(1,3) = "Level 3 Parent Name"

Cells(1,4) = "Add this item"

Cells(1,5) = ""

When value = ""  then

     Create entire branch or any part of it that doesn't already exist.

advance to next row

For processing speed I'd probably want to work with an array, like:

$aExcelData = _ExcelReadSheetToArray($oExcel,2,1,$LastUsedRow,$LastUsedCol)

Can someone help me with the loop?  or maybe point to tool that may do this?

Share this post


Link to post
Share on other sites
water

I use the following example to create a treeview.

Func _AD_GetOUTreeView($sAD_OU, $hAD_TreeView)

    Local $sSeparator = "\", $aAD_Temp, $sAD_Line, $iAD_Level
    Local $aAD_OUs = _AD_GetAllOUs($sAD_OU, $sSeparator)
    If @error <> 0 Then Return SetError(@error, @extended, 0)
    Local $aAD_TreeView[$aAD_OUs[0][0] + 1][3] = [[$aAD_OUs[0][0], 3]]
    For $i = 1 To $aAD_OUs[0][0]
        $aAD_Temp = StringSplit($aAD_OUs[$i][0], $sSeparator)
        $aAD_TreeView[$i][0] = StringFormat("%" & $aAD_Temp[0] - 1 & "s", "") & "#" & $aAD_Temp[$aAD_Temp[0]]
        $aAD_TreeView[$i][1] = $aAD_OUs[$i][1]
    Next
    _GUICtrlTreeView_BeginUpdate($hAD_TreeView)
    Local $ahAD_Node[50]
    For $iAD_Index = 1 To $aAD_TreeView[0][0]
        $sAD_Line = StringSplit(StringStripCR($aAD_TreeView[$iAD_Index][0]), @TAB)
        $iAD_Level = StringInStr($sAD_Line[1], "#")
        If $iAD_Level = 0 Then ExitLoop
        If $iAD_Level = 1 Then
            $ahAD_Node[$iAD_Level] = _GUICtrlTreeView_Add($hAD_TreeView, 0, StringMid($sAD_Line[1], $iAD_Level + 1))
            $aAD_TreeView[$iAD_Index][2] = $ahAD_Node[$iAD_Level]
        Else
            $ahAD_Node[$iAD_Level] = _GUICtrlTreeView_AddChild($hAD_TreeView, $ahAD_Node[$iAD_Level - 1], StringMid($sAD_Line[1], $iAD_Level + 1))
            $aAD_TreeView[$iAD_Index][2] = $ahAD_Node[$iAD_Level]
        EndIf
    Next
    _GUICtrlTreeView_EndUpdate($hAD_TreeView)
    Return $aAD_TreeView

EndFunc   ;==>_AD_GetOUTreeView

The data to display starts after the "'#" sign.

The number of spaces before the "#" denotes the level in the treeview. The root has zero spaces, all entries on the first level one etc.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jags

Thanks water,

But, I'm very new and don't understand how to apply that solution.  Maybe some more basic building blocks would help me get this on my own.

For example:

if $x = "This Particular Existing TreeView Item String"

How do I search the tree for $x and return its location so I can add a child?

Share this post


Link to post
Share on other sites
water

My function creates the TreeView from an array in one go.

The array could look like this example:
 

"#Root"

" #Level1 - First entry"

"  #Level1.1 - First entry"

"   #Level1.1.1 - First entry"

"  #Level1.1 - Second entry"

"  #Level1.1 - Third entry"

" #Level1 - Second entry"

So you would need to create the entries in Excel top-down.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jags

I'm missing _AD_GetAllOUs

Share this post


Link to post
Share on other sites
water

I've stripped down the example. The data for the TreeView is stored in an array on line 42.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>

$iSelected = _TreeView()
Exit

Func _TreeView()
    Local $Msg, $hSelection
    Local $sTitle = "Treeview Test"
    Local $hGUI = GUICreate($sTitle, 743, 683, -1, -1)
    Local $hTree = GUICtrlCreateTreeView(6, 6, 600, 666, -1, $WS_EX_CLIENTEDGE)
    Local $bExit = GUICtrlCreateButton("Exit", 624, 8, 97, 33)
    Local $bExpand = GUICtrlCreateButton("Expand", 624, 56, 97, 33)
    Local $bCollapse = GUICtrlCreateButton("Collapse", 624, 104, 97, 33)
    Local $bSelect = GUICtrlCreateButton("Select", 624, 152, 97, 33)
    Local $aTreeView = _TV_Populate($hTree)
    GUISetState(@SW_SHOW)
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE, $bExit
                Exit
            Case $bExpand
                _GUICtrlTreeView_Expand($hTree)
            Case $bCollapse
                _GUICtrlTreeView_Expand($hTree, 0, False)
            Case $bSelect
                $hSelection = _GUICtrlTreeView_GetSelection($hTree)
                For $i = 1 To $aTreeView[0][0]
                    If $hSelection = $aTreeView[$i][2] Then ExitLoop
                Next
                Return $aTreeView[$i][1]
        EndSwitch
    WEnd
EndFunc   ;==>_TreeView

Func _TV_Populate($hTree)

    ; Test data
    Local $aTreeView[6][3] = [[5, 3], ["#Root", "ID1"], [" #Level1 Entry 1", "ID2"], [" #Level1 Entry 2", "ID3"], ["  #Level 2 Entry 1", "ID4"], [" #Level1 Entry 3", "ID5"]]
    _GUICtrlTreeView_BeginUpdate($hTree)
    Local $ahNode[50]
    For $iIndex = 1 To $aTreeView[0][0]
        $iLevel = StringInStr($aTreeView[$iIndex][0], "#")
        If $iLevel = 0 Then ExitLoop
        If $iLevel = 1 Then
            $ahNode[$iLevel] = _GUICtrlTreeView_Add($hTree, 0, StringMid($aTreeView[$iIndex][0], $iLevel + 1))
            $aTreeView[$iIndex][2] = $ahNode[$iLevel]
        Else
            $ahNode[$iLevel] = _GUICtrlTreeView_AddChild($hTree, $ahNode[$iLevel - 1], StringMid($aTreeView[$iIndex][0], $iLevel + 1))
            $aTreeView[$iIndex][2] = $ahNode[$iLevel]
        EndIf
    Next
    _GUICtrlTreeView_EndUpdate($hTree)
    Return $aTreeView

EndFunc   ;==>_TV_Populate

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

Jags,

Building on waters technique...

#include <array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

; arrays used to populate treeview controls
;
;  [0] - parent name ('0' is root level)
;  [1] - element name
;
; note - If the parent does not exist the element will be skipped.
;        If a child is named the same as a previous parent it cannot become a parent (see example in TreeView #2).

Local $aTV1[100][2] = [ _
        ['0', '01'], _
        ['0', '02'], _
        ['0', '03'], _
        ['0', '04'], _
        ['0', '05'], _
        ['01', '01-01'], _
        ['01', '01-02'], _
        ['03', '03-01'], _
        ['03', '03-02'], _
        ['03', '03-03'], _
        ['04', '04-01'], _
        ['01', '01-03'], _
        ['01', '01-04'], _
        ['0', '06'], _
        ['04-01', '04-01-01'], _
        ['04-01', '04-01-02'], _
        ['04-01-02', '04-01-02-01'], _
        ['09', '09-01'], _
        ['01-03', '01-03-01'], _
        ['01-03-01', '01-03-01-01'], _
        ['01-03-01', '01-03-01-02'], _
        ['01-03-01', '01-03-01-03'], _
        ['01-03-01-02', '01-03-01-02-01'], _
        ['04', '04-02'] _
        ]

local $aTV2[100][2] = [ _
        ['0','AA'], _
        ['0','Aa'], _
        ['0','BB'], _
        ['0','bb'], _
        ['AA','AA-01'], _
        ['AA','AA-02'], _
        ['BB','BB-01'], _
        ['bb','bb-01'], _
        ['Aa','Aa-01'], _
        ['bb','bb-02'], _
        ['bb-01','bb-01-01'], _
        ['bb-01','bb-01-02'], _
        ['bb-01-02','bB-01-02-01'], _
        ['bb-01-02-01','bb-01-02-01-01'], _
        ['bb-01-02','bb-01'], _
        ['bb-01','added to first bb-01'], _
        ['aA','aA-01'] _
                        ]

Local $gui010 = GUICreate('TreeView Example',500,500)
Local $tv010 = GUICtrlCreateTreeView(10, 30, 200, 400)
guictrlcreatelabel('TreeView #1',10,10,100,20)
guictrlsetfont(-1,8.5,600)
Local $tv011 = GUICtrlCreateTreeView(290, 30, 200, 400)
guictrlcreatelabel('TreeView #2',290,10,100,20)
guictrlsetfont(-1,8.5,600)
_pop_treeview($tv010,$aTV1)
_pop_treeview($tv011,$aTV2)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
    EndSwitch
WEnd

func _pop_treeview($hTV,$array)

    ; populate the treeview control
    ;
    ; note - _My_GUICtrlTreeView_FindItem is a replacement for UDF
    ;        _GUICtrlTreeView_FindItem to accomodate case sensitivity

    _GUICtrlTreeView_BeginUpdate($hTV)
    For $1 = 0 To UBound($array) - 1
        if $array[$1][0] = '' then exitloop
        If $array[$1][0] = '0' Then
            _GUICtrlTreeView_Add($hTV, 0, $array[$1][1])
        Else
            $hitem = _My_GUICtrlTreeView_FindItem($hTV, $array[$1][0])
            If $hitem <> 0 Then
                _GUICtrlTreeView_AddChild($hTV, $hitem, $array[$1][1])
            Else
                ConsoleWrite('! Skipping ' & $array[$1][0] & ' cannot find parent' & @LF)
            endif
        EndIf
    Next
    _GUICtrlTreeView_EndUpdate($hTV)
    _GUICtrlTreeView_Expand($hTV)
endfunc

Func _My_GUICtrlTreeView_FindItem($hWnd, $sText, $fInStr = False, $hStart = 0)

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    If $hStart = 0 Then $hStart = _GUICtrlTreeView_GetFirstItem($hWnd)
    While $hStart <> 0x00000000
        Local $sItem = _GUICtrlTreeView_GetText($hWnd, $hStart)
        Switch $fInStr
            Case False
                If $sItem == $sText Then Return $hStart
            Case True
                If StringInStr($sItem, $sText) Then Return $hStart
        EndSwitch
        $hStart = _GUICtrlTreeView_GetNext($hWnd, $hStart)
    WEnd
EndFunc   ;==>_GUICtrlTreeView_FindItem

kylomas


Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • TheAutomator
      By TheAutomator
      Is there a (simple) way to make your script using a picture-control to resize the gui?
      This would be useful for a transparant pop-up window with a custom made theme using picture controls:
      $Form = GUICreate('', 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUICtrlCreatePic(@scriptdir & "\resize_win.bmp", 0, 73, 20, 51) ; some api call or code telling the os to use this picture as a resize border GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While True if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit WEnd  
      EDIT: to make it more clear what i wanna do, if you go with the mouse arrow over the border of a re-sizable window the arrow changes to a "resize" arrow, you click and drag the border and then the window size adjusts to the mouse position until you release the mouse button.
      I want my picture control to be used the same way as the resize border to resize my window.
    • robertocm
      By robertocm
      I'm using this for replacing text strings in the VBProject of all excel files in a folder and subfolders.
      I have the same text string in several lines and those lines could have some differences between files: then not feasible for .ReplaceLine method
      I'm not interested in placing all the code in a xla AddIn, because the code is similar but not exactly the same in all the files.
       
      Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <File.au3> #include <WinAPIFiles.au3> #include <Excel.au3> $oMyError = ObjEvent("AutoIt.Error", "ErrFunc") ;Install a custom error handler Global $iEventError ; to be checked to know if com error occurs. Must be reset after handling. Global Const $sMessage = "Select Folder" Global $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then MsgBox(0, "", "No folder was selected.") Exit EndIf Global $bFileOpen ;Look for excel files in selected directory and all subdirectories Global $aFileList = _FileListToArrayRec($sFileSelectFolder, "*.xlsm", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) If Not @error Then Local $oAppl = _Excel_Open(Default, Default, False, Default, True) ;If @error Then Exit MsgBox(0, "Error", "Error _Excel_Open" & @CRLF & "@error = " & @error & ", @extended = " & @extended) For $i = 1 To $aFileList[0] $bFileOpen = _WinAPI_FileInUse($aFileList[$i]) If $bFileOpen = 0 Then ;ShellExecute($aFileList[$i]) Local $oWorkbook = _Excel_BookOpen($oAppl, $aFileList[$i]) ;If @error Then Exit MsgBox(0, "Error", "Error _Excel_BookOpen: " & $sFilePath & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oProject = $oWorkbook.VBProject ;From: Adapt VBA in a workbook using VBA / http://www.snb-vba.eu/index_en.html ;2.7.2 Macromodule delete With $oProject .VBComponents.Remove(.VBComponents("SplashText")) If $iEventError Then Consolewrite("SplashText Form not found: " & $aFileList[$i] & @CRLF) $iEventError = 0 ; Reset after displaying a COM Error occurred EndIf .VBComponents.Import("C:\Documents and Settings\XP\Escritorio\PLANTILLAS_EXPORT\SplashText.frm") EndWith ;3.2.1.8 Macro: delete With $oProject.VBComponents("Actual").CodeModule ;3.2.1.2 Macro: find If .Find("Sub Check_NumPed(", 1, 1, -1, -1) Then ;Note: using '+ 1' at the end of the line because i'm used to add an empty line between procedures (see vba help for ProcCountLines) .DeleteLines( .ProcStartLine("Check_NumPed", 0), .ProcCountLines("Check_NumPed", 0) + 1) EndIf EndWith ;Check if range name exists. If not create named ranges If Not IsObj($oWorkbook.Sheets("DATOS").Evaluate("Booking_DestPort")) Then ;If Not IsObj($oWorkbook.Sheets("DATOS").Range("Booking_DestPort")) Then If $oWorkbook.Sheets("DATOS").Range("AC7").value = "DestPort" Then $oWorkbook.Names.Add("Booking_DestPort", "=DATOS!$AC$8") Else ConsoleWrite("-> Not: 'DestPort' in AC7" & @TAB & $aFileList[$i] & @CRLF) EndIf If $oWorkbook.Sheets("DATOS").Range("AD7").value = "FinalDest" Then $oWorkbook.Names.Add("Booking_FinalDest", "=DATOS!$AD$8") Else ConsoleWrite("-> Not: 'FinalDest' in AD7" & @TAB & $aFileList[$i] & @CRLF) EndIf EndIf ;Open VBE Editor (like Alt+F11) $oAppl.VBE.MainWindow.Visible = True ;$oAppl.VBE.Windows("Inmediato").Visible = True ;https://www.autoitscript.com/forum/topic/77545-resolved-vbaofficeexcel-experts/ ;Spiff59, Aug 2008 ;Local $oModules = $oProject.VBComponents ;Local $oModules = $oWorkbook.VBProject.VBComponents ;$oModules.Item(1).CodeModule.CodePane.Show ;$oModules.Item(1).Activate ; With $oModules.Item($y).CodeModule ; .ReplaceLine (1 , "Sub SpellCheck()") ; .DeleteLines (10, 1) ; .InsertLines (7 , "TEST") ; EndWith ;Wait 30 seconds for the window to appear. Local $hWnd = WinWait("Microsoft Visual Basic - ", "Proyecto - VBAProjec", 30) WinActivate($hWnd) WinWaitActive($hWnd, "", 30) If WinActive($hWnd, "") Then ;Sleep(100) ;Send("{F7}") $oProject.VBComponents("Actual").Activate ;Wait 30 seconds for the window to appear. Local $hWnd2 = WinWait(" - [Actual (Código)]", "Proyecto - VBAProject", 30) WinActivate($hWnd2) WinWaitActive($hWnd2, "", 30) ;First Replace If WinActive($hWnd2, "") Then Send("{CTRLDOWN}h{CTRLUP}") ;Wait 30 seconds for the window to appear. Local $hWnd3 = WinWait("Reemplazar", "&Procedimiento actua", 30) WinActivate($hWnd3) WinWaitActive($hWnd3, "", 30) Sleep(100) Send('Sheets("DATOS").Range("AC8")') Sleep(200) Send("{TAB}") Sleep(100) ;Send("{DEL}") Send('Range("Booking_DestPort")') Sleep(200) ControlClick("Reemplazar", "", "[ID:4892]") Sleep(100) Send("{ALTDOWN}z{ALTUP}") Local $hWnd4 = WinWait("Microsoft Visual Basic", "Se ha buscado en la ", 2) ;WinActivate($hWnd4) ;WinWaitActive($hWnd4, "", 3) If WinActive($hWnd4, "") Then Sleep(100) Send("{SPACE}") Else Consolewrite("Not found 1: " & $aFileList[$i] & @CRLF) Local $hWnd5 = WinWait("Microsoft Visual Basic", "No se encontró", 0) ;WinActivate($hWnd5) ;WinWaitActive($hWnd5, "", 2) Sleep(100) Send("{SPACE}") EndIf Sleep(100) If WinActive($hWnd3, "") Then ;Alt+F4 Send("!{F4}") Sleep(100) EndIf EndIf ;Second Replace If WinActive($hWnd2, "") Then Send("{CTRLDOWN}h{CTRLUP}") ;Wait 30 seconds for the window to appear. Local $hWnd3 = WinWait("Reemplazar", "&Procedimiento actua", 30) WinActivate($hWnd3) WinWaitActive($hWnd3, "", 30) Sleep(100) Send('Sheets("DATOS").Range("AD8")') Sleep(200) Send("{TAB}") Sleep(100) Send('Range("Booking_FinalDest")') Sleep(200) ControlClick("Reemplazar", "", "[ID:4892]") Sleep(100) Send("{ALTDOWN}z{ALTUP}") Local $hWnd4 = WinWait("Microsoft Visual Basic", "Se ha buscado en la ", 2) ;WinActivate($hWnd4) ;WinWaitActive($hWnd4, "", 3) If WinActive($hWnd4, "") Then Sleep(100) Send("{SPACE}") Else Consolewrite("Not found 2: " & $aFileList[$i] & @CRLF) Local $hWnd5 = WinWait("Microsoft Visual Basic", "No se encontró", 0) ;WinActivate($hWnd5) ;WinWaitActive($hWnd5, "", 2) Sleep(100) Send("{SPACE}") EndIf Sleep(100) If WinActive($hWnd3, "") Then ;Alt+F4 Send("!{F4}") Sleep(100) EndIf EndIf ;Close VBE Editor If WinActive($hWnd2, "") Then $oAppl.VBE.ActiveWindow.Close ;Send("^{F4}") ;Sleep(100) ;Send("^s") $oAppl.VBE.MainWindow.Visible = False ;Sleep(100) ;Send("!{F4}") EndIf EndIf _Excel_BookClose($oWorkbook, True) ;If @error Then Exit MsgBox(0, "Error", "Error _Excel_BookClose: " & $sFilePath & @CRLF & "@error = " & @error & ", @extended = " & @extended) EndIf Next Else MsgBox(16, "Error", "No files were found in the folder specified.") EndIf _Excel_Close($oAppl) ;If @error Then Exit MsgBox(0, "Error", "Error _Excel_Close" & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;This is a custom error handler Func ErrFunc() $HexNumber = Hex($oMyError.number, 8) ;~ MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ ;~ "Number is: " & $HexNumber & @CRLF & _ ;~ "WinDescription is: " & $oMyError.windescription) ConsoleWrite("-> We intercepted a COM Error !" & @CRLF & _ "-> err.number is: " & @TAB & $HexNumber & @CRLF & _ "-> err.source: " & @TAB & $oMyError.source & @CRLF & _ "-> err.windescription: " & @TAB & $oMyError.windescription & _ "-> err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF) $iEventError = 1 ; Use to check when a COM Error occurs EndFunc ;==>ErrFunc  
    • lattey
      By lattey
      hi,
      i have checkboxes and each checkbox that checked, i put in array. 
      now, im stuck on how to loop the checked array and store in in one variable. what i can do now, is only write the result into a text file. 
      below is the code:
      #include <GUIConstantsEx.au3> ;~ #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <Array.au3> Global $Count = 3 Global $CheckBoxP[$Count] Global $step[$Count] global $array1[1] Global $ExitResult $hGUI = GUICreate("Summary Steps", 500, 400) GUISetFont(12, 400, "Tahoma") GUICtrlCreateLabel( "Please Select the Summary Steps for Script Check", 70, 20) GUISetFont(10, 400, "Tahoma") Global $array_Pstep[3] = ["fix2","fix1","fix3"] global $step[3] = ["2","3","4"] $Spacing = 50 For $i = 0 To UBound($array_Pstep) - 1 $CheckBoxP[$i] = GUICtrlCreateCheckbox($array_Pstep[$i], 80, $Spacing + (20 * $i), 65, 17) Next $submit = GUICtrlCreateButton("Submit",180, 280, 80, 30) $exit = GUICtrlCreateButton("Exit",180, 320, 80, 30) GUISetState() While 1 $Msg = GUIGetMsg() Select case $Msg=$submit For $i = 0 To $Count - 1 If GUICtrlRead($CheckBoxP[$i]) = $GUI_CHECKED Then _ArrayAdd($array1, $step[$i]) EndIf Next Global $logfilerray = @WorkingDir & "\checkedlist.txt" FileDelete ($logfilerray) Global $readlogfile = FileOpen($logfilerray,1) for $a = 1 to UBound($array1) - 1 ;~ $var=$array1[$a] FileWriteLine($readlogfile,$array1[$a]) Next FileClose($readlogfile) Exit case $Msg=$exit $ExitResult = MsgBox(1,"Summary Step", "Continue to Exit ?") if $ExitResult = 1 Then ;ok Exit EndIf Exit EndSelect WEnd  
    • timmy2
      By timmy2
      I have the impression that the traditional method for processing responses to a GUI is to assign variables to each GUICreateButton (or Pic) and then use Switch/Case/Endswitch to detect when any Control is clicked.  In the tutorials I've seen about Koda it appears to use this method, too.
      While 1 Global $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Pic2 Call("verizon") Case $Pic3 Call("skype") Case $PicExit Exit EndSwitch WEnd But in a few examples I've seen a script use a different method. The script always includes the following option near the top:
      Opt("GUIOnEventMode", 1) ...and then, later, after creating each Control for the GUI, there's the function, GUICtrlSetOnEvent.  In these cases a very simple While/WEnd loop is used to wait for the user to respond. 
      I happened to employ this second method in a recent script where I used "canned" controls (checkbox and buttons). Later in the same script I used the GuiCreatePic and Switch/Case/EndSwitch method because my GUI was all custom images. (I'm not sure if that's necessary, but it's what I've deduced.) The second GUI failed to respond to any mouse clicks, but eventually I figured out the cause was the GUIOnEvenMode being enabled at the top of the script.
      This is when I realized I don't understand the reasoning behind choosing between these two methods. And I'm having no luck phrasing an appropriate search criterion. Is there an overview somewhere that explains the two methods and -- most importantly -- describes when each is appropriate?
    • gahhon
      By gahhon
      Hi Guys,
      I was trying to read some data from the excel file and without opening the file. But I tried a lot of methods, it still open the file.
      And also, I am able to capture the ColumnA value but not Column B.
      Thanks for advance information.
      Global $oDataA, $oDataB Call ("ExcelRead", "B2", "C2") Func ExcelRead($oColumnA, $oColumnB) Local $oPath = @ScriptDir & "\MyFile.xlsx" Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, $oPath, 1, 0) $oDataA = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnA) $oDataB = _Excel_RangeRead($oWorkbook, "Sheet 1", $oColumnB) MsgBox(0, "Test Value", $oDataA & ", " & $oDataB) EndFunc  
×