cesinha87 Posted August 15, 2019 Share Posted August 15, 2019 Never used Array and I am clueless how to assign the output of the Array to a variable. Essentially what I want to do is assign $db_ServerName to Row 0, $db_DatabaseName to Row 1, $db_port to Row 3 Link to comment Share on other sites More sharing options...
spudw2k Posted August 15, 2019 Share Posted August 15, 2019 You can reference the content of an array by using brackets at the end of the array, and the index of the desired element. For example $aArrayVariableName[0] would reference the string "WIN2K16" in your array above (using the correct array variable name of course). This article should tell you everything you need to know about Arrays.https://www.autoitscript.com/wiki/Arrays Let us know if you have questions. Just as a recommendation. I find it useful to use Constants to collect info from arrays to make it easier to read the source, and you don't have to keep track of what index numbers represent the contents of an array. This also depends on the accuracy of the array being produced, but additional error checking/logic should help rule out anomalies. #include <Array.au3> Const Enum $DB_HOSTNAME, $DB_NAME, $DB_FIELD, $DB_PORT Local $aTest[4]=['WIN2K16','ePO_WIN2K16','',1433] Local $db_ServerName = $aTest[$DB_HOSTNAME] Local $db_DatabaseName = $aTest[$DB_NAME] Local $db_DatabasePort = $aTest[$DB_PORT] Msgbox(0,"DB Info",$db_ServerName & @CRLF & $db_DatabaseName & @CRLF & $db_DatabasePort) Also, depending on your situation, you may not need to go through the work of creating variables which duplicate the values in the array. Up to you and your needs. FrancescoDiMuro 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
cesinha87 Posted August 16, 2019 Author Share Posted August 16, 2019 It didn't quite work for me. Having a hard time to understand this Array thing. My Array output is assigned to $res $read = FileRead($read) ;MsgBox(0, "", $read) $res = StringRegExp($read, 'db\.(?|server.name|database.name|instance.name|port)=(\N*)', 3) _ArrayDisplay($res) Const Enum $DB_HOSTNAME, $DB_NAME, $DB_FIELD, $DB_PORT Local $res[4] Local $db_ServerName = $res[$DB_HOSTNAME] Local $db_DatabaseName = $res[$DB_NAME] Local $db_DatabasePort = $res[$DB_PORT] Msgbox(0,"DB Info",$db_ServerName & @CRLF & $db_DatabaseName & @CRLF & $db_DatabasePort) Link to comment Share on other sites More sharing options...
cesinha87 Posted August 16, 2019 Author Share Posted August 16, 2019 What I don't understand is the piece? Local $aTest[4]=['WIN2K16','ePO_WIN2K16','',1433] Here I am declaring 'WIN2k16' and this will change if I run in a different environment. It should get the info coming from the regex and assigned a variable to it Global $read = $file $read = FileRead($read) ;MsgBox(0, "", $read) $res = StringRegExp($read, 'db\.(?|server.name|database.name|instance.name|port)=(\N*)', 3) _ArrayDisplay($res) Link to comment Share on other sites More sharing options...
spudw2k Posted August 16, 2019 Share Posted August 16, 2019 Remove Local $res[4] from your example. You are effectively erasing the array returned from your StringRegExp function call. cesinha87 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
spudw2k Posted August 16, 2019 Share Posted August 16, 2019 8 hours ago, cesinha87 said: What I don't understand is the piece? Local $aTest[4]=['WIN2K16','ePO_WIN2K16','',1433] That is just an array I created to replicate the contents from your original screenshot. Don't worry about it, just tor demonstration purposes since I didn't know how your array was being generated. Just use the StringRegExp you got. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
water Posted August 16, 2019 Share Posted August 16, 2019 How about _ArrayToString to create a string? 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 More sharing options...
spudw2k Posted August 17, 2019 Share Posted August 17, 2019 @water The OP already has a string that he is parsing into an array using REGEX, and he was asking for help using arrays. I don't think turning a string into an array and back into a string helps him accomplish that. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
water Posted August 17, 2019 Share Posted August 17, 2019 On 8/15/2019 at 3:55 AM, cesinha87 said: Never used Array and I am clueless how to assign the output of the Array to a variable. And the title of the thread asks for the same. So he gets what he’s asking for 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now