Rimoun

Button works for one time only then gives error

15 posts in this topic

#1 ·  Posted

Hello everyone

I would like to have some help regarding my issue.

I am trying to extract some information from excel sheet, I use _Excel_RangeFind then I get the array for the value then I check the array. In case the array is true the next will be to get some information based on the extracted array if no array because the value is not found it gives a messages box that the value is not found.

My problem that the button works for one time only if i tried any value which exist in the sheet it gives me that value not found.

I suspect that there is a problem regarding While loop.

here is my code

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#Include <GuiListBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <ExcelConstants.au3>

if FileExists ("result.txt") Then
   Sleep (100)
Else
   readxl()
   EndIf


Global $oExcel = _Excel_Open(False,False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel Error", "Error opening workbook '" & $oWorkbook & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oExcel)
    Exit
 EndIf

Local $lab1 = _Excel_RangeRead($oWorkbook, Default,"B1")
Local $lab2 = _Excel_RangeRead($oWorkbook, Default,"C1")
Local $lab3 = _Excel_RangeRead($oWorkbook, Default,"D1")
Local $lab4 = _Excel_RangeRead($oWorkbook, Default,"E1")

Global $sResult1,$sResult2,$sResult3,$sResult4,$sResult5,$sResult6

Global $asKeyWords = stringsplit (FileRead (@ScriptDir & "\result.txt"),@CRLF)
Global Const $xlUp = -4162
;~ _Main()


    Local $hGUI, $hList, $hInput, $aSelected, $sChosen, $hUP, $hDOWN, $hENTER, $hESC
    Local $sCurrInput = "", $aCurrSelected[2] = [-1, -1], $iCurrIndex = -1, $hListGUI = -1

   $hGUI = GUICreate("Rimo System", 253, 270, 192, 124)
Global $hInput = GUICtrlCreateInput("", 24, 48, 169, 21)
Global $Label1 = GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25)
GUICtrlSetFont(-1, 14, 800, 0, "MS Serif")
Global $Input2 = GUICtrlCreateInput("", 72, 144, 161, 21)
Global $Input3 = GUICtrlCreateInput("", 72, 176, 161, 21)
Global $Input4 = GUICtrlCreateInput("", 72, 208, 161, 21)
Global $Input5 = GUICtrlCreateInput("", 72, 240, 161, 21)
$Input6 = GUICtrlCreateInput("", 72, 272, 161, 21)
$Input7 = GUICtrlCreateInput("", 72, 304, 161, 21)
$Button1 = GUICtrlCreateButton("Get Info", 72, 88, 89, 33)
$Label2 = GUICtrlCreateLabel("Label2", 16, 144, 36, 17)
GUICtrlSetData( -1,$lab1)
$Label3 = GUICtrlCreateLabel("Label3", 16, 176, 36, 17)
GUICtrlSetData( -1,$lab2)
$Label4 = GUICtrlCreateLabel("Label4", 16, 208, 36, 17)
GUICtrlSetData( -1,$lab3)
$Label5 = GUICtrlCreateLabel("Label5", 16, 240, 36, 17)
GUICtrlSetData( -1,$lab4)
$Label6 = GUICtrlCreateLabel("", 16, 272, 36, 17)
$Label7 = GUICtrlCreateLabel("", 16, 304, 36, 17)
$Button2 = GUICtrlCreateButton("Cancel", 112, 416, 121, 25)

    GUISetState(@SW_SHOW, $hGUI)
