Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a problem about programming

45 views
Skip to first unread message

Lino

unread,
Nov 23, 2016, 12:52:53 PM11/23/16
to
Script Below


--------------
AB = CreateObject("Broker.Application");
sts = AB.Stocks();
Qty = sts.Count;


for( i = Qty - 1; i >= 0; i = i - 1 )
{
st = sts.Item( i );
Ticker = st.Ticker;
printf("changing " + ticker + "\n" );
Length = StrLen(Ticker );
if( StrFind(ticker, ".TO") )
st.Ticker = StrLeft( ticker, Length-3)+"-TC";
}

-------------

I Have a database with many symbols and the script [above] change latest
(RIGHT) 3 letter of any symbol.

Now, how can I change the script above to modify the "FIRST THREE" of any
Symbol ?


Thanks
Lino

Louis Krupp

unread,
Nov 23, 2016, 3:10:59 PM11/23/16
to

Lino

unread,
Nov 23, 2016, 3:19:41 PM11/23/16
to
Louis Krupp scriveva il 23/11/2016 :
oh yes, I try to change st.Ticker

st.Ticker= "TC-"+StrRight(ticker,Lenght-3);

but won't work. Can You help me?

Louis Krupp

unread,
Nov 23, 2016, 3:35:22 PM11/23/16
to
When you say it doesn't work, what do you mean? What happens when you
try it? What does st.Ticker look like before and after you try to
change it?

Louis

Lino

unread,
Nov 23, 2016, 3:37:26 PM11/23/16
to
Louis Krupp ha detto questo mercoledì :
this work well

st.Ticker= "IT_"+StrRight(ticker,Lenght+3);


but change only 1 symbol (the last) and I have hundred symbols.
Maybe the problem iis in the FOR cycle.
Can you help me?

Thanks.
Lino

Louis Krupp

unread,
Nov 23, 2016, 3:54:41 PM11/23/16
to
Only if you show me your code.

I did notice something about what you posted earlier:

for( i = Qty - 1; i >= 0; i = i - 1 )
{
st = sts.Item( i );
Ticker = st.Ticker;

** This variable 'Ticker' starts with an upper case 'T'

printf("changing " + ticker + "\n" );

** This one stars with a lower case 't'

Length = StrLen(Ticker );

** Upper case

if( StrFind(ticker, ".TO") )
st.Ticker = StrLeft( ticker, Length-3)+"-TC";

** Lower case
}

Do you really have two variable, 'Ticker' and 'ticker'? Where do you
assign a value to 'ticker' with a lower case 't'? Could this be part
of your problem?

Louis

Lino

unread,
Nov 23, 2016, 4:46:54 PM11/23/16
to
> Do you really have two variable, 'Ticker' and 'ticker'? Where do you
> assign a value to 'ticker' with a lower case 't'? Could this be part
> of your problem?

> Louis


ok I have corrected the script:


-------------------------------------------
AB = CreateObject("Broker.Application");
sts = AB.Stocks();
Qty = sts.Count;


for( i = Qty - 1; i >= 0; i = i - 1 )
{
st = sts.Item( i );
Ticker = st.Ticker;
printf("changing " + Ticker + "\n" );
Length = StrLen(Ticker );
if( StrFind(Ticker, "BIT:") )

st.Ticker= "TC-"+StrRight(Ticker,Lenght+3);

}


-------------------------------------------


this (below) work partially and it have 2 problem:

----> st.Ticker= "IT_"+StrRight(ticker,Lenght+3);



