Jump to content

string concantenation not working


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

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

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

garysr59,

Declare $t before the loop and see how that works out for you.

Edited by guinness

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

  • Moderators

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:

Local $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? :huh:

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

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 by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Adding a seperator did the trick. Though I could swear I tried that  :sorcerer:

Cheerio and thanks for all your help :thumbsup: 

 

therefore, I would be interested to know what was the cause of the problem please

for what reason the strings were not concatenated?

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...