Global $sSearch = guictrlread ($hInput)
    $hUP = GUICtrlCreateDummy()
    $hDOWN = GUICtrlCreateDummy()
    $hENTER = GUICtrlCreateDummy()
    $hESC = GUICtrlCreateDummy()
    Dim $AccelKeys[4][2] = [["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER], ["{ESC}", $hESC]]
    GUISetAccelerators($AccelKeys)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
             Case $Button2
                Exit
             Case $Button1

               Global $aResult = _Excel_RangeFind($oWorkbook, guictrlread($hInput) ,"A2:A2000")
               Global $aExtract = _ArrayExtract($aResult, 0, 0, 2, 2)


               if _elementExists($aExtract,0) Then
               getdata()
               Else

               MsgBox(0,"","Value Does Not Exist")
    


               EndIf

            Case $hESC
                If $hListGUI <> -1 Then ; List is visible.
                    GUIDelete($hListGUI)
                    $hListGUI = -1
                Else
                    ExitLoop
                EndIf

            Case $hUP
                If $hListGUI <> -1 Then ; List is visible.
                    $iCurrIndex -= 1
                    If $iCurrIndex < 0 Then
                        $iCurrIndex = 0
                    EndIf
                    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
                EndIf

            Case $hDOWN
                If $hListGUI <> -1 Then ; List is visible.
                    $iCurrIndex += 1
                    If $iCurrIndex > _GUICtrlListBox_GetCount($hList) - 1 Then
                        $iCurrIndex = _GUICtrlListBox_GetCount($hList) - 1
                    EndIf
                    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
                EndIf

            Case $hENTER
                If $hListGUI <> -1 And $iCurrIndex <> -1 Then ; List is visible and a item is selected.
                    $sChosen = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                EndIf

            Case $hList
                $sChosen = GUICtrlRead($hList)
        EndSwitch

        Sleep(10)
        $aSelected = _GetSelectionPointers($hInput)
        If GUICtrlRead($hInput) <> $sCurrInput Or $aSelected[1] <> $aCurrSelected[1] Then ; Input content or pointer are changed.
            $sCurrInput = GUICtrlRead($hInput)
            $aCurrSelected = $aSelected ; Get pointers of the string to replace.
            $iCurrIndex = -1
            If $hListGUI <> -1 Then ; List is visible.
                GUIDelete($hListGUI)
                $hListGUI = -1
            EndIf
            $hList = _PopupSelector($hGUI, $hListGUI, _CheckInputText($sCurrInput, $aCurrSelected)) ; ByRef $hListGUI, $aCurrSelected.
        EndIf
        If $sChosen <> "" Then
            GUICtrlSendMsg($hInput, 0x00B1, $aCurrSelected[0], $aCurrSelected[1]) ; $EM_SETSEL.
            _InsertText($hInput, $sChosen)
            $sCurrInput = GUICtrlRead($hInput)
            GUIDelete($hListGUI)
            $hListGUI = -1
            $sChosen = ""
        EndIf
    WEnd
    GUIDelete($hGUI)


Func _CheckInputText($sCurrInput, ByRef $aSelected)
    Local $sPartialData = ""
    If (IsArray($aSelected)) And ($aSelected[0] <= $aSelected[1]) Then
        Local $aSplit = StringSplit(StringLeft($sCurrInput, $aSelected[0]), " ")
        $aSelected[0] -= StringLen($aSplit[$aSplit[0]])
        If $aSplit[$aSplit[0]] <> "" Then
            For $A = 1 To $asKeyWords[0]
                If StringLeft($asKeyWords[$A], StringLen($aSplit[$aSplit[0]])) = $aSplit[$aSplit[0]] And $asKeyWords[$A] <> $aSplit[$aSplit[0]] Then
                    $sPartialData &= $asKeyWords[$A] & "|"
                EndIf
            Next
        EndIf
    EndIf
    Return $sPartialData
EndFunc   ;==>_CheckInputText

Func _PopupSelector($hMainGUI, ByRef $hListGUI, $sCurr_List)
    Local $hList = -1
    If $sCurr_List = "" Then
        Return $hList
    EndIf
    $hListGUI = GUICreate("", 280, 160, 23, 62, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_MDICHILD), $hMainGUI)
    $hList = GUICtrlCreateList("", 0, 0, 170, 150, BitOR(0x00100000, 0x00200000))
    GUICtrlSetData($hList, $sCurr_List)
    GUISetControlsVisible($hListGUI) ; To Make Control Visible And Window Invisible.
    GUISetState(@SW_SHOWNOACTIVATE, $hListGUI)
    Return $hList
EndFunc   ;==>_PopupSelector

Func _InsertText(ByRef $hEdit, $sString)
    #cs
        Description: Insert A Text In A Control.
        Returns: Nothing
    #ce
    Local $aSelected = _GetSelectionPointers($hEdit)
    GUICtrlSetData($hEdit, StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString & StringTrimLeft(GUICtrlRead($hEdit), $aSelected[1]))
    Local $iCursorPlace = StringLen(StringLeft(GUICtrlRead($hEdit), $aSelected[0]) & $sString)
    GUICtrlSendMsg($hEdit, 0x00B1, $iCursorPlace, $iCursorPlace) ; $EM_SETSEL.
EndFunc   ;==>_InsertText

Func _GetSelectionPointers($hEdit)
    Local $aReturn[2] = [0, 0]
    Local $aSelected = GUICtrlRecvMsg($hEdit, 0x00B0) ; $EM_GETSEL.
    If IsArray($aSelected) Then
        $aReturn[0] = $aSelected[0]
        $aReturn[1] = $aSelected[1]
    EndIf
    Return $aReturn
EndFunc   ;==>_GetSelectionPointers

Func GUISetControlsVisible($hWnd) ; By Melba23.
    Local $aControlGetPos = 0, $hCreateRect = 0, $hRectRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    Local $iLastControlID = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1))
    For $i = 3 To $iLastControlID
        $aControlGetPos = ControlGetPos($hWnd, '', $i)
        If IsArray($aControlGetPos) = 0 Then ContinueLoop
        $hCreateRect = _WinAPI_CreateRectRgn($aControlGetPos[0], $aControlGetPos[1], $aControlGetPos[0] + $aControlGetPos[2], $aControlGetPos[1] + $aControlGetPos[3])
        _WinAPI_CombineRgn($hRectRgn, $hCreateRect, $hRectRgn, 2)
        _WinAPI_DeleteObject($hCreateRect)
    Next
    _WinAPI_SetWindowRgn($hWnd, $hRectRgn, True)
    _WinAPI_DeleteObject($hRectRgn)
 EndFunc


 Func _elementExists($array, $element)
    If $element > UBound($array)-1 Then Return False ; element is out of the array bounds
    Return True ; element is in array bounds
 EndFunc

 Func getdata()





;~ Local
$sResult1 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","B"))
;~ Local
$sResult2 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","C"))
;~ Local
$sResult3 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","D"))
;~ Local
$sResult4 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","E"))
;~ Local
$sResult5 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","F"))
;~ Local
$sResult6 = _Excel_RangeRead($oWorkbook, Default,StringReplace(StringReplace ($aExtract[0],"$",""),"A","G"))


guictrlsetdata($Input2,$sResult1)
guictrlsetdata($Input3,$sResult2)
guictrlsetdata($Input4,$sResult3)
guictrlsetdata($Input5,$sResult4)
guictrlsetdata($Input6,$sResult5)
guictrlsetdata($Input7,$sResult6)

_Excel_Close($oExcel,Default,True)



EndFunc


Func readxl()
   Global $oExcel = _Excel_Open(False,False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeFind Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Global $oWorkbook = _Excel_BookOpen($oExcel, "D:\info.xlsx",False,False)

LOcal Const $xlUp = -4162
With $oWorkbook.ActiveSheet ; process active sheet
    $oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell) ; get a Range that contains the last used cells
    $iRowCount = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column)).Rows.Count ; get the the row count for the range starting in row/column 1 and ending at the last used row/column
    $iLastCell = .Cells($iRowCount + 1, "B").End($xlUp).Row
    ProgressOn("Copying Cells", "Copying Cells progress", "0%")

