Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #6996 > unrolled thread

A problem about programming

Started byLino <lino@net.com>
First post2016-11-23 19:09 +0100
Last post2016-11-24 17:18 +0000
Articles 15 — 3 participants

Back to article view | Back to comp.programming


Contents

  A problem about programming Lino <lino@net.com> - 2016-11-23 19:09 +0100
    Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 19:36 +0000
      Re: A problem about programming Lino <lino@net.com> - 2016-11-23 21:04 +0100
      Re: A problem about programming Lino <lino@net.com> - 2016-11-23 23:38 +0100
    Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 21:01 +0000
      Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-23 21:02 +0000
      Re: A problem about programming Lino <lino@net.com> - 2016-11-23 22:38 +0100
        Re: A problem about programming Lino <lino@net.com> - 2016-11-23 22:40 +0100
        Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 09:33 +0000
          Re: A problem about programming Lino <lino@net.com> - 2016-11-24 11:18 +0100
            Re: A problem about programming Lino <lino@net.com> - 2016-11-24 12:49 +0100
              Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 12:08 +0000
          Re: A problem about programming Lino <lino@net.com> - 2016-11-24 14:08 +0100
          Re: A problem about programming BartC <bc@freeuk.com> - 2016-11-24 17:14 +0000
            Re: A problem about programming Richard Heathfield <rjh@cpax.org.uk> - 2016-11-24 17:18 +0000

#6996 — A problem about programming

FromLino <lino@net.com>
Date2016-11-23 19:09 +0100
SubjectA problem about programming
Message-ID<mn.bc7d7e0bef53dd75.142705@Kiss-the-Sphinx>
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

[toc] | [next] | [standalone]


#6997

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-23 19:36 +0000
Message-ID<o14r13$29k$1@dont-email.me>
In reply to#6996
On 23/11/16 18:09, Lino wrote:
> 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 ?

I know this will probably sound like rather a strange question, but what 
language is that code written in? Your chances of getting a good answer 
will be greatly increased if we know what language you're using.

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#6998

FromLino <lino@net.com>
Date2016-11-23 21:04 +0100
Message-ID<mn.bcf07e0b72b99e35.142705@Kiss-the-Sphinx>
In reply to#6997
Richard Heathfield ha spiegato il 23/11/2016 :
> On 23/11/16 18:09, Lino wrote:
>> 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 ?

> I know this will probably sound like rather a strange question, but what 
> language is that code written in? Your chances of getting a good answer 
> will be greatly increased if we know what language you're using.

Jscript (but VBscript use the the same syntax)
Thanks

[toc] | [prev] | [next] | [standalone]


#7003

FromLino <lino@net.com>
Date2016-11-23 23:38 +0100
Message-ID<mn.bd8a7e0ba8f2191d.142705@Kiss-the-Sphinx>
In reply to#6997
Richard Heathfield speaks:

> I know this will probably sound like rather a strange question, but what 
> language is that code written in? Your chances of getting a good answer 
> will be greatly increased if we know what language you're using.

It's AFL LAnguage
https://www.amibroker.com/guide/AFL.html

[toc] | [prev] | [next] | [standalone]


#6999

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-23 21:01 +0000
Message-ID<o1500m$m4q$1@dont-email.me>
In reply to#6996
On 23/11/16 18:09, Lino wrote:
> Script Below

(The OP says elsethread that the language is JavaScript or VBScript)

> --------------
> 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" );

JavaScript's attitude to case sensitivity is a little odd. But 
presumably your printf() call is displaying ticker correctly, so I'll 
let it pass.

> Length = StrLen(Ticker );

This is puzzling. In JavaScript, I would expect to see:

Length = Ticker.length;

And in VBScript, I'd expect to see:

Length = len(Ticker)

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

I can find no reference to a StrLeft function in JavaScript. I'd expect 
to see:

st.Ticker = Ticker.substring(0, Length - 3) + "-TC";

In VBScript, I'd expect to see:

st.Ticker = Mid(Ticker, 1, 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 ?

Here are four ways to do it --- I should warn you that I haven't tested 
any of them:

1) JavaScript:

   st.Ticker = concat("-TC", Ticker.substring(3, Length - 3);

2) VBScript:

   st.Ticker = "-TC" & Mid(Ticker, 4, Length + 1)

3) Your language, whatever it is, and assuming that the second arg to 
substring() represents the length of the substring:

   st.Ticker = "-TC" + Ticker.substring(3, Length - 3);

