Jump to content

trouble with arraytostring


 Share

Go to solution Solved by Jewtus,

Recommended Posts

I'm trying to populate a a list guide box with an array of data, but Ian can't seem to get it functional. I read another that said you needed to convert the array to a string prior to using guictrlsetdata and both array to string and guictrlsetdata use | as the delimiter I could do something like this:

Guictrlsetdata($Resultlist, _arraytostring ($aresult) )

But it did not work. I also tried to just view it in a massage box as well, but the arraytostring command keeps spitting out blanks. I've even tried to transpose the array (Thinking the vertical might be the issue because it's using @crlf as a delimiter).

I've also tried a simpler array (I'm grabbing data from a dB using a ado connection) and it seems to work fine. I'm including my code for additional context.

Edited by Jewtus
Link to comment
Share on other sites

Would you please be so kind and enclose your code in AutoIt code tags (that's the blue "A" in the editor).? That enhances readability a lot :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

Jewtus,

Repost the code and I will format it for you. :)

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

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
#cs
$Array = "1234|4321"
$populateResults = StringSplit($Array,"|",2)
$Main = GUICreate("Main Menu", 624, 563, -1078, 138)
$Entry = GUICtrlCreateInput("", 8, 26, 121, 21)
$SearchButton = GUICtrlCreateButton("Search", 294, 25, 75, 25)
$Results = GUICtrlCreateList("", 8, 56, 209, 448)
GUISetState(@SW_SHOW)
 
While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                                Case $GUI_EVENT_CLOSE
                                                Exit
                                Case $SearchButton
                                                _ArrayDisplay($populateResults)
                                                MsgBox(0,"",_ArrayToString($populateResults))
                EndSwitch
WEnd
#ce
 
$sqlConLoans2 = ObjCreate("ADODB.Connection")
$sqlConLoans2.Open ($connectionstring)
If @error Then
    MsgBox(0, "ERROR", "Failed to connect to the database")
    Exit
EndIf
 
$Main = GUICreate("Main Menu", 624, 563, -1078, 138)
$IDEntry = GUICtrlCreateInput("", 8, 26, 121, 21)
$RequestIDEntry = GUICtrlCreateInput("", 157, 26, 133, 21)
$SearchButton = GUICtrlCreateButton("Search", 294, 25, 75, 25)
$Results = GUICtrlCreateList("", 8, 56, 209, 448)
$Label1 = GUICtrlCreateLabel("OR", 135, 30, 20, 17)
$CaseSelect = GUICtrlCreateButton("Select Case", 16, 512, 75, 25)
$TreeView1 = GUICtrlCreateTreeView(248, 56, 545, 449)
$IDLabel = GUICtrlCreateLabel("ID", 10, 9, 26, 17)
$RequestIDLabel = GUICtrlCreateLabel("Request ID", 159, 9, 58, 17)
GUISetState(@SW_SHOW)
While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                                Case $GUI_EVENT_CLOSE
                                                Exit
                                Case $SearchButton
                                                If $IDEntry <> '' Then
                                                                $ID = GUICtrlRead($IDEntry)
                                                                $sqlRs2 = ObjCreate("ADODB.Recordset")
                                                                $sqlRs2.open ("Select RequestID from Request where ID = '""$ID""'", $sqlConLoans2)
                                                                $populateResults = $sqlRs2.GetRows
                                                                _ArrayDisplay($populateResults)
                                                                MsgBox(0,"",_ArrayToString($populateResults))
                                                                GUICtrlSetData($Results,_ArrayToString($populateResults))
                                                                GUICtrlSetData($IDEntry,'')
                                                EndIf
                                EndSwitch
WEnd
All done. :)

M23

P.S. Next time just add these lines manually before and after the code:

[code=autoit:0]; code here[/code]
Edited by Jewtus
Link to comment
Share on other sites

I see.

Even the "Full Version" of the editor seems to be a stripped down version on a mobile device.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Jewtus,Repost the code and I will format it for you. :)M23

Thanks!

Also, with the array, it does show the result data when I use the ArrayDisplay command

Edited by Jewtus
Link to comment
Share on other sites

  • Solution

AHHH HA! I figured it out.

Because I was using GetRows, I need to handle the result as a 2d array.

This is how I figured it out

$Result = $sqlRs2.GetRows
_ArrayDisplay($Result)
for $z=0 to (UBound($Result)) -1
   MsgBox(0,"",$Result[$z])
Next

and I got this error

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Once I changed it to $Result[$z][0] it worked flawlessly

Link to comment
Share on other sites

Not sure exactly what you mean with what does the data source look like... 

I'm not willing to put the connection string in as its a private database and the connection string has my credentials, but I can say its a SQLOLEDB provider.

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...