For $i = 2 to $iLastCell
  Local $total = Int(($i/$iLastCell)*100)
    Local $sResult3 = _Excel_RangeRead($oWorkbook, Default, "A" & $i)
    FileWriteLine("result.txt",$sResult3)
    ProgressSet(($i/$iLastCell)*100, $total & "%")

Next
;~  FileWrite("result.txt",$sResult3)
 ProgressSet(100, "Done", "Complete")
 Sleep (1500)
ProgressOff()

   _Excel_Close($oExcel,Default,True)

   EndWith
EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Do you have an excel sheet to try this with?, make sure there is no personal\private info inside.

Some suggestions about the code. Don't declare Globals in functions, or locals in loops. A lot of the variable have already been declared and you are declaring the again with the same values.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

Can you post an excel sheet so I can try it with your code?.  It's hard to try and pinpoint a reason for your button issue

Share this post


Link to post
Share on other sites

#4 ·  Posted

Why are you closing Excel at the bottom of the getdata function?

Share this post


Link to post
Share on other sites

#5 ·  Posted

19 minutes ago, Danp2 said:

Why are you closing Excel at the bottom of the getdata function?

I think it's just that the code needs tidying and reorganizing. There are a few improvements that could be made.

1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted

@benners Very true. However, I believe the crux of the issue is that he's closing Excel and then attempting to perform additional actions in Excel.

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I agree. I would expect the button to show the "Value Does Not Exist" message on the attempts due to unchecked errors from the _Excel_RangeFind and\or _ArrayExtract functions.

@Rimoun Try Danp2's suggestion and comment out the line below just as a test. If the button works multiple times then that's the issue and it needs to be moved somewhere else

_Excel_Close($oExcel, Default, True)

 

Edited by benners
1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted

19 minutes ago, benners said:

I agree. I would expect the button to show the "Value Does Not Exist" message on the attempts due to unchecked errors from the _Excel_RangeFind and\or _ArrayExtract functions.

@Rimoun Try Danp2's suggestion and comment out the line below just as a test. If the button works multiple times then that's the issue and it needs to be moved somewhere else

_Excel_Close($oExcel, Default, True)

 

Thanks Guys for help, that solved my issue 

Sorry for the messy way the I wrote the code with it.

attached the sample file that I used with the script.

I appreciate your valuable assistance.

Thanks

info.xlsx

Share this post


Link to post
Share on other sites

#9 ·  Posted

No need to apologize, most of us have been there. When I see others code, it sometimes feels like I still am there. Now I can test my changes, I'll have a look and post back.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Well, after the initial loading, when I selected 1001 from the list and pressed Get Info button, I got an error from the excel udf. As I understand it, the basic operation is to read the information from the sheet, load the Staff# into the listbox, when the Staff# is selected, pressing Get Info should get the related info, Name. Dept, Joining and Id and input them into the inputs. Is this correct?

The other labels that are created but not visible because the GUI is to small, they are the text of the excel columns, like Id etc?.

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted

37 minutes ago, benners said:

Well, after the initial loading, when I selected 1001 from the list and pressed Get Info button, I got an error from the excel udf. As I understand it, the basic operation is to read the information from the sheet, load the Staff# into the listbox, when the Staff# is selected, pressing Get Info should get the related info, Name. Dept, Joining and Id and input them into the inputs. Is this correct?

The other labels that are created but not visible because the GUI is to small, they are the text of the excel columns, like Id etc?.

Yes everything exactly as u said. the script will work if u replaced the excel udf as the old has a problem, there is a post was talking about that, in case u didnt find i can shRe my amended excel udf, the problem in rangefind function, just

Share this post


Link to post
Share on other sites

#12 ·  Posted

That's Ok, thanks for the info, I'll have a search. It is easier to read all the sheet in one go into an array then use the array from there on, so that's how I'll work it.

1 person likes this

Share this post


Link to post
Share on other sites

#13 ·  Posted

Well try this. I have commented a lot of things but if there's anything you don't know then just post. The AutoIt Wiki is a good place to pick up info and there's a thread on Best Practices here that's worth a read. I picked up a lot from both.

I changed the top input for a combo box, 

I kept your other  inputs for the info but they would be better as labels. I have included one as an example but commented it out. The inputs text can be deleted. It has no effect on the program but a bit more professional :) 

#Region #### Includes ################################
#include <Array.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>
;~ #include <StaticConstants.au3> ; only needed for label example
#include <WindowsConstants.au3>
#EndRegion #### Includes ################################

#Region #### Globals #################################
; these relate to the columns that contain the information,
; they relate to the ARRAY columns layout NOT the EXCEL sheet columns. Enum will
; assign them a value starting at 0 and incrementing by one. If you add or change the column
; layout in the excel sheet, these will need to be altered
Global Enum _
        $STAFFNUMBER_COL, _ ; 0
        $NAME_COL, _ ; 1
        $DEPT_COL, _ ; 2
        $JOINING_COL, _ ; 3
        $ID_COL, _ ; 4
        $MAX_COLS ; 5, or 1 above the last column

; these relate to the controls on the GUI. Only the ones
; we need to update that would be Global are in here
; ### THESE MUST HAVE THE SAME VALUE AS THEIR COLUMN COUNTERPARTS ###
Global Enum _
        $STAFFNUMBER_CBO, _ ; 0
        $NAME_INP, _ ; 1
        $DEPT_INP, _ ; 2
        $JOINING_INP, _ ; 3
        $ID_INP, _ ; 4
        $MAX_IDS ; 5, or 1 above the last control

; create an array to hold the id's for the controls
; scope is global so it can be accessed by all. We
; loop through this array later when updating the inputs
; with the array values
Global $g_aiControlIDs[$MAX_IDS]