4) Your language, whatever it is, and assuming that the second arg to 
substring() represents the index of the first character that follows the 
substring and that the function is 0-based:

   st.Ticker = "-TC" + Ticker.substring(3, Length);

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#7000

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-23 21:02 +0000
Message-ID<o1503k$m4q$2@dont-email.me>
In reply to#6999
On 23/11/16 21:01, Richard Heathfield wrote:

<snip>

> 1) JavaScript:
>
>   st.Ticker = concat("-TC", Ticker.substring(3, Length - 3);

I missed a )

   st.Ticker = concat("-TC", Ticker.substring(3, Length - 3));

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#7001

FromLino <lino@net.com>
Date2016-11-23 22:38 +0100
Message-ID<mn.bd4e7e0be141a73c.142705@Kiss-the-Sphinx>
In reply to#6999
Richard Heathfield ha pensato forte :


> Here are four ways to do it --- I should warn you that I haven't tested any 
> of them:

> 1) JavaScript:
>    st.Ticker = concat("-TC", Ticker.substring(3, Length - 3);

> 2) VBScript:
>    st.Ticker = "-TC" & Mid(Ticker, 4, Length + 1)

> 3) 
>    st.Ticker = "-TC" + Ticker.substring(3, Length - 3);

> 4) 
>    st.Ticker = "-TC" + Ticker.substring(3, Length);


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
Thanks for help.

Lino.

[toc] | [prev] | [next] | [standalone]


#7002

FromLino <lino@net.com>
Date2016-11-23 22:40 +0100
Message-ID<mn.bd507e0bdad47a63.142705@Kiss-the-Sphinx>
In reply to#7001
Correct:

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

[toc] | [prev] | [next] | [standalone]


#7004

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-24 09:33 +0000
Message-ID<o16c26$eqd$1@dont-email.me>
In reply to#7001
On 23/11/16 21:38, Lino wrote:
<snip>
>
> this (below) work partially and it have 2 problem:
>
>        st.Ticker= "IT_"+StrRight(ticker,Lenght+3);

I think you mean "Length", not "Lenght".

I note that you wish the replacement substring to be "IT_" (and I think 
this is the first time you have mentioned this).

> 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
> Thanks for help.

So, if your other follow-up is correct, this isn't VBScript /or/ 
JavaScript, but something called AFL. Okay.

Specification: replace the first three characters of a string with three 
different supplied characters.

This AFL solution assumes that "TO:" will only occur once in the string:

StrReplace(st.Ticker, "TO:", "IT_");

And that's it! A one-line solution.

But if you are concerned that "TO:" might also occur elsewhere in the 
string, then StrReplace won't do it, because it replaces all 
occurrences, not just the first, in which case you'll need to do 
something like:

st.Ticker = "IT_" + strmid(st.Ticker, 3);

This assumes you are using AFL 5.90 or later, which allows you to omit 
the final length argument. Otherwise, you will have to do this:

Length = strlen(st.Ticker);
st.Ticker = "IT_" + strmid(st.Ticker, 3, Length - 3);

More generally, if you wish to replace the FIRST occurrence of a 
particular symbol OLD with some new symbol NEW, no matter where in the 
string OLD occurs, then you can do something like this (where // 
introduces a comment --- I don't know what the actual AFL comment syntax 
is):

old = "TO:"; // replace "TO:" with whatever you want out
new = "IT_"; // replace "IT_" with whatever you want in
left = "";
centre = new;
right = "";
st = sts.Item(i); // I'll have to trust you that this is correct
startpos = StrFind(st.Ticker, old); // where is the old string?
if(startpos > 0) // we have a match
{
   if(startpos > 1) // we need to save the part before the match
   {
     left = StrLeft(st.Ticker, startpos); // first part saved
   }

   // now we need to save the part /after/ the match.
   // The part after the match will be the length of the string,
   // LESS the length of the bit you want to get rid of, LESS
   // the length of the part we already accounted for.

   rightlength = StrLen(st.Ticker) - StrLen(old) - StrLen(left);

   // Now we can save the part after the match

   right = StrRight(st.Ticker, rightlength);

   // The easy bit: adding together all the bits we want to keep.

   st.Ticker = left + centre + right;
}

How does that work for you? (I can't test it because I don't have access 
to AFL.)

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#7005

