Hi All,
I'd like to deconstruct a string and get all the variables contained with in it.
I'm sure there's a "clever" way to do it.
The pattern is always the same; the variables are contained within quotes after the "=", separated by the &.
The name at the begining can change and is not that important the number of variables can also change.
eg CUST="26082"&"29185"&"35247"&"45407"&"65488"&"72471"&"110082"
Thanks
Danton
Deconstruct string
Moderators: Dorian (MJT support), JRL
Try this:
This will return an array of variables, i.e.
ITEMS_1="26082"
ITEMS_2="29185"
ITEMS_3="35247"
ITEMS_4="45407"
ITEMS_5="65488"
ITEMS_6="72471"
ITEMS_7="110082"
And also return a variable with the count of the items, i.e.
ITEMS_COUNT=7
Code: Select all
Let>String=CUST="26082"&"29185"&"35247"&"45407"&"65488"&"72471"&"110082"
Position>=",String,1,nPos,TRUE
Add>nPos,1
Length>String,nLength
MidStr>String,nPos,nLength,strSub
Separate>strSub,&,Items
ITEMS_1="26082"
ITEMS_2="29185"
ITEMS_3="35247"
ITEMS_4="45407"
ITEMS_5="65488"
ITEMS_6="72471"
ITEMS_7="110082"
And also return a variable with the count of the items, i.e.
ITEMS_COUNT=7
adroege wrote:Try this:
This will return an array of variables, i.e.Code: Select all
Let>String=CUST="26082"&"29185"&"35247"&"45407"&"65488"&"72471"&"110082" Position>=",String,1,nPos,TRUE Add>nPos,1 Length>String,nLength MidStr>String,nPos,nLength,strSub Separate>strSub,&,Items
ITEMS_1="26082"
ITEMS_2="29185"
ITEMS_3="35247"
ITEMS_4="45407"
ITEMS_5="65488"
ITEMS_6="72471"
ITEMS_7="110082"
And also return a variable with the count of the items, i.e.
ITEMS_COUNT=7
Great, thanks, that works!!
adroege wrote:Try this:
This will return an array of variables, i.e.Code: Select all
Let>String=CUST="26082"&"29185"&"35247"&"45407"&"65488"&"72471"&"110082" Position>=",String,1,nPos,TRUE Add>nPos,1 Length>String,nLength MidStr>String,nPos,nLength,strSub Separate>strSub,&,Items
ITEMS_1="26082"
ITEMS_2="29185"
ITEMS_3="35247"
ITEMS_4="45407"
ITEMS_5="65488"
ITEMS_6="72471"
ITEMS_7="110082"
And also return a variable with the count of the items, i.e.
ITEMS_COUNT=7
Thanks again,
I tried the next step myself but I've been pulling my hair out trying to get it to work.
Ideally I'd like to post this array to excel using DDEPoke
DDERequest>Excel,%filename%,R1C1,strData,10
Let>String=strData
Position>=",String,1,nPos,TRUE
Add>nPos,1
Length>String,nLength
MidStr>String,nPos,nLength,strSub
Separate>strSub,&,Items
Let>xlRow=%xlRow%+1
DDEPoke>Excel,%filename%,R%xlRow%C1,%ITEMS_1%
Let>xlRow=%xlRow%+1
DDEPoke>Excel,%filename%,R%xlRow%C1,%ITEMS_2%
I can get this to work, but it's clumsy. I'd like to use a loop and repeat until the end of the array. Basically can we have a count with the items_x variable?
Thanks again
Danton
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
The count is in items_count. Separate produces items_1 ... items_n plus items_count
So you can loop through the array:
And I would use XLGetCell and XLSetCell rather than DDERequest/DDEPoke
So you can loop through the array:
Code: Select all
Let>k=0
Repeat>k
Let>k=k+1
Let>this_item=items_%k%
...
Until>k=items_count
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
mtettmar wrote:The count is in items_count. Separate produces items_1 ... items_n plus items_count
So you can loop through the array:
And I would use XLGetCell and XLSetCell rather than DDERequest/DDEPokeCode: Select all
Let>k=0 Repeat>k Let>k=k+1 Let>this_item=items_%k% ... Until>k=items_count
Strange. For some reason DDERequest has suddenly stopped working. It worked flawlessly on a previous script in the past and was working earlier today and now it's not working on either the new or old script I get a "strdata=DDE_service_invalid"