; declare a variable to hold the RangeRead return
; scope is global so it can be accessed by all
Global $g_asStaffInfo = ''
#EndRegion #### Globals #################################

; read the full sheet to the array
ReadSheetToArray($g_asStaffInfo)
;~ _ArrayDisplay($g_asStaffInfo)

; draw the GUI
GUI_Draw()

Func GUI_Draw()
    GUICreate("Rimo System", 270, 500, -1, -1)

    ; no need to assign the controlID to a variable as
    ; it's text is constant
    GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25)
    GUICtrlSetFont(-1, 14, 800, 0, "MS Serif")

    ; $STAFFNUMBER_CBO
    $g_aiControlIDs[$STAFFNUMBER_CBO] = GUICtrlCreateCombo("", 50, 48, 169, 21, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL))
    GUICtrlSetData(-1, LoadStaffNumberCombo())

    ; declare as Local because it's not used outside of this function
    Local $id_GetInfo_btn = GUICtrlCreateButton("Get Info", 85, 88, 89, 33)

    ; $NAME_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$NAME_COL], 16, 147, 36, 17)
    $g_aiControlIDs[$NAME_INP] = GUICtrlCreateInput("", 72, 144, 161, 21)

    ; label example
;~  $g_aiControlIDs[$NAME_INP] = GUICtrlCreateLabel("", 72, 144, 161, 21, $SS_CENTERIMAGE, $WS_EX_STATICEDGE)
;~  GUICtrlSetBkColor(-1, 0xFFFFFF)

    ; $DEPT_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$DEPT_COL], 16, 177, 36, 17)
    $g_aiControlIDs[$DEPT_INP] = GUICtrlCreateInput("", 72, 176, 161, 21)

    ; $JOINING_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$JOINING_COL], 16, 211, 36, 17)
    $g_aiControlIDs[$JOINING_INP] = GUICtrlCreateInput("", 72, 208, 161, 21)

    ; $ID_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$ID_COL], 16, 243, 36, 17)
    $g_aiControlIDs[$ID_INP] = GUICtrlCreateInput("", 72, 240, 161, 21)

    ; unknown1 - These two will need to be added when you expand the spreadsheet
    ; you will need to create them in the same way as the others above
;~  GUICtrlCreateLabel("", 16, 272, 36, 17)
;~  Global $id_unknown2_inp = GUICtrlCreateInput("", 72, 272, 161, 21)

    ; unknown2
;~  GUICtrlCreateLabel("", 16, 304, 36, 17)
;~  Global $id_unknown2_inp = GUICtrlCreateInput("", 72, 304, 161, 21)

    ; declare as Local because it's not used outside of this function
    Local $id_Cancel_btn = GUICtrlCreateButton("Cancel", 75, 416, 121, 25)

    ; show the gui
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $id_Cancel_btn
                ExitLoop
            Case $id_GetInfo_btn
                LoadStaffInfoInputs() ; retreive the info from the array
        EndSwitch
    WEnd

    GUIDelete()
EndFunc   ;==>GUI_Draw

Func LoadStaffNumberCombo()
    ; set a starting string
    Local $s_Input = '|'

    ; loop through the Staff# column of the array
    For $i = 1 To UBound($g_asStaffInfo) - 1
        ; add the values from the rows ($i)
        $s_Input &= '|' & $g_asStaffInfo[$i][$STAFFNUMBER_COL]
    Next

    ; trim the first pipe symbol
    Return StringTrimLeft($s_Input, 1)
EndFunc   ;==>LoadStaffNumberCombo

Func LoadStaffInfoInputs()
    ; get the index of the currently selected item in the combo
    Local $i_ComboIndex = _GUICtrlComboBox_GetCurSel($g_aiControlIDs[$STAFFNUMBER_CBO])
    If $i_ComboIndex = -1 Then Return ; nothing selected

    ; _GUICtrlComboBox_GetCurSel returns a zero based index so
    ; we need to increase by one to tally with $g_asStaffInfo rows
    $i_ComboIndex += 1

    ; loop through the inputs and add the values. If the number of columns in the excel
    ; sheet increases and the number of inputs increases, as long as they are added to the global
    ; enums at the top of the script in the correct order, this should not need adjusting
    For $i = $NAME_COL To $MAX_COLS - 1
        GUICtrlSetData($g_aiControlIDs[$i], $g_asStaffInfo[$i_ComboIndex][$i])
    Next
EndFunc   ;==>LoadStaffInfoInputs

Func ReadSheetToArray(ByRef $as_RangeRead)
    Local $s_ErrorMsg = "Error creating the Excel application object"

    ; create an instance of excel. Declare as local scope
    ; as it is only needed in this function
    Local $o_Excel = _Excel_Open(False)

    If Not @error Then
        $s_ErrorMsg = "Error opening workbook"

        ; open the workbook. Scope as above
        Local $o_WorkBook = _Excel_BookOpen($o_Excel, 'D:\info.xlsx', False, False)

        If Not @error Then
            $s_ErrorMsg = "Error reading excel range"
            $as_RangeRead = _Excel_RangeRead($o_WorkBook)
        EndIf
    EndIf

    If @error Then Exit MsgBox($MB_SYSTEMMODAL, _
            "Excel Error", _
            $s_ErrorMsg & $o_WorkBook & @CRLF & _
            "@error = " & @error & ", @extended = " & @extended)

    ; we're are finished with excel now as all the info
    ; is in the array so it can be closed
    _Excel_Close($o_Excel)
EndFunc   ;==>ReadSheetToArray

 

1 person likes this

Share this post


Link to post
Share on other sites

#14 ·  Posted

12 hours ago, benners said:

