dbTalk Databases Forums  

Re: A new twist on the last problem (D3/NT)

comp.databases.pick comp.databases.pick


Discuss Re: A new twist on the last problem (D3/NT) in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
johnmarshall@xtra.co.nz
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 04:46 AM






Mike

thanks for the feedback - I thought it might come down to this as I
suspected that what I was wanting was a bit too arcane for a "standard"
synonym. Most of the synonyms I have which call up subroutines have
been to do relatively mundane things like sum up multivalues in another
file. I've had a few written for me many years back and cloned the
rest, but I'm certainly no dab hand at manipulating strings, so any
code snippets appreciated.

John


Mike Preece wrote:
Quote:
I think you'll have to call a subroutine. Put a "CALL MYSUB" in line 8
and write, compile and catalog MYSUB subroutine. It will have a single
argument, in which you pass back the data to be used in the "synonym".
Look in the ref man for ACCESS. You can access each item by using
ACCESS(3) - as in ACCESS(3)<9> or ACCESS(3)<2,5> etc.

The are many examples in here - just google cdp. You can do anything
you want with a CALL from a dictionary. I'm fairly sure that, once you
have mastered this, we'll see fewer requests like this. Let's know how
you get on. Do you need help with the PickBasic code to extract the
leading alpha chars?




Reply With Quote
  #2  
Old   
Bruce Nichol
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 04:48 AM






On 29 Aug 2006 02:00:14 -0700, "johnmarshall (AT) xtra (DOT) co.nz"
<johnmarshall (AT) xtra (DOT) co.nz> wrote:

Quote:
Folks
my posting a few weeks back revolved around getting the front numeric
characters of a stream of record IDs like the following:

R123
R12345
RC12
RC123
RC12345
S12
SV123456
SVX679101
SVX123

and the solution kindly proposed by a helpful poster was a synonym like
the one below called TYPE

001 S
002 0
003 TYPE
004
005
006
007
008 MCA
009 L
010 6

This synonym gave me all the alphas in the record ID so for the above
data I got 1 to 3 alpha characters, which was great as it allowed me to
seperate the data for reporting purposes, as the leading alphas
indicated the type of job (Production, repair, R&D, marketing etc etc)

All was going well until today, when horrors, I noticed that some users
had also been raising job numbers in the form R123A RC1234C SZY45T
etc, so that my TYPE synonym stopped working the way I wanted as it
now returned results like RA, RCC, SZYT for the data whereas I just
wanted just the first alpha part before the numeric, ie R, RC, SZY.

Is their any simple tweak that I can do to my synonym to get just those
pesky leading alpha characters? Note that the number of leading alphas
and the following numerics can vary, but the end alpha (after the
numeric) if present at all, is only ever 1 character.
Oh, yeah? Mate, if you believe that, then I've got a bridge in
Sydney that's surplus to requirements, and you can have it for.....

Being the probable that gave you the original answer, I must declare
that THIS is about the time I'd leap out into a subroutine and cover
the bases now, and leave the way open to cover any other unforeseen
contingencies....

Being Vanilla Pick, look at CALL....

And in the CALLed subroutine, I'd just start with a heap of CASE
statements:

X = ''
BEGIN CASE
CASE THIS.ID MATCHES "1A0A1N0N"; X = THIS.ID.
CASE THIS.ID MATCHES "1A0A1N0N1A"; X = THIS.ID[1,LEN(THIS.ID)-1]
....
....
END CASE
RETURN

and have the MCA conversion in attr 7 of the DICT item as a proper
"conversion". Over time, as users discover more tricks to thwart
your best endeavours, you can just add to the subroutine with more
CASE statements....

I appreciate that this is more than a gentle tweak to a DICT item, but
sooner or later you're going to have to do it..... May as well do it
now, and save the bandwidth for every other possibility that *IS*
going to crop up....

HTH

Regards,

Bruce Nichol
Talon Computer Services
ALBURY NSW Australia

http://www.taloncs.com.au

If it ain't broke, fix it until it is....


Reply With Quote
  #3  
Old   
Mark Brown
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 08:40 AM



subroutine extract.alpha(fld)
fx = ''
for i = 1 to len(fld)
if alpha(fld[i,1]) then fx := fld[i,1] else exit
next i
fld = fx
return


<johnmarshall (AT) xtra (DOT) co.nz> wrote

Quote:
Mike

thanks for the feedback - I thought it might come down to this as I
suspected that what I was wanting was a bit too arcane for a "standard"
synonym. Most of the synonyms I have which call up subroutines have
been to do relatively mundane things like sum up multivalues in another
file. I've had a few written for me many years back and cloned the
rest, but I'm certainly no dab hand at manipulating strings, so any
code snippets appreciated.



