Jump to content

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


JonBMN
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

×
×
  • Create New...