Well try this. I have commented a lot of things but if there's anything you don't know then just post. The AutoIt Wiki is a good place to pick up info and there's a thread on Best Practices here that's worth a read. I picked up a lot from both.

I changed the top input for a combo box, 

I kept your other  inputs for the info but they would be better as labels. I have included one as an example but commented it out. The inputs text can be deleted. It has no effect on the program but a bit more professional :) 

#Region #### Includes ################################
#include <Array.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>
;~ #include <StaticConstants.au3> ; only needed for label example
#include <WindowsConstants.au3>
#EndRegion #### Includes ################################

#Region #### Globals #################################
; these relate to the columns that contain the information,
; they relate to the ARRAY columns layout NOT the EXCEL sheet columns. Enum will
; assign them a value starting at 0 and incrementing by one. If you add or change the column
; layout in the excel sheet, these will need to be altered
Global Enum _
        $STAFFNUMBER_COL, _ ; 0
        $NAME_COL, _ ; 1
        $DEPT_COL, _ ; 2
        $JOINING_COL, _ ; 3
        $ID_COL, _ ; 4
        $MAX_COLS ; 5, or 1 above the last column

; these relate to the controls on the GUI. Only the ones
; we need to update that would be Global are in here
; ### THESE MUST HAVE THE SAME VALUE AS THEIR COLUMN COUNTERPARTS ###
Global Enum _
        $STAFFNUMBER_CBO, _ ; 0
        $NAME_INP, _ ; 1
        $DEPT_INP, _ ; 2
        $JOINING_INP, _ ; 3
        $ID_INP, _ ; 4
        $MAX_IDS ; 5, or 1 above the last control

; create an array to hold the id's for the controls
; scope is global so it can be accessed by all. We
; loop through this array later when updating the inputs
; with the array values
Global $g_aiControlIDs[$MAX_IDS]

; declare a variable to hold the RangeRead return
; scope is global so it can be accessed by all
Global $g_asStaffInfo = ''
#EndRegion #### Globals #################################

; read the full sheet to the array
ReadSheetToArray($g_asStaffInfo)
;~ _ArrayDisplay($g_asStaffInfo)

; draw the GUI
GUI_Draw()

Func GUI_Draw()
    GUICreate("Rimo System", 270, 500, -1, -1)

    ; no need to assign the controlID to a variable as
    ; it's text is constant
    GUICtrlCreateLabel("Rimo System", 80, 16, 150, 25)
    GUICtrlSetFont(-1, 14, 800, 0, "MS Serif")

    ; $STAFFNUMBER_CBO
    $g_aiControlIDs[$STAFFNUMBER_CBO] = GUICtrlCreateCombo("", 50, 48, 169, 21, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL))
    GUICtrlSetData(-1, LoadStaffNumberCombo())

    ; declare as Local because it's not used outside of this function
    Local $id_GetInfo_btn = GUICtrlCreateButton("Get Info", 85, 88, 89, 33)

    ; $NAME_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$NAME_COL], 16, 147, 36, 17)
    $g_aiControlIDs[$NAME_INP] = GUICtrlCreateInput("", 72, 144, 161, 21)

    ; label example
;~  $g_aiControlIDs[$NAME_INP] = GUICtrlCreateLabel("", 72, 144, 161, 21, $SS_CENTERIMAGE, $WS_EX_STATICEDGE)
;~  GUICtrlSetBkColor(-1, 0xFFFFFF)

    ; $DEPT_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$DEPT_COL], 16, 177, 36, 17)
    $g_aiControlIDs[$DEPT_INP] = GUICtrlCreateInput("", 72, 176, 161, 21)

    ; $JOINING_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$JOINING_COL], 16, 211, 36, 17)
    $g_aiControlIDs[$JOINING_INP] = GUICtrlCreateInput("", 72, 208, 161, 21)

    ; $ID_INP - Gets the text from the array and corresponding column
    GUICtrlCreateLabel($g_asStaffInfo[0][$ID_COL], 16, 243, 36, 17)
    $g_aiControlIDs[$ID_INP] = GUICtrlCreateInput("", 72, 240, 161, 21)

    ; unknown1 - These two will need to be added when you expand the spreadsheet
    ; you will need to create them in the same way as the others above
;~  GUICtrlCreateLabel("", 16, 272, 36, 17)
;~  Global $id_unknown2_inp = GUICtrlCreateInput("", 72, 272, 161, 21)

    ; unknown2
;~  GUICtrlCreateLabel("", 16, 304, 36, 17)
;~  Global $id_unknown2_inp = GUICtrlCreateInput("", 72, 304, 161, 21)

    ; declare as Local because it's not used outside of this function
    Local $id_Cancel_btn = GUICtrlCreateButton("Cancel", 75, 416, 121, 25)

    ; show the gui
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $id_Cancel_btn
                ExitLoop
            Case $id_GetInfo_btn
                LoadStaffInfoInputs() ; retreive the info from the array
        EndSwitch
    WEnd

    GUIDelete()
EndFunc   ;==>GUI_Draw

Func LoadStaffNumberCombo()
    ; set a starting string
    Local $s_Input = '|'

    ; loop through the Staff# column of the array
    For $i = 1 To UBound($g_asStaffInfo) - 1
        ; add the values from the rows ($i)
        $s_Input &= '|' & $g_asStaffInfo[$i][$STAFFNUMBER_COL]
    Next

    ; trim the first pipe symbol
    Return StringTrimLeft($s_Input, 1)
EndFunc   ;==>LoadStaffNumberCombo