Reply With Quote
  #4  
Old   
Tom deL
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 10:23 AM



Hi Brian,

Quote:
1. Update data entry programs to prohibit this type of job number!

2. Educate users so that they don't use this sort of job number!

3. The practical way seeing these items already exist - write a basic
subroutine to parse the ID and return only the leading alpha characters.
You will be able to call the subroutine from a dictionary item (sorry
- I don't know the format for D3 - possibly a CALLX - someone else will
help you there).

But seriously - you should be investigating point 1 above so that ID's
have a standard format.
Amen.

"The great thing about PICK is the fact that with it, one can do
anything ... The horrible thing about PICK is the fact that with it,
one can do anything."
-TED



Reply With Quote
  #5  
Old   
dzigray
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 04:02 PM




johnmarshall (AT) xtra (DOT) co.nz wrote:

Quote:
Is their any simple tweak that I can do to my synonym to get just those
pesky leading alpha characters? Note that the number of leading alphas
and the following numerics can vary, but the end alpha (after the
numeric) if present at all, is only ever 1 character.
assuming you have at least one leading alpha... the following will
work:

f1;(mca);p;p;(l0);1;_;c1;_;[];=;JT end;1;p;(l0);c1;_;c1;-;[];(mca);~end



Reply With Quote
  #6  
Old   
dzigray
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 04:17 PM



actually... i could have eliminated a step... try:

f1;(mca);p;p;(L0);1;_;c1;_;[];=;JT end;p;(L0);c1;_;c1;-;[];(mca);~end


Reply With Quote
  #7  
Old   
Mark Brown
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 04:49 PM



"dzigray" <google (AT) bridge2 (DOT) com> wrote

Quote:
actually... i could have eliminated a step... try:

f1;(mca);p;p;(L0);1;_;c1;_;[];=;JT end;p;(L0);c1;_;c1;-;[];(mca);~end

Dave,

Yikes! Isn't this exactly why we went to called subroutines.

The correlative makes perfect sense if you're familiar with the more
esoteric functions (L0 gives length and JT 'jump true') but what's an
average guy supposed to do?

Good to hear from you after all these years. I still tell the story of how
you and I totally re-designed the spooler one afternoon. You were a joy to
work with.

Mark Brown




Reply With Quote
  #8  
Old   
Mike Preece
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 06:01 PM




dzigray wrote:
Quote:
actually... i could have eliminated a step... try:

f1;(mca);p;p;(L0);1;_;c1;_;[];=;JT end;p;(L0);c1;_;c1;-;[];(mca);~end
DON'T DO THIS!!!

Use a Basic subroutine instead - or a *simple* f-correlative if that
makes sense. This doesn't. It's clever - but stupid at the same time.
These things are a nightmare to deal with. It is SO easy to make a
mistake - as Dave has done. You concentrate so much on the structure of
the correlative and what is in each of up to seven stack positions,
that you often lose sight of things like the fact that you're working
on attribute 1 instead of the id (attribute 0).

Mike.



Reply With Quote
  #9  
Old   
dzigray
 
Posts: n/a

Default Re: A new twist on the last problem (D3/NT) - 08-29-2006 , 06:26 PM



Quote:
It is SO easy to make a mistake - as Dave has done.
No mistake! <wink

FYI... *both* versions will work (the latter was simply an optimization
in reusing an intermediate value on the stack vs. regrabbing the
original one.)

John, apart from his attitude, I agree with Mike; if you're even
remotely after "maintainability"... a BASIC subroutine call is the best
solution here -- especially as you may uncover yet another constraint
in your logic that has to be programmed for, so you will be far ahead
of the game going that route.

....otherwise, if you simply want a one-off cut/paste solution that will
work based upon the discussed constraints...

(Mike, mellow! A simple F-correlative doesn't work here -- unless of
course you're holding back on us??? That was part of the presented
challenge/fun for the thread participants...)

Dave



Reply With Quote
  #10  
Old   
Frank Winans
 
Posts: n/a

Default sub to return leading letters of alphanum. string - 08-29-2006 , 07:03 PM



Subroutine to return leading letter(s) of a mixed letter/number string

Mark Brown wrote
Quote:
subroutine extract.alpha(fld)
fx = ''
for i = 1 to len(fld)
if alpha(fld[i,1]) then fx := fld[i,1] else exit
next i
fld = fx
return
Which is correct and efficient, but I find keywords like
CONVERT and FIELD more clear than FOR loops...

subroutine extract.alpha(fld)
convert '0123456789' to space(10) in fld
fld = field(fld,space(1),1)
return





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.