FromLino <lino@net.com>
Date2016-11-24 11:18 +0100
Message-ID<mn.c2a67e0b772051a3.142705@net.com>
In reply to#7004
Scriveva Richard Heathfield giovedì, 24/11/2016:
> On 23/11/16 21:38, Lino wrote:
> <snip>
>>
>> this (below) work partially and it have 2 problem:
>>
>>        st.Ticker= "IT_"+StrRight(ticker,Lenght+3);

> I think you mean "Length", not "Lenght".

> I note that you wish the replacement substring to be "IT_" (and I think 
> this is the first time you have mentioned this).

>> 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
>> Thanks for help.

> So, if your other follow-up is correct, this isn't VBScript /or/ 
> JavaScript, but something called AFL. Okay.

> Specification: replace the first three characters of a string with three 
> different supplied characters.

> This AFL solution assumes that "TO:" will only occur once in the string:

> StrReplace(st.Ticker, "TO:", "IT_");

> And that's it! A one-line solution.

> But if you are concerned that "TO:" might also occur elsewhere in the 
> string, then StrReplace won't do it, because it replaces all occurrences, 
> not just the first, in which case you'll need to do something like:

> st.Ticker = "IT_" + strmid(st.Ticker, 3);

> This assumes you are using AFL 5.90 or later, which allows you to omit the 
> final length argument. Otherwise, you will have to do this:

> Length = strlen(st.Ticker);
> st.Ticker = "IT_" + strmid(st.Ticker, 3, Length - 3);

> More generally, if you wish to replace the FIRST occurrence of a particular 
> symbol OLD with some new symbol NEW, no matter where in the string OLD 
> occurs, then you can do something like this (where // introduces a comment 
> --- I don't know what the actual AFL comment syntax is):

> old = "TO:"; // replace "TO:" with whatever you want out
> new = "IT_"; // replace "IT_" with whatever you want in
> left = "";
> centre = new;
> right = "";
> st = sts.Item(i); // I'll have to trust you that this is correct
> startpos = StrFind(st.Ticker, old); // where is the old string?
> if(startpos > 0) // we have a match
> {
>    if(startpos > 1) // we need to save the part before the match
>    {
>      left = StrLeft(st.Ticker, startpos); // first part saved
>    }

>    // now we need to save the part /after/ the match.
>    // The part after the match will be the length of the string,
>    // LESS the length of the bit you want to get rid of, LESS
>    // the length of the part we already accounted for.

>    rightlength = StrLen(st.Ticker) - StrLen(old) - StrLen(left);

>    // Now we can save the part after the match

>    right = StrRight(st.Ticker, rightlength);

>    // The easy bit: adding together all the bits we want to keep.

>    st.Ticker = left + centre + right;
> }

> How does that work for you? (I can't test it because I don't have access to 
> AFL.)


I have AFL version 5.70.

Thank you very much for your patience.


  I test all (and correct my errors) above today in the afternoon and I'll 
send you a reply as soon as possible.

[toc] | [prev] | [next] | [standalone]


#7006

FromLino <lino@net.com>
Date2016-11-24 12:49 +0100
Message-ID<mn.c3017e0bbb5b6a7b.142705@net.com>
In reply to#7005
Dopo dura riflessione, Lino ha scritto :
> Scriveva Richard Heathfield giovedì, 24/11/2016:
>> On 23/11/16 21:38, Lino wrote:
>> <snip>
>>>
>>> this (below) work partially and it have 2 problem:
>>>
>>>        st.Ticker= "IT_"+StrRight(ticker,Lenght+3);

>> I think you mean "Length", not "Lenght".


aaaaaaaaarghhhhhhhhhhhh

now the problem of "cycle For" is resolved. All symbols is changed on apply.

:)

------



but remain the 2nd problem the "lenght of string" that isin't the same for 
all symbols

I'll try to adapt your help and I reply you for the result

THANKS :)

[toc] | [prev] | [next] | [standalone]


#7007

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-24 12:08 +0000
Message-ID<o16l5o$em5$1@dont-email.me>
In reply to#7006
On 24/11/16 11:49, Lino wrote:
> Dopo dura riflessione, Lino ha scritto :
>> Scriveva Richard Heathfield giovedì, 24/11/2016:
>>> On 23/11/16 21:38, Lino wrote:
>>> <snip>
>>>>
>>>> this (below) work partially and it have 2 problem:
>>>>
>>>>        st.Ticker= "IT_"+StrRight(ticker,Lenght+3);
>
>>> I think you mean "Length", not "Lenght".
>
>
> aaaaaaaaarghhhhhhhhhhhh
>
> now the problem of "cycle For" is resolved. All symbols is changed on
> apply.
>
> :)
>
> ------
>
>
>
> but remain the 2nd problem the "lenght of string" that isin't the same
> for all symbols

