Jump to content
Sign in to follow this  
JonBMN

[SOLVED]Putting Array values into GUI box (getting all values into the array)

Recommended Posts

JonBMN

I'm trying to take array values which I can't seem to get all the values into the array to send to the GUI window and I can't seem to get the array to even go into the GUI window. Here is the FULL code I'm working with.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Green.ico
#AutoIt3Wrapper_Outfile=DriverInstall.exe
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
AutoItWinSetTitle("Driver Install")
AutoItSetOption("MustDeclareVars", 1)
Opt("TrayMenuMode", 0)
#NoTrayIcon
#include-once
#RequireAdmin

#include <GUIconstants.au3>
#include <myerror.au3>
#include <misc.au3>
#include <Array.au3>

If _Singleton("Driver Install", 1) = 0 Then
Exit
EndIf

Local $Result
Local $NumComports = -1, $OrigPortNum[30]
Local $NewPortNum[30], $NewNumComports = -1
Local $GUIhandle, $CM[10], $AddedPort, $msg, $newports[20], $oldports[20]

; Update registry to ignor dongle serial number
$Result = RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\UsbFlags", "IgnoreHWSerNum04036001", "REG_BINARY", Chr(1))
If $Result = 0 Then
$ErrorTitle = "Error Updating Registry"
$ErrorMessage = "Unable to update registry UsbFlags"
$IsErrorFatal = True
MyError()
EndIf

MsgBox(0, "Alert!", "Please make sure OBD processor is not plugged into the computer.")

BuildOriginal()
Run("CDM20828.EXE")
MsgBox(0, "Alert!", "Now plug in the OBD processor into the USB port on the computer. When you have plugged it in click OK.")
BuildNew()
GUIwindow()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Quit()
EndSelect
WEnd
Exit

Func Quit()
Exit
EndFunc

