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


Groups > comp.programming > #6999

Re: A problem about programming

From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.programming
Subject Re: A problem about programming
Date 2016-11-23 21:01 +0000
Organization Fix this later
Message-ID <o1500m$m4q$1@dont-email.me> (permalink)
References <mn.bc7d7e0bef53dd75.142705@Kiss-the-Sphinx>

Show all headers | View raw


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

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web