That is why I gave the rather longer solution in my most recent post. It 
was designed to work with any length inputs. (Whether it /does/ work 
with any length inputs isn't something I can test here, since I don't 
have AFL.)

If it /does/ work, you might want to consider turning it into a 
parameterised user-defined function, so that you don't have to solve the 
same problem again should it arise in a different context.

I don't know the syntax for AFL user-defined functions, but I would 
imagine it would look something like this:

// replace_first(): in the string s, search
// for the first occurrence of old. If found,
// return a string in which old is replaced with new.
// Otherwise, return the empty string.

function replace_first(s, old, new)
{
   result = "";
   left = "";
   centre = new;
   right = "";
   startpos = StrFind(s, old); // where is the old string?
   if(startpos > 0) // we have a match
   {
     if(startpos > 1) // we need to save the part before the match
     {
       left = StrLeft(s, startpos); // first part saved
     }

     // now we need to save the part /after/ the match.
     // The part after the match will be the length of the string,
     // LESS the length of the bit you want to get rid of, LESS
     // the length of the part we already accounted for.

     rightlength = StrLen(s) - StrLen(old) - StrLen(left);

     // Now we can save the part after the match

     right = StrRight(s, rightlength);

     // The easy bit: adding together all the bits we want to keep.

     result = left + centre + right;
   }
   return result;
}

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#7008

FromLino <lino@net.com>
Date2016-11-24 14:08 +0100
Message-ID<mn.c3507e0be7cf3d76.142705@net.com>
In reply to#7004
Richard Heathfield ha usato la sua tastiera per scrivere :


> This AFL solution assumes that "TO:" will only occur once in the string:

> StrReplace(st.Ticker, "TO:", "IT_");

> And that's it! A one-line solution.


NOW it's all Perfect!

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= StrReplace(st.Ticker, "BIT:", "IT_");
}

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

My problem was only in the prefix (first n-chars) delimited with "_" or ":" 
or other special chars.



> But if you are concerned that "TO:" might also occur elsewhere in the 
> string, then StrReplace won't do it, because it replaces all occurrences, 
> not just the first, in which case you'll need to do something like:....

other part of your script (string manipulation) will be useful to me in the 
futures.

THANKS FOR YOUR HELP!!! :)
[I'm sure that I contact you again in the future for other little help about 
scripting :)]

Have a good day!

[toc] | [prev] | [next] | [standalone]


#7009

FromBartC <bc@freeuk.com>
Date2016-11-24 17:14 +0000
Message-ID<o1773p$jin$1@dont-email.me>
In reply to#7004
On 24/11/2016 09:33, Richard Heathfield wrote:
> On 23/11/16 21:38, Lino wrote:

> So, if your other follow-up is correct, this isn't VBScript /or/
> JavaScript, but something called AFL. Okay.

 From the AFL Scripting Host link in the page the OP linked to:

"AFL scripting host is an interface between AFL engine and 
JScript/VBScript engines (aka. Active Scripting technologies) available 
as a part of Internet Tools & Technologies platform provided by
Microsoft.

It allows you to build the formulas that are have parts in AFL code and 
parts in JScript/VBScript."

So it is perfectly clear...

-- 
Bartc

[toc] | [prev] | [next] | [standalone]


#7010

FromRichard Heathfield <rjh@cpax.org.uk>
Date2016-11-24 17:18 +0000
Message-ID<o177bo$jum$1@dont-email.me>
In reply to#7009
On 24/11/16 17:14, BartC wrote:
> On 24/11/2016 09:33, Richard Heathfield wrote:
>> On 23/11/16 21:38, Lino wrote:
>
>> So, if your other follow-up is correct, this isn't VBScript /or/
>> JavaScript, but something called AFL. Okay.
>
> From the AFL Scripting Host link in the page the OP linked to:
>
> "AFL scripting host is an interface between AFL engine and
> JScript/VBScript engines (aka. Active Scripting technologies) available
> as a part of Internet Tools & Technologies platform provided by
> Microsoft.
>
> It allows you to build the formulas that are have parts in AFL code and
> parts in JScript/VBScript."
>
> So it is perfectly clear...

Absolutely. :-)

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming


csiph-web