Func BuildOriginal()
Local $Instance = 1, $Key = "", $Port = "", $Found = False
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NumComports += 1
$OrigPortNum[$NumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NumComports
_ArrayPush($OrigPortNum,$OrigPortNum[$Instance], 0)
Next
EndFunc




Func BuildNew()
Local $Instance = 1, $Key = "", $Port = "", $Found = False, $i = 0
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NewNumComports += 1
$NewPortNum[$NewNumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NewNumComports
_ArrayPush($NewPortNum,$NewPortNum[$Instance], 0)
Next
For $i = 0 To $NewNumComports
If ($NewPortNum[$i] <> $OrigPortNum[$i]) Then
;MsgBox(0, "Alert!", "Found new Port!" & $NewPortNum[$i])
$Addedport = $NewPortNum[$i]
ExitLoop
EndIf
Next
EndFunc

Func GUIwindow()
$GUIhandle = GUICreate("Port Settings", 455, 325)
GUICtrlCreateLabel("-Before OBD doggle plugin-", 15, 25)
$CM[1] = GUICtrlCreateEdit("", 15, 45, 180, 100, 400)
GUICtrlSetData($CM[1], $OrigPortNum, $OrigPortNum)
GUICtrlCreateLabel("-After OBD doggle plugin-", 250, 25)
$CM[2] = GUICtrlCreateEdit("", 250, 45, 180, 100, 400)
GUICtrlSetData($CM[2], $NewPortNum, $NewPortNum)
GUICtrlCreateLabel("This is the added port:", 15, 300)
$CM[3] = GUICtrlCreateEdit("", 120, 300, 150, 20)
GUICtrlSetData($CM[3], $AddedPort, $AddedPort)
GUISetState(@SW_SHOW) ;shows the GUI window
EndFunc
Edited by JonBMN

Share this post


Link to post
Share on other sites
BrewManNH

Well, you can't apply the contents of an array to an edit box directly. You should loop through the array and add each value to a string, and then use the string to update the edit control.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JonBMN

Any chance you could give me a basic example of this?

Share this post


Link to post
Share on other sites
Melba23

JonBMN,

About as basic as I can make it: ;)

#include <GUIConstantsEx.au3>

; Here is the array
Global $aLines[4] = [3, "Line 1", "Line 2", "Line 3"]

$hGUI = GUICreate("Test", 500, 500)

$cEdit = GUICtrlCreateEdit("", 10, 10, 200, 200)

$cButton = GUICtrlCreateButton("Load Array", 10, 400, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ; Start with an empty string
            $sData = ""
            ; Loop through the array and add each line to the string - do not forget the line break
            For $i = 1 To $aLines[0]
                $sData &= $aLines[$i] & @CRLF
            Next
            ; And finally, add the string to the edit
            GUICtrlSetData($cEdit, $sData)
    EndSwitch

WEnd

All clear?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
BrewManNH

This example is a very basic demo that shows what I was talking about.

You don't really need the _ArrayToString function if you build the string as you build the array, but I used it for simplicity.

#include <GUIconstants.au3>
#include <misc.au3>
#include <Array.au3>

If _Singleton("Driver Install", 1) = 0 Then
    Exit
EndIf

Local $Result
Local $NumComports = -1, $sOrigPortNum
Local $sNewPortNum, $NewNumComports = -1
Local $GUIhandle, $CM[10], $AddedPort, $msg, $newports[20], $oldports[20]

BuildOriginal()
BuildNew()
GUIwindow()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Quit()
    EndSelect
WEnd

Func BuildNew()
    Local $NewPortNum[30]
    For $I = 0 To 29
        $NewPortNum[$I] = $I
    Next
    $sNewPortNum = _ArrayToString($NewPortNum, @CRLF)
EndFunc   ;==>BuildNew

Func BuildOriginal()
    Local $OrigPortNum[30]
    For $I = 0 To 29
        $OrigPortNum[$I] = $I
    Next
    $sOrigPortNum = _ArrayToString($OrigPortNum, @CRLF)
EndFunc   ;==>BuildOriginal

Func GUIwindow()
    $GUIhandle = GUICreate("Port Settings", 455, 325)
    GUICtrlCreateLabel("-Before OBD dongle plugin-", 15, 25)
    $CM[1] = GUICtrlCreateEdit("", 15, 45, 180, 100, 400)
    GUICtrlSetData($CM[1], $sOrigPortNum)
    GUICtrlCreateLabel("-After OBD dongle plugin-", 250, 25)
    $CM[2] = GUICtrlCreateEdit("", 250, 45, 180, 100, 400)
    GUICtrlSetData($CM[2], $sNewPortNum)
    GUICtrlCreateLabel("This is the added port:", 15, 300)
    $CM[3] = GUICtrlCreateEdit("", 120, 300, 150, 20)
    GUICtrlSetData($CM[3], $AddedPort, $AddedPort)
    GUISetState(@SW_SHOW) ;shows the GUI window
EndFunc   ;==>GUIwindow

Func Quit()
    Exit
EndFunc   ;==>Quit


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JonBMN

Thank you both. Both examples will give me a better understanding of what is going on.

Share this post


Link to post
Share on other sites
JonBMN

It seems to be only putting in the last value of the array that's being looped through into the $orig = "" which is my initialized string variable that I want to hold all my array values.

Func BuildOriginal()
Local $Instance = -1, $Key = "", $Port = "", $Found = False
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NumComports += 1
$OrigPortNum[$NumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NumComports
$orig = $OrigPortNum[$Instance] & @CRLF
Next
EndFunc

so if I had two com ports 13 and 35 the only one it sends to the GUI is 35.

Edited by JonBMN

Share this post


Link to post
Share on other sites
BrewManNH

You're missing the "&" before the "=".

$orig &= $OrigPortNum[$Instance] & @CRLF


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JonBMN

After adding that, I seem to get nothing from the BuildOriginal() function, but the BuildNew() function seems to be working perfectly...

Local $orig = "", $new = ""
Func BuildOriginal()
Local $Instance = -1, $Key = "", $Port = "", $Found = False
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NumComports += 1
$OrigPortNum[$NumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NumComports
$orig &= $OrigPortNum[$Instance] & @CRLF
Next
EndFunc




Func BuildNew()
Local $Instance = 1, $Key = "", $Port = "", $Found = False, $i = 0
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NewNumComports += 1
$NewPortNum[$NewNumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NewNumComports
$new &= $NewPortNum[$Instance] & @CRLF
Next
For $i = 0 To $NewNumComports
If ($NewPortNum[$i] <> $OrigPortNum[$i]) Then
;MsgBox(0, "Alert!", "Found new Port!" & $NewPortNum[$i])
$Addedport = $NewPortNum[$i]
ExitLoop
EndIf
Next
EndFunc
Edited by JonBMN

Share this post


Link to post
Share on other sites
BrewManNH

You declared the $Instance variable in BuildNew as -1 instead of 1.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JonBMN

Ah the little things! thanks for catching that one BrewManNH

Share this post


Link to post
Share on other sites
JonBMN

My program seems to be working perfectly, but when I move it over to a windows XP for testing the $orig and $new values do not show up in the edit control, but I put a msgbox and saw all the com ports from these variables. Any answers to why it may not be showing up?

Edited by JonBMN

Share this post


Link to post
Share on other sites
BrewManNH

No clue, I don't have an XP machine to test it on.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JonBMN

Local $orig = "", $new = ""
Func BuildOriginal()
Local $Instance = -1, $Key = "", $Port = "", $Found = False
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NumComports += 1
$OrigPortNum[$NumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NumComports
$orig &= $OrigPortNum[$Instance] & @CRLF
Next
EndFunc




Func BuildNew()
Local $Instance = 1, $Key = "", $Port = "", $Found = False, $i = 0
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NewNumComports += 1
$NewPortNum[$NewNumComports] = $Port
$Instance += 1
WEnd
for $Instance = 0 To $NewNumComports
$new &= $NewPortNum[$Instance] & @CRLF
Next
For $i = 0 To $NewNumComports
If ($NewPortNum[$i] <> $OrigPortNum[$i]) Then
;MsgBox(0, "Alert!", "Found new Port!" & $NewPortNum[$i])
$Addedport = $NewPortNum[$i]
ExitLoop
EndIf
Next
EndFunc

Figured out what was going wrong on the XP machine. It was not the fact that it was an XP it had to many values in the array for the SetData to put into the Edit control. Posting BuildOriginal() function, BuildNew() function along with GUI function.. Not going to post first half as it is posted at top.

Local $orig = "", $new = ""
Func BuildOriginal()
Local $Instance = 1, $Key = "", $Port = "", $Found = False
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NumComports += 1
$OrigPortNum[$NumComports] = $Port
$orig &= $Port & " ** " & $Key & @CRLF
$Instance += 1
WEnd
EndFunc




Func BuildNew()
Local $Instance = 1, $Key = "", $Port = "", $Found = False, $i = 0
While 1
$Key = RegEnumVal("HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM", $Instance)
If @error = -1 Then
ExitLoop
     EndIf
$Port = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM",$Key )
$NewNumComports += 1
$NewPortNum[$NewNumComports] = $Port
$new &= $Port & " ** " & $Key & @CRLF
$Instance += 1
WEnd
For $i = 0 To $NewNumComports
If ($NewPortNum[$i] <> $OrigPortNum[$i]) Then
$Addedport = $NewPortNum[$i]
ExitLoop
EndIf
Next
EndFunc

Func GUIwindow()
$GUIhandle = GUICreate("Port Settings", 455, 325)
GUICtrlCreateLabel("-Before OBD doggle plugin-", 15, 25)
$CM[1] = GUICtrlCreateEdit("", 15, 45, 180, 200)
GUICtrlSetData($CM[1], $orig, $orig)
GUICtrlCreateLabel("-After OBD doggle plugin-", 250, 25)
$CM[2] = GUICtrlCreateEdit("", 250, 45, 180, 200)
GUICtrlSetData($CM[2], $new, $new)
GUICtrlCreateLabel("This is the added port:", 15, 300)
$CM[3] = GUICtrlCreateEdit("", 120, 300, 150, 20)
GUICtrlSetData($CM[3], $AddedPort, $AddedPort)
GUISetState(@SW_SHOW) ;shows the GUI window
EndFunc

EDIT: cleaned up the code a bit in BuildOriginal() and BuildNew()

Edited by JonBMN

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

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • Iceburg
      By Iceburg
      Hi everyone, I'm at best a noobie.  I have read through the Array helps, and specifically the 2D array help file, and I'm struggling to get my code working.
      I have an array that is read from a file, thats working great.  I'm trying to do some math on the array, so I can find the largest, average, lowest, day over day change %, etc.
      The array read working fine, I get 43 lines, line 0 is 44, and then I get data that looks like
      0519 $10,000
      0520 $10,001
      0521 $10,002
      The data in this array is a single 1D array, breaking it out into 2 columns so I can do the math is what I can get to happen.  
      How do I reference the array to store this data?  Second, how do I assign this data to the appropriate row/column?
      Thanks in advance.
      Dim $all_cash_amounts[UBound($aInput)][2] Dim $max_amount_in_account Dim $min_amount_in_account _FileReadToArray($LC_Check_file_path, $aInput) _ArrayDisplay($aInput) local $date = StringRegExp($aInput[1], "(\d\d\d\d)", 1) local $cash = StringRegExp($aInput[1], "\d+\s(-?[0-9\.\,]+)", 1) ConsoleWrite("Date is: " & $date & @CRLF) For $i = 1 To UBound($aInput)-1     $date = StringRegExp($aInput[$i], "(\d\d\d\d)", 1)     $all_cash_amounts[$i][2] = $date[$i][0], $cash[$i][1]      Next _ArrayDisplay($all_cash_amounts)  
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • OldGuyWalking
      By OldGuyWalking
      Given an array with multiple columns that is displayed in a listview,
       ===> What is the fastest/most efficient way to create and manage multiple filters and display results in ListView.
      I have a text file that loads into a listview that has string, numeric, and date columns.  The main file contains about 5100 rows. It's loaded into an array and (in this ListView) it's pre-filtered to display a range of rows based on a start and end date.  On the form I have menu options for various filters. (see below).
      I have options to filter on an "Air Date" column (=Today, >=Today, <=Today) and on a numeric field that is either 1 or 0 that indicate Active or Ended.

      For each filter option I have a prebuilt array that holds a subset of the main array based on a single filter.  For the list above I have the main Array and 5 additional arrays.  None of the arrays are updated since this is for "view only" purposes.  This is a short list and I could have done the filtering "live" but I have several of these forms and so kept the same functionality in each. I have another ListView that displays the complete 5100 row list with 3 filters that, when building the filters live was considerably slower than using prebuilt arrays.
      If I want to expand past simple single column filtering, using an array for each filter becomes cumbersome especially if I want to combine filters using AND & OR.
      The text file I'm working with has 16 columns. If I setup filters for 4 columns and include AND / OR capability that would require prebuilding 24 arrays to cover the various combinations.
      If using the slower method of building a filtered array in real time each time a different filter is selected is the only way to go with this then I'll live with it. It is less overhead. .
      Below is the code I'm currently using to "filter" an array.  My next change was going to add AND / OR functionality (see the info above the header for where I was going with this) .
      ; Description ...: Delete rows from an array and only keep rows that meet the crtieria of identified columns. ; ; Next Change: Add AND/OR to combine filters. Use array to hold multiple criteria and values? ; ; Local $aCriteria[][] = [["",$iColNbr1, $sOperator1, $vValue1], ["AND",$iColNbr2, $sOperator2, $vValue2], ["OR",$iColNbr3, $sOperator3, $vValue3]] ; The first set of criteria ["", $iColNbr1, $sOperator1, $vValue1] must start with a "". ; If anything is entered in that first parameter it will be ignored. ; If the first parameter in any additional criteria set is left blank, or it is not OR, it will default to AND. ; If $aArray is 1 dimension with more than one set of criteria, only the first set will be used. ; Any criteria that uses a column that is less than 0 or higher than the total number of columns in the array will return an error. ; ; Recognized data types for this function are: S (String), D (Date), N (Number). ; ; Recognized Operators are: "EQ", "NEQ", "IN", "GT", "GE", "LT", "LE", "BETWEEN". ; ****** Not all operators work with all data types. ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayFilter ; Description ...: Delete rows from an array and only keep rows that meet the crtieria of identified columns. ; Syntax ........: _ArrayFilter(Byref $aArray[, $iCol = 0[, $sOperator = "EQ"[, $vValue = ""[, $iOptionBase = 0]]]]) ; Parameters ....: $aArray - Array being filtered. ; $iCol - [optional] Column to filter. Default is 0. ; $sOperator - [optional] Operator. Default is "EQ". ; $vValue - [optional] Criteria to compare the column/row value against. ; $iOptionBase - [optional] Starting row. Default is 0. ; Return values .: None ; Author ........: OldGuyWalking ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ArrayFilter(ByRef $aArray, $iCol = 0, $sOperator = "EQ", $vValue = "", $iOptionBase = 0) Local $hFunc = _ArrayFilter $vValue = StringStripWS($vValue, 3) If $vValue = "[Today]" Then $vValue = _NowCalcDate() EndIf Local $sMsg Local $sMsgHdr Local $n1 Local $sDeleteIndex Local $aDeleteIndex Local $iCnt = 0 Local $iRows Local $iColMax Local $iDim Local $sData Local $sVType Local $sDType Local $LBound Local $iDiff If $iOptionBase <> 0 Then $iOptionBase = 1 EndIf If _IsValueEmpty($aArray) Then Return SetError(1, 0, "") EndIf $iDim = UBound($aArray, $UBOUND_DIMENSIONS) If $iDim = 1 Then If $iCol <> 0 Then $iCol = 0 EndIf EndIf If $iDim = 2 Then $iColMax = UBound($aArray, $UBOUND_COLUMNS) - 1 If $iCol > $iColMax Or $iCol < 0 Then Return SetError(1, 0, "") EndIf EndIf If Not _IsBetween($iDim, 1, 2) Then ;############### MSG2 - START ############### $sMsgHdr = FuncName($hFunc) & " :Line: " & @ScriptLineNumber & " :Error= " & @error $sMsg = "Invalid Dimensioned Array. Must be a 1 or 2 dimensional array." MsgBox(0, $sMsgHdr, $sMsg) Return SetError(1, 0, "") ;############### MSG2 - END ############### EndIf ; Identify what the value is ; If it is not a String, Int, Number, or Date then skip. Select Case _DateIsValid($vValue) = 1 $sVType = "D" Case IsNumber($vValue) = 1 $sVType = "N" Case IsString($vValue) = 1 $sVType = "S" Case Else ;############### MSG2 - START ############### $sMsgHdr = FuncName($hFunc) & " :Line: " & @ScriptLineNumber & " :Error= " & @error $sMsg = "Comparison value must be a " & @CRLF & _ "1. Date in YYYY/MM/DD format " & @CRLF & _ "2. A string " & @CRLF & _ "3. A number " & @CRLF MsgBox(0, $sMsgHdr, $sMsg) Return SetError(1, 0, "") ;############### MSG2 - END ############### EndSelect $iCnt = 0 For $n1 = UBound($aArray) - 1 To $iOptionBase Step -1 If $iDim = 1 Then $sData = StringStripWS($aArray[$n1], 3) ElseIf $iDim = 2 Then $sData = StringStripWS($aArray[$n1][$iCol], 3) EndIf Select Case _DateIsValid($sData) = 1 $sDType = "D" Case IsNumber($sData) = 1 $sDType = "N" Case IsString($sData) = 1 $sDType = "S" Case Else $sDType = "U" EndSelect If _IsValueEmpty($sData) Then $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop ; $sDType = $sVType EndIf If Not _IsValueEmpty($sData) And $sDType <> $sVType Then $sDeleteIndex = $sDeleteIndex & $n1 & "," $iCnt += 1 ContinueLoop EndIf Select Case $sOperator = "EQ" Switch $sDType Case "D" $iDiff = _DateDiff("D", $vValue, $sData) If $iDiff = 0 Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "S" If $sData = $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "N" If $sData = $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "NEQ" Switch $sDType Case "D" If $sData <> $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "S" If $sData <> $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "N" If $sData <> $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "IN" Switch $sDType Case "S" If StringInStr($sData, $vValue) Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "GT" Switch $sDType Case "N" If $sData > $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "D" $iDiff = _DateDiff("D", $vValue, $sData) If $iDiff > 0 Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "GE" Switch $sDType Case "N" If $sData >= $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "D" $iDiff = _DateDiff("D", $vValue, $sData) If $iDiff >= 0 Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "LT" Switch $sDType Case "N" If $sData < $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "D" $iDiff = _DateDiff("D", $vValue, $sData) If $iDiff < 0 Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch Case $sOperator = "LE" Switch $sDType Case "N" If $sData <= $vValue Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop Case "D" $iDiff = _DateDiff("D", $vValue, $sData) If $iDiff <= 0 Then ContinueLoop EndIf $sDeleteIndex &= $n1 & "," $iCnt += 1 ContinueLoop EndSwitch EndSelect Next If $iCnt > 0 Then _DeleteArrayRows($aArray, $sDeleteIndex) EndIf EndFunc ;==>_ArrayFilter Thanks in advance.
      OldGuyWalking
    • MyEarth
      By MyEarth
      Hello. I have a 1D array. Is made in this way:
      1. This is a line Messages: a message etc Context: a context etc 2. This is a line Messages: a message etc Context: a context etc 3. This is a line Messages: a message etc Correction: a correction etc Context: a context etc I need to make something like:
      1. This is a line|Messages: a message etc|Context: a context etc 2. This is a line|Messages: a message etc|Context: a context etc 3. This is a line|Messages: a message etc|Correction: a correction|Context: a context etc For exporting in another software. I need to split every time there is a number when the line start, can be 1. until something like 3.976. Since i don't know if there a 2 line after a number or 3 i have opened this thread. Thanks
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.