1. change only 1 symbol a time (I think it's a "FOR Cycle" problem)

2.

Example: I have symbols [below] -----> and result

TO:A TC-T:A wrong
TO:DE TC-:DE wrong
TO:ASD TC-ASD OK OK OK OK
TO:AXMA TC-XMA Wrong
TO:ERJTT TC-JTT wrong


I want to change "only" the "TO:" or the part of string that I want to change
leaving the rest the same as originally printed.


Hope I'an clear. Tell me a specific question to clarify it myself.
Thanks for help.

Lino.

Lino

unread,
Nov 23, 2016, 4:48:43 PM11/23/16
to
Corrected : if( StrFind(Ticker, "TO-") )

Lino

unread,
Nov 23, 2016, 4:53:45 PM11/23/16
to
Dopo dura riflessione, Lino ha scritto :
> Corrected : if( StrFind(Ticker, "TO-") )

TO:

Louis Krupp

unread,
Nov 23, 2016, 6:05:37 PM11/23/16
to
Does it work? If so, congratulations! If not, please post your code
and your results.

Louis

Lino

unread,
Nov 23, 2016, 6:37:19 PM11/23/16
to
Louis Krupp wrote:

> Does it work? If so, congratulations! If not, please post your code
> and your results.

> Louis


------------------------------------------------
code written in AFL language (Amibroker Formula Language)
[https://www.amibroker.com/guide/AFL.html]


AB = CreateObject("Broker.Application");
sts = AB.Stocks();
Qty = sts.Count;

for( i = Qty - 1; i >= 0; i = i - 1 )
{
st = sts.Item( i );
Ticker = st.Ticker;
printf("changing " + Ticker + "\n" );
Length = StrLen(Ticker );
if( StrFind(Ticker, "TO:") )

st.Ticker= "TC-"+StrRight(Ticker,Lenght+3);

}
-------------------------------------------------------------



haven't a code result.
The result is in the symbol changed on my database on the screen.

...and the results are 2 errors:


[1]. change only 1 symbol a time (every time i click "apply") and I think
it's a "FOR Cycle" problem.



[2]. Example: I have a list symbols on the left side [below] -----> and the
result in the symbols modified [every time I click apply script] in the
right side.


TO:A TC-T:A [wrong]
TO:DE TC-:DE [wrong]
TO:ASD TC-ASD OK <<<<<<< Thats OK (I want this)
TO:AXMA TC-XMA [Wrong]
TO:ERJTT TC-JTT [wrong]


I want to change in this case "ONLY" the "TO:" [or in other case the part of
string that I want to change from the first chacacter on the left] leaving

Louis Krupp

unread,
Nov 23, 2016, 9:44:24 PM11/23/16
to
On Thu, 24 Nov 2016 00:37:09 +0100, Lino <li...@net.com> wrote:

>Louis Krupp wrote:
>
>> Does it work? If so, congratulations! If not, please post your code
>> and your results.
>
>> Louis
>
>
>------------------------------------------------
>code written in AFL language (Amibroker Formula Language)
>[https://www.amibroker.com/guide/AFL.html]
>
>
>AB = CreateObject("Broker.Application");
>sts = AB.Stocks();
>Qty = sts.Count;
>
>for( i = Qty - 1; i >= 0; i = i - 1 )
>{
> st = sts.Item( i );
> Ticker = st.Ticker;
> printf("changing " + Ticker + "\n" );
> Length = StrLen(Ticker );
> if( StrFind(Ticker, "TO:") )
>
> st.Ticker= "TC-"+StrRight(Ticker,Lenght+3);

What is 'Lenght', and why are you adding 3 to it?

Does AFL allow you to use variables you haven't declared?

Louis

Lino

unread,
Nov 24, 2016, 3:43:23 AM11/24/16
to
Louis Krupp ha usato la sua tastiera per scrivere :
please note that I'm not a programmer.
I have only copy an existant code to adapt it for this little work for
changing the name ot multiple symbol on Dbase.

-I think (but not sure) the plus (on Lenght) isin't necessary on StrRight
[https://www.amibroker.com/guide/afl/strright.html]


-Lenght is a lenght (number) of the sting of the symbol (StrLeng)
http://www.amibroker.com/guide/afl/strlen.html

Louis Krupp

unread,
Nov 24, 2016, 11:47:09 AM11/24/16
to
Your program, as you last posted it:

AB = CreateObject("Broker.Application");
sts = AB.Stocks();
Qty = sts.Count;

for( i = Qty - 1; i >= 0; i = i - 1 )
{
st = sts.Item( i );
Ticker = st.Ticker;
printf("changing " + Ticker + "\n" );
Length = StrLen(Ticker );

** 'Length' is now set to the length of the symbol

if( StrFind(Ticker, "TO:") )
st.Ticker= "TC-"+StrRight(Ticker,Lenght+3);

** 'Lenght' is not the same as 'Length'. My guess is that 'Lenght' is
** zero.
**
** I would try this:
** st.Ticker= "TC-"+StrRight(Ticker,Length - 3);

}

Let me know what happens.

Louis

Richard

unread,
Nov 24, 2016, 1:24:22 PM11/24/16
to
[Please do not mail me a copy of your followup]

Lino <li...@net.com> spake the secret code
<mn.bc6c7e0ba4c48da2.142705@Kiss-the-Sphinx> thusly:

>Script Below

Wrong newsgroup. Try a forum for Windows Scripting.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages