garysr59 Posted January 7, 2014 Posted January 7, 2014 hello For some odd reason, string concantenation in the script I am working on, does not work. In a loop I am trying to add to a string with this command $t &= $Array[$j] $Array[$j] changes its value as the index is incremented, however $t never changes. It picks up the value at the first index and never changes as the loop is processed.
DatMCEyeBall Posted January 7, 2014 Posted January 7, 2014 Show all your code perhaps you made a mistake somewhere else that causes this. "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation
Moderators Melba23 Posted January 7, 2014 Moderators Posted January 7, 2014 garysr59,That is no use at all - please post the whole script or at least the loop section. And please use Code tags when you do - see here how to do it. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 (edited) do ; read into array from host $Array[$j] = StdoutRead($pID) ; cleanup the data $Array[$j] =StringReplace($Array[$j], "-", "") $Array[$j] =StringReplace($Array[$j], "Press any key to continue (Q to quit)", "" & @CR) $Array[$j] = StringStripWS($Array[$j], 4) $Array[$j] = StringReplace($Array[$j], "OK", "OK" & @CR) ;store into a variable $t &= $Array[$j] ;send - to the host to get next screen StdinWrite($pID, "-" & @CRLF) Sleep(300) $j = $j + 1 Until $j = 4 Edited January 7, 2014 by garysr59
l3ill Posted January 7, 2014 Posted January 7, 2014 $t &= $Array[$j] ___^__________ Is this & intentional ? My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
guinness Posted January 7, 2014 Posted January 7, 2014 (edited) garysr59, Declare $t before the loop and see how that works out for you. Edited January 7, 2014 by guinness DatMCEyeBall 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 Yes. Thought was the syntax for adding to the variable $t what is in the array
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 (edited) $t is declared before the loop Edited January 7, 2014 by garysr59
iamtheky Posted January 7, 2014 Posted January 7, 2014 (edited) declare all else before the loop as well and add some debug: #include <Array.au3> Global $Array[4] ;declare the array $j = 0 ; set $j to the first element before you start the do loop $t = "" ; set $t before you start appending strings to nothing do ; set data to array $Array[$j] = @HOUR & @MIN & @SEC & @MSEC ;do whatever ;then maybe see what it looks like _ArrayDisplay($Array) ;store into a variable $t &= $Array[$j] & @LF ;then maybe take a look at that msgbox (0, '' , $t) ;then do whatever and sleep and increment Sleep(500) $j = $j + 1 Until $j = 4 Edited January 7, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
l3ill Posted January 7, 2014 Posted January 7, 2014 It seems to me that to concatenate $t with your var $t has to be holding something but it is an empty variable at this point. Or am I missing the boat? My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 Array.au3 is included, $Array[4], $j = 0 and $t = "" have been declared previously Adding a message box shown here do ; read into array from host $Array[$j] = StdoutRead($pID) ; cleanup the data $Array[$j] =StringReplace($Array[$j], "-", "") $Array[$j] =StringReplace($Array[$j], "Press any key to continue (Q to quit)", "" & @CR) $Array[$j] = StringStripWS($Array[$j], 4) $Array[$j] = StringReplace($Array[$j], "OK", "OK" & @CR)MsgBox(1, "value of array at " & $j, $Array[$j]) ;store into a variable $t &= $Array[$j]MsgBox(1, "value of t ", $t) ;send - to the host to get next screen StdinWrite($pID, "-" & @CRLF) Sleep(300) $j = $j + 1 Until $j = 4 Array[$j] value first time is "1.1 HPDD VDISK 300 GB OK" "1.2 HPDD VDISK 300 GB OK" $t value first time is "1.1 HPDD VDISK 300 GB OK" "1.2 HPDD VDISK 300 GB OK Array[$j] value 2nd time is "1.3 HPDD VDISK 300 GB OK" "1.4 HPDD VDISK 300 GB OK" $t value 2nd time is still "1.1 HPDD VDISK 300 GB OK" "1.2 HPDD VDISK 300 GB OK The loop continues 2 more times. Everytime Array[$j] changes, but $t never does. I don't get it, $t should change
KaFu Posted January 7, 2014 Posted January 7, 2014 How about something like this? Local $i_timeout_timer Do $i_timeout_timer = TimerInit() While Sleep(10) $Array[$j] &= StdoutRead($pID) If @error Then ExitLoop If TimerDiff($i_timeout_timer) > 10000 Then MsgBox(16, "Error", "StdoutRead timed out...") StdioClose($pID) ExitLoop 2 EndIf WEnd ; cleanup the data $Array[$j] = StringReplace($Array[$j], "-", "") $Array[$j] = StringReplace($Array[$j], "Press any key to continue (Q to quit)", "" & @CR) $Array[$j] = StringStripWS($Array[$j], 4) $Array[$j] = StringReplace($Array[$j], "OK", "OK" & @CR) ; MsgBox(1, "value of array at " & $j, $Array[$j]) ;store into a variable $t &= $Array[$j] ; MsgBox(1, "value of t ", $t) ;send - to the host to get next screen StdinWrite($pID, "-" & @CRLF) ; Sleep(300) $j = $j + 1 Until $j = 4 StdioClose($pID) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 That's nice but $t still doesn't add the array values
Moderators Melba23 Posted January 7, 2014 Moderators Posted January 7, 2014 garysr59,Firstly, I have lifted you "New Member" posting restriction - so keep on posting. Now, here is your script with a preset array and for me the concatenation works perfectly - I presume it will for you too:expandcollapse popupLocal $i_timeout_timer Global $Array[4] = ["A", "B", "C", "D"], $j = 0, $t = "" Do #cs $i_timeout_timer = TimerInit() While Sleep(10) $Array[$j] &= StdoutRead($pID) If @error Then ExitLoop If TimerDiff($i_timeout_timer) > 10000 Then MsgBox(16, "Error", "StdoutRead timed out...") StdioClose($pID) ExitLoop 2 EndIf WEnd #ce ; cleanup the data ;$Array[$j] = StringReplace($Array[$j], "-", "") ;$Array[$j] = StringReplace($Array[$j], "Press any key to continue (Q to quit)", "" & @CR) ;$Array[$j] = StringStripWS($Array[$j], 4) ;$Array[$j] = StringReplace($Array[$j], "OK", "OK" & @CR) ; MsgBox(1, "value of array at " & $j, $Array[$j]) ;store into a variable $t &= $Array[$j] ; MsgBox(1, "value of t ", $t) ;send - to the host to get next screen ;StdinWrite($pID, "-" & @CRLF) ; Sleep(300) $j = $j + 1 Until $j = 4 ConsoleWrite($t & @CRLF) ;StdioClose($pID)So I suggest the problem is that you are ending up with an empty string after you have read and cleaned the StdoutRead. Have you tried a ConsoleWrite or MsgBox to see what you are actually trying to concatenate? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
iamtheky Posted January 7, 2014 Posted January 7, 2014 (edited) msgbox(0, '' , StdoutRead($pID)) first. if there are no contents expect blanks. *or add a seperator and have a visual $t &= $Array[$j] & ":" if you see three colons in a row they were blanks Edited January 7, 2014 by boththose garysr59 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
garysr59 Posted January 7, 2014 Author Posted January 7, 2014 Yes I can do the same with a prefilled array. Concatenation works. However it doesn't work with an array picking up its values from a StdoutRead. Going back to my code, msgbox right after the read shows $Array[$j] = StdoutRead($pID)MsgBox(1, "value of array at " & $j, $Array[$j]) Array[$j] value first time is "1.1 HPDD VDISK 300 GB OK" "1.2 HPDD VDISK 300 GB OK" Array[$j] value 2nd time is "1.3 HPDD VDISK 300 GB OK" "1.4 HPDD VDISK 300 GB OK" this works as expected thru the loop. It is the concatenation of the array contents to a single variable that doesn't work $t &= $Array[$j]MsgBox(1, "value of t ", $t) $t value all time thru the loop remains at "1.1 HPDD VDISK 300 GB OK" "1.2 HPDD VDISK 300 GB OK
Gianni Posted January 7, 2014 Posted January 7, 2014 (edited) maybe there is a chr(0) in the string $t after the second OK"300 GB 1.1 HPDD VDISK OK""300 GB 1.2 HPDD VDISK OK <- here maybe there is a chr(0) to test try to use this (flag 8 instead of 4): $Array[$j] = StringStripWS($Array[$j], 8) edit: or also try to add another one cleanup statement after the others like this: $Array[$j] = StringReplace($Array[$j], chr(0), "") Edited January 8, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
garysr59 Posted January 8, 2014 Author Posted January 8, 2014 Adding a seperator did the trick. Though I could swear I tried that Cheerio and thanks for all your help
Gianni Posted January 8, 2014 Posted January 8, 2014 Adding a seperator did the trick. Though I could swear I tried that Cheerio and thanks for all your help therefore, I would be interested to know what was the cause of the problem please for what reason the strings were not concatenated? Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
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