Jump to content
Sign in to follow this  
Jewtus

trouble with arraytostring

Recommended Posts

Jewtus

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

Share this post


Link to post
Share on other sites
water

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 :)

  • Like 1

My UDFs and Tutorials:

Spoiler

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

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jewtus

I'm on a mobile device so I can't but I put into a text file

Share this post


Link to post
Share on other sites
Melba23

Jewtus,

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

M23

  • Like 1

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

 

Share this post


Link to post
Share on other sites
Jewtus

#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

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Jewtus

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

Share this post


Link to post
Share on other sites
Jewtus

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

Share this post


Link to post
Share on other sites
kylomas

jewtus,

Just out of curiousity:

  1. What does your data source look like?
  2. What does $connectionstring contain?

 

Thanks,

kylomas


Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Jewtus

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.

Share this post


Link to post
Share on other sites
kylomas

NP, just curious about your use of SQL with a recordset...been many years since I used the active data object, a refresher is probably in order...


Forum Rules         Procedure for posting code

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

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • jimdaway
      By jimdaway
      I'm struggling with something I'm sure I've missed...
      I have a 1-dimensional array and I'm populating a ListBox using an _ArrayToString function within the GUICtrlSetData function.
      If I perform an _ArrayReverse on the array before I execute the _ArrayToString function within the GUICtrlSetData, the list still populates in a sorted order.
      If I do an _ArrayDisplay, it's showing to be reversed but when I populate the ListBox, it's still sorted!
      _GetDirectoryListing() _ArrayReverse($aMasterJobList) _ArrayDisplay($aMasterJobList) GUICtrlSetData($hJobList, _ArrayToString($aMasterJobList)) Am I missing a subtle (or not-so subtle) flag somewhere?
×