Func LoadStaffInfoInputs()
    ; get the index of the currently selected item in the combo
    Local $i_ComboIndex = _GUICtrlComboBox_GetCurSel($g_aiControlIDs[$STAFFNUMBER_CBO])
    If $i_ComboIndex = -1 Then Return ; nothing selected

    ; _GUICtrlComboBox_GetCurSel returns a zero based index so
    ; we need to increase by one to tally with $g_asStaffInfo rows
    $i_ComboIndex += 1

    ; loop through the inputs and add the values. If the number of columns in the excel
    ; sheet increases and the number of inputs increases, as long as they are added to the global
    ; enums at the top of the script in the correct order, this should not need adjusting
    For $i = $NAME_COL To $MAX_COLS - 1
        GUICtrlSetData($g_aiControlIDs[$i], $g_asStaffInfo[$i_ComboIndex][$i])
    Next
EndFunc   ;==>LoadStaffInfoInputs

Func ReadSheetToArray(ByRef $as_RangeRead)
    Local $s_ErrorMsg = "Error creating the Excel application object"

    ; create an instance of excel. Declare as local scope
    ; as it is only needed in this function
    Local $o_Excel = _Excel_Open(False)

    If Not @error Then
        $s_ErrorMsg = "Error opening workbook"

        ; open the workbook. Scope as above
        Local $o_WorkBook = _Excel_BookOpen($o_Excel, 'D:\info.xlsx', False, False)

        If Not @error Then
            $s_ErrorMsg = "Error reading excel range"
            $as_RangeRead = _Excel_RangeRead($o_WorkBook)
        EndIf
    EndIf

    If @error Then Exit MsgBox($MB_SYSTEMMODAL, _
            "Excel Error", _
            $s_ErrorMsg & $o_WorkBook & @CRLF & _
            "@error = " & @error & ", @extended = " & @extended)

    ; we're are finished with excel now as all the info
    ; is in the array so it can be closed
    _Excel_Close($o_Excel)
EndFunc   ;==>ReadSheetToArray

 

This sounds very advanced for me. You used only just 10% from the size of my code to do the same. I will study it very well once I am at home, and I am pretty sure that this code will have a great developmental impact on me.

Thanks for your great help to rewrite my code in a readable & easy way.

Thanks a million.

Share this post


Link to post
Share on other sites

#15 ·  Posted

It only looks that way at first :). A lot of your code seemed to be to make the input box act like a combo box with accelerator keys to control it.  I replaced it with a combo box, you can scroll through it with the mouse or arrow keys and it expands to show a list. I hope it functions the way you want compared with the first input box.

Everyone has there own preferences on layout, so as long as your code is easily readable, is easy to maintain (even after it's not fresh in your mind) and understandable (more likely to get help here) your half way there.

If you do add extra inputs like the unknown input parts, you can add them to the controls array. The declarations below are only there to show you the scope each control needs to be declared in. Don't declare the Globals inside the function, If that makes sense :blink: Good luck

;~  GUICtrlCreateLabel("", 16, 272, 36, 17)
;~  Global $id_unknown1_inp = GUICtrlCreateInput("", 72, 272, 161, 21)

    ; unknown2
;~  GUICtrlCreateLabel("", 16, 304, 36, 17)
;~  Global $id_unknown2_inp = GUICtrlCreateInput("", 72, 304, 161, 21)

 

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

  • Similar Content

    • anusha
      By anusha
      Hi I have jus started using auto-it . Please correct me if I'm wrong.
      I need to read data from an input in text box and search in excel file and return value in next column of matched cell on GUI.
      I have written below code but i cannot use variable which has data stored. it works only when search string is hard coded.
      Please help out.
       
      Example()
      Func Example()
      Local $GuiMain = GUICreate("EXCEL TEST", 399, 180) ;creates main GUI
      ;~ Local $idOK = GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
      Local $iWidthCell = 70
      Local $idLabel = GUICtrlCreateLabel("PART NUMBER", 10, 30, $iWidthCell,50)
      Local $RUN_1 = GUICtrlCreateButton("OK", 70, 70, 85, 25)
      Local $Input_1 = GUICtrlCreateInput("PART NUMBER", 100, 20, 120, 20)
      Local $sMenutext = GUICtrlRead($Input_1, 1)
      GUISetState(@SW_SHOW, $GuiMain)

          While 1
          $MSG = GUIGetMsg()
          Select
              Case $MSG = $GUI_EVENT_CLOSE
                  Exit
              Case $MSG = $RUN_1
                  Local $oAppl = _Excel_Open()

      Local $sFilePath1 = "D:\Anu_WorkFolder\Components.xlsx"
      Local $oWorkbook = _Excel_BookOpen($oAppl, $sFilePath1, Default, Default, True)
      Local $aResult = _Excel_RangeFind($oWorkbook, $sMenutext , Default, Default, $xlWhole)
    • Nareshm
      By Nareshm
      How to Activate Opened Excel Windows Using Class not Tittle, Because Some time opened defferent excel that have different name.
      I Tried with
      Winactivate ("[CLASS:XLMAIN]") but not working
    • willichan
      By willichan
      Here is another one from my archives that filled a specific need.
       
      Here is the back story if you are interested.
       
      Keep in mind that I wrote this script over 3 years ago, so it may not compile or run directly without some minor tweaks.  It also requires the use of GraphViz to build the graph.
      #cs ---------------------------------------------------------------------------- Project Name: ExcelLinksMapper Description: Analyse an Excel file's links and map them out. Creation Date: 9/26/2014 AutoIt Version: Author: willichan Requires: Graphviz (http://graphviz.org/) #ce ---------------------------------------------------------------------------- Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause Opt("TrayMenuMode", 0) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon Global Const $MyName=StringLeft(@ScriptName, StringInStr(@ScriptName,".", 0, -1)-1) ;get just the name portion of the script/exe name Global Const $MyMutex=$MyName & "-82243BEBC30533A3" ;name the mutex for this app Global $SQLloaded = False Global $sDbName = @ScriptDir & "\db2gv.db" ConsoleWrite($sDbName & @crlf) If _MutexExists($MyMutex) Then Exit #include <SQLite.au3> #include <SQLite.dll.au3> #include <file.au3> #include <array.au3> #include <excel.au3> _ConfigInitialize() _Main() Func _ConfigInitialize() OnAutoItExitRegister("_ConfigDestroy") ;initializers here Global $sSQliteDll = _SQLite_Startup() If @error Then MsgBox(0, "SQLite Error", "could not load the DLL") Global $sSQLiteDB = _SQLite_Open($sDbName) If $sSQLiteDB = 0 Then MsgBox(0, "SQLite Error", "could not open the database") $SQLloaded =True __CreateTables() EndFunc ;==>_ConfigInitialize Func _ConfigDestroy() ;destructors here If $SQLloaded Then _SQLite_Close() _SQLite_Shutdown() EndIf EndFunc ;==>_ConfigDestroy Func _MutexExists($sOccurenceName) Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError $sOccurenceName = StringReplace($sOccurenceName, "\", "") $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName) $lastError = DllCall("kernel32.dll", "int", "GetLastError") Return $lastError[0] = $ERROR_ALREADY_EXISTS EndFunc ;==>_MutexExists Func __CreateTables() _SQLite_Exec($sSQLiteDB, "DROP TABLE IF EXISTS nodes;") _SQLite_Exec($sSQLiteDB, "CREATE TABLE IF NOT EXISTS nodes( name TEXT PRIMARY KEY, fileexists INTEGER);") _SQLite_Exec($sSQLiteDB, "DROP TABLE IF EXISTS links;") _SQLite_Exec($sSQLiteDB, "CREATE TABLE IF NOT EXISTS links( id INTEGER PRIMARY KEY, name1 TEXT, name2 TEXT, weight INTEGER);") EndFunc Func _Main() Local $sInfile, $vResult, $iErrLoop $sInfile = FileOpenDialog("Source File", @WorkingDir, "Excel files (*.xl*)", 1 + 2) If Not FileExists($sInfile) Then MsgBox(0, "Excel Links Mapper Error", "Unable to locate source file") Exit EndIf $vResult = $SQLITE_IOERR $iErrLoop = 5 While $vResult = $SQLITE_IOERR $vResult = _SQLite_Exec($sSQLiteDB, "INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sInfile) & ", 1);") If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then ConsoleWrite($iErrLoop & " tries" & @CRLF & $sInfile & @CRLF) $vResult = $SQLITE_OK EndIf WEnd _GetExcelLinks($sInfile) Global $hOutfile = FileOpen(@ScriptDir & "\" & $MyName & ".gv", 2) If $hOutfile = -1 Then MsgBox(0, $MyName & " ERROR", "Unable to upen file for output") Exit EndIf _WriteHeader() _WriteNodes() _WriteLinks() _WriteFooter() FileClose($hOutfile) _GenerateGraph() ShellExecute(@ScriptDir & '\ExcelLinksMapper.png') EndFunc ;==>_Main Func _GetExcelLinks($strFileName) Local $hQuery, $aCount, $iErrLoop, $vResult ConsoleWrite($strFileName & @CRLF) Local $iLoop, $iExists Local $aLinks Local Const $xlExcelLinks = 1 Local $oExcel = _Excel_Open() Local $ret = _Excel_BookOpen_NoUpdate($oExcel, $strFileName, True, True) Local $err = @error If $err Then If Not IsObj($oExcel) Then ConsoleWrite($ret & " - " & $err & @CRLF) Exit EndIf EndIf $aLinks = $oExcel.ActiveWorkbook.LinkSources($xlExcelLinks) _Excel_BookClose($oExcel, False) _Excel_Close($oExcel, False, True) If IsArray($aLinks) Then If UBound($aLinks) > 0 Then For $iLoop = 0 To UBound($aLinks) - 1 If $aLinks[$iLoop] <> $strFileName Then $iExists = FileExists($aLinks[$iLoop]) ConsoleWrite("DEBUG - Calling WriteNode()") __WriteNode($aLinks[$iLoop], $iExists) ConsoleWrite("DEBUG - Calling WriteLink()") __WriteLink($strFileName, $aLinks[$iLoop]) If $iExists And ($aLinks[$iLoop] <> $strFileName) Then _GetExcelLinks($aLinks[$iLoop]) EndIf Next EndIf EndIf EndFunc ;==>_GetExcelLinks Func __WriteNode($sName, $iExists) Local $iErrLoop = 5 ;Number of attempts to make Local $vResult Do ConsoleWrite("DEBUG - WriteNode()" & @CRLF & " _SQLite_Exec(INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sName) & ", " & $iExists & ");) - create node entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "INSERT OR IGNORE INTO nodes ('name', 'fileexists') VALUES (" & _SQLite_FastEscape($sName) & ", " & $iExists & ");") If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then $vResult = $SQLITE_OK ;Used up all our attempts, so simulate a success Until $vResult = $SQLITE_OK EndFunc ;==>__WriteNode Func __WriteLink($sName1, $sName2) Local $iErrLoop = 5 ;Number of attempts to make Local $vResult, $hQuery, $vCount ConsoleWrite("DEBUG - WriteNode()" & @CRLF & " _SQLite_Query(SELECT weight FROM links WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2'=" & _SQLite_FastEscape($sName2) & ";) - lookup link entry" & @CRLF) _SQLite_Query($sSQLiteDB, "SELECT weight FROM links WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2'=" & _SQLite_FastEscape($sName2) & ";", $hQuery) ConsoleWrite("DEBUG - _SQLite_FetchData()" & @CRLF) _SQLite_FetchData($hQuery, $vCount) If UBound($vCount) > 1 Then _ArrayDisplay($vCount) If $SQLITE_OK And UBound($vCount) > 1 Then $vCount = $vCount[1] + 1 Else $vCount = 1 EndIf Do If $vCount = 1 Then ConsoleWrite("DEBUG - _SQLite_Exec() - create link entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "INSERT INTO links ('name1', 'name2', 'weight') VALUES (" & _SQLite_FastEscape($sName1) & ", " & _SQLite_FastEscape($sName2) & ", " & $vCount & ");") Else ConsoleWrite("DEBUG - _SQLite_Exec() - update link entry" & @CRLF) $vResult = _SQLite_Exec($sSQLiteDB, "UPDATE links SET 'weight'=" & $vCount & " WHERE 'name1'=" & _SQLite_FastEscape($sName1) & " AND 'name2=" & _SQLite_FastEscape($sName2) & ";") EndIf If Not $vResult = $SQLITE_OK Then Sleep(100) $iErrLoop -= 1 If $iErrLoop = 0 Then $vResult = $SQLITE_OK ;Used up all our attempts, so simulate a success Until $vResult = $SQLITE_OK EndFunc ;==>__WriteLink ; #FUNCTION# ==================================================================================================================== ; Author ........: SEO <locodarwin at yahoo dot com> ; Modified.......: litlmike, water, GMK, willichan ; =============================================================================================================================== Func _Excel_BookOpen_NoUpdate($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default) If Not IsObj($oExcel) Or ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, @error, 0) If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) If $bReadOnly = Default Then $bReadOnly = False If $bVisible = Default Then $bVisible = True ;; changing the second parameter on the following line to a 0 tells Excel not to update any links. Local $oWorkbook = $oExcel.Workbooks.Open($sFilePath, 0, $bReadOnly, Default, $sPassword, $sWritePassword) If @error Then Return SetError(3, @error, 0) $oExcel.Windows($oWorkbook.Name).Visible = $bVisible ; If a read-write workbook was opened read-only then return an error If $bReadOnly = False And $oWorkbook.Readonly = True Then Return SetError(4, 0, $oWorkbook) Return $oWorkbook EndFunc ;==>_Excel_BookOpen_NoUpdate Func _GenerateGraph() RunWait(@ScriptDir & '\GraphViz238\bin\dot.exe -Tpng "' & @ScriptDir & '\' & $MyName & '.gv" -o "' & @ScriptDir & '\ExcelLinksMapper.png"') EndFunc ;==>_GenerateGraph Func _WriteHeader() __OutLine(0, "digraph main {") EndFunc ;==>_WriteHeader Func _WriteNodes() Local $aResult, $iRows, $iColumns, $iRval Local $iLoop, $sStyle __OutLine(1, "// Nodes") $iRval = _SQLite_GetTable($sSQLiteDB, "SELECT name, fileexists FROM nodes;", $aResult, $iRows, $iColumns) If @error Then ConsoleWrite("_WriteNodes()" & @CRLF & "_SQLite_GetTable") If $iRval = $SQLITE_OK Then For $iLoop = 1 To $iRows If $aResult[($iLoop * 2) + 2] > 0 Then $sStyle = "normal" Else $sStyle = "missing" EndIf __OutNode($aResult[1 + (2 * $iLoop)], $sStyle) ;; Next Else MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg() & @CRLF & "in _WriteNotes() calling _SQLite_GetTable()") Exit EndIf EndFunc ;==>_WriteNodes Func __OutNode($sName, $sStyle = Default) If $sStyle = Default Then $sStyle = "Normal" Switch StringLower($sStyle) Case "missing" __OutLine(1, __MakeName($sName) & ' [label="' & StringReplace($sName, "\", "\\") & '",color=red,fontcolor=red,shape=octagon];') Case Else ;"normal", Default __OutLine(1, __MakeName($sName) & ' [label="' & StringReplace($sName, "\", "\\") & '",color=black,fontcolor=black,shape=box];') EndSwitch EndFunc ;==>__OutNode Func _WriteLinks() Local $aResult, $iRows, $iColumns, $iRval Local $iLoop, $sStyle, $aCount __OutLine(1, "// Links") $iRval = _SQLite_GetTable($sSQLiteDB, "SELECT name1, name2 FROM links ORDER BY name1 ASC, name2 ASC;", $aResult, $iRows, $iColumns) If $iRval = $SQLITE_OK Then For $iLoop = 1 To $iRows __OutLink($aResult[1 + (2 * $iLoop)], $aResult[2 + (2 * $iLoop)]) Next Else MsgBox($MB_SYSTEMMODAL, "SQLite Error: " & $iRval, _SQLite_ErrMsg()) Exit EndIf EndFunc ;==>_WriteLinks Func __OutLink($sName1, $sName2, $iWeight = 1) __OutLine(1, __MakeName($sName1) & ' -> ' & __MakeName($sName2) & ';') EndFunc ;==>__OutLink Func _WriteFooter() __OutLine(0, "}") EndFunc ;==>_WriteFooter Func __OutLine($iTabs, $sText) Local $iLoop If $iTabs > 0 Then For $iLoop = 1 To $iTabs FileWrite($hOutfile, " ") ;ConsoleWrite(" ") Next EndIf FileWriteLine($hOutfile, $sText) EndFunc ;==>__OutLine Func __MakeName($sText) Local $sNewName = StringReplace($sText, "\", " ") $sNewName = StringReplace($sNewName, "/", " ") $sNewName = StringReplace($sNewName, "'", " ") $sNewName = StringReplace($sNewName, '"', " ") $sNewName = StringReplace($sNewName, ':', " ") $sNewName = StringReplace($sNewName, '.', " ") $sNewName = StringReplace($sNewName, '-', " ") $sNewName = StringReplace($sNewName, '$', " ") $sNewName = StringStripWS($sNewName, 8) Return StringLower($sNewName) EndFunc ;==>__MakeName  
    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx