Loading ...
Sorry, an error occurred while loading the content.

[Clip] Re: regular expression q

Expand Messages
  • Michael Gerholdt
    ... But ^LLine worked a little. I switched between a couple different formats, clicked on replace all; it would take two at a time, I d click again, two more
    Message 1 of 23 , Nov 4, 1999
    • 0 Attachment
      > "^Line" will not find the word Line at the beginning of a line because ^L
      > is seen as a token - even in regular expressions - for a line feed

      But ^LLine worked a little. I switched between a couple different formats,
      clicked on replace all; it would take two at a time, I'd click again, two
      more were gone, etc.

      kind of strange!

      Thanks,
      --Michael Gerholdt
    • Larry Thomas
      Hi Michael, ... Not so strange. The line feed character is part of the cr/lf pair that ends each line so that ^LLine would find it at the beginning of a line.
      Message 2 of 23 , Nov 4, 1999
      • 0 Attachment
        Hi Michael,

        At 03:44 PM 11/4/1999 -0500, you wrote:
        >
        >
        >> "^Line" will not find the word Line at the beginning of a line because ^L
        >> is seen as a token - even in regular expressions - for a line feed
        >
        >But ^LLine worked a little. I switched between a couple different formats,
        >clicked on replace all; it would take two at a time, I'd click again, two
        >more were gone, etc.
        >
        >kind of strange!

        Not so strange. The line feed character is part of the cr/lf pair that
        ends each line so that ^LLine would find it at the beginning of a line.
        The problem here is that you do not want to remove the line feed character,
        just the word "Line". The clip below should remove all of the items as you
        described them.

        ^!Replace "^[L]ine [0-9]*[0-9]" >> "" WASHR
        ^!IfError Exit Else Skip_-1

        The clip will keep looping back until the Replace command fails because it
        does not find any more occurrences. I used H at the end so that you could
        limit your replacement to a selection if you wish.

        Regards,

        Larry
        larryt@...
      • Michael Gerholdt
        Larry, the first thing that happens is a pop up warning of improper syntax. Then click on OK and the clip runs with precisely the desired results. ^!Replace
        Message 3 of 23 , Nov 4, 1999
        • 0 Attachment
          Larry,

          the first thing that happens is a pop up warning of improper syntax. Then
          click on OK and the clip runs with precisely the desired results.

          ^!Replace "^[L]ine [0-9]*[0-9]: " >> "" WASHR
          ^!IfError Exit Else Skip_-1

          is what I used to get rid of the colon and a few spaces after it on each
          line

          Thanks,
          --Michael Gerholdt


          > The clip below should remove all of the items as you
          > described them.
          >
          > ^!Replace "^[L]ine [0-9]*[0-9]" >> "" WASHR
          > ^!IfError Exit Else Skip_-1
        • Jody
          Hi Michael, ... I see Larry has helped already, but if you are in Pro perhaps this might help also. From Help under Line-feed: The following are not available
          Message 4 of 23 , Nov 4, 1999
          • 0 Attachment
            Hi Michael,

            >> "^Line" will not find the word Line at the beginning of a line
            >> because ^L is seen as a token - even in regular expressions -
            >> for a line feed
            >
            > But ^LLine worked a little. I switched between a couple
            > different formats, clicked on replace all; it would take two at
            > a time, I'd click again, two more were gone, etc.

            I see Larry has helped already, but if you are in Pro perhaps
            this might help also. From Help under Line-feed:

            The following are not available in NoteTab Pro:

            ^C = Carriage-return ($0D)
            ^L = Line-feed ($0A)

            Happy Clip'n!
            Jody

            http://www.sureword.com/notetab

            The NoteTab Clip List...
            mailto:Ntb-Clips-Subscribe@...
            mailto:Ntb-Clips-UnSubscribe@...
          • Kay Roath
            11/04/1999 1:51 PM Jody wrote ... Maybe that only applies to the find/replace dialogs. They do work in clips in Pro.
            Message 5 of 23 , Nov 4, 1999
            • 0 Attachment
              11/04/1999 1:51 PM Jody wrote
              > The following are not available in NoteTab Pro:
              > ^C = Carriage-return ($0D)
              > ^L = Line-feed ($0A)

              Maybe that only applies to the find/replace dialogs. They
              do work in clips in Pro.

              --- Grandma Kay ---
            • Larry Thomas
              Hi Michael, ... I have given this clip a better look. Regular expressions are more complicated than I thought and some of these things are causing problems
              Message 6 of 23 , Nov 6, 1999
              • 0 Attachment
                Hi Michael,

                At 04:27 PM 11/4/1999 -0500, you wrote:
                >Larry,
                >
                >the first thing that happens is a pop up warning of improper syntax. Then
                >click on OK and the clip runs with precisely the desired results.
                >
                >^!Replace "^[L]ine [0-9]*[0-9]: " >> "" WASHR
                >^!IfError Exit Else Skip_-1
                >
                >is what I used to get rid of the colon and a few spaces after it on each
                >line
                >
                >Thanks,
                >--Michael Gerholdt

                I have given this clip a better look. Regular expressions are more
                complicated than I thought and some of these things are causing problems
                that do not occur in normal search and replace operations. The syntax
                error that you saw appears to have been caused by the ^[L] expression. I
                modified this to ^\L and it worked without an error. It did work the other
                way as you described but this way it also worked but without the syntax
                error message. I cannot say why the error message. There was no such
                message when the expression was used in a dialog box from the toolbar s&r
                but the clip does cause such a message. Possibly there is a conflict
                between ^[L] searching for a "[" at the beginning of a line and searching
                for a "L" at the beginning of a line. In any event, the clip below works.

                ^!Replace "^\Line [0-9]*[0-9]:" >> "" WSR
                ^!IfError Exit Else Skip_-1

                On the options, you cannot get the H option to work when a clip is looping
                like the above. The first replace unselects the selection and the
                remaining loops do the whole document. If you want to just do a selection,
                then you must write a more complicated clip using code to copy/paste your
                selection to a temporary doc and do the replace there and then copy the
                result, close discard the temp doc, return to the original doc and
                paste/replace the selected text there.

                Regards,

                Larry
                larryt@...
              • Michael Gerholdt
                Larry, I appreciate your careful look at this. It will help me be more self-sufficient in the future. Great bunch folks here who are willing to help. Thanks,
                Message 7 of 23 , Nov 8, 1999
                • 0 Attachment
                  Larry,

                  I appreciate your careful look at this. It will help me be more
                  self-sufficient in the future.

                  Great bunch folks here who are willing to help.

                  Thanks,
                  --Michael Gerholdt

                  Subject: [Clip] Re: regular expression q
                • Harry Pollard
                  Jody, Please remove me from these addresses: george@4link.net henrygeorge@mediaone.net Thanks! Harry Pollard ... From: Jody To:
                  Message 8 of 23 , Nov 22, 1999
                  • 0 Attachment
                    Jody,

                    Please remove me from these addresses:

                    george@...

                    henrygeorge@...

                    Thanks!

                    Harry Pollard

                    _____________________________________________________

                    ----- Original Message -----
                    From: "Jody" <KJB1611@...>
                    To: <ntb-clips@egroups.com>
                    Sent: Thursday, November 04, 1999 1:51 PM
                    Subject: [Clip] Re: regular expression q


                    > Hi Michael,
                    >
                    > >> "^Line" will not find the word Line at the beginning of a line
                    > >> because ^L is seen as a token - even in regular expressions -
                    > >> for a line feed
                    > >
                    > > But ^LLine worked a little. I switched between a couple
                    > > different formats, clicked on replace all; it would take two at
                    > > a time, I'd click again, two more were gone, etc.
                    >
                    > I see Larry has helped already, but if you are in Pro perhaps
                    > this might help also. From Help under Line-feed:
                    >
                    > The following are not available in NoteTab Pro:
                    >
                    > ^C = Carriage-return ($0D)
                    > ^L = Line-feed ($0A)
                    >
                    > Happy Clip'n!
                    > Jody
                    >
                    > http://www.sureword.com/notetab
                    >
                    > The NoteTab Clip List...
                    > mailto:Ntb-Clips-Subscribe@...
                    > mailto:Ntb-Clips-UnSubscribe@...
                    >
                    > ------------------------------------------------------------------------
                    > -- Check out your eGroup's private Chat room
                    > -- http://www.egroups.com/ChatPage?listName=ntb-clips&m=1
                    >
                    >
                  • Jody
                    Hi Harry and All, At the bottom of most of my posts is the information on how to unsubscribe. The only catch is you have to unsubscribe with a post that uses
                    Message 9 of 23 , Nov 22, 1999
                    • 0 Attachment
                      Hi Harry and All,

                      At the bottom of most of my posts is the information on how to
                      unsubscribe. The only catch is you have to unsubscribe with a
                      post that uses the address you subscribed with. Be sure to set
                      your Reply to/Return address to that in your mail program if need
                      be.

                      > Please remove me from these addresses:
                      > henrygeorge@...

                      Done, the other was not subscribed.

                      Happy Clip'n!
                      Jody

                      http://www.sureword.com/notetab

                      The NoteTab Clip List...
                      mailto:Ntb-Clips-Subscribe@...
                      mailto:Ntb-Clips-UnSubscribe@...
                    • Manuel
                      Hi, All.. Another question?, I would like a clip such as: Give me a randozime number between intervals numbers But I don t have idea that to do it Regards. --
                      Message 10 of 23 , Nov 25, 1999
                      • 0 Attachment
                        Hi, All..

                        Another question?,

                        I would like a clip such as:

                        Give me a randozime number between intervals numbers
                        But I don't have idea that to do it

                        Regards.
                        --
                        Manuel, from Spain
                        manumail@...
                      • Eb Guenther
                        Hi Manuel, ... ^!Set %LowLimit%=5; %HiLimit%=12 ^!Set %range%= ^$Calc(^%HiLimit%-^%LowLimit%)$ ^!Set %rNum%= ^$Calc(INT(RANDOM(1)*^%range%)+^%LowLimit%+1)$
                        Message 11 of 23 , Nov 25, 1999
                        • 0 Attachment
                          Hi Manuel,

                          Below is a solution for INTEGER random numbers:

                          >Give me a randozime number between intervals numbers
                          >But I don't have idea that to do it


                          ^!Set %LowLimit%=5; %HiLimit%=12
                          ^!Set %range%="^$Calc(^%HiLimit%-^%LowLimit%)$"
                          ^!Set %rNum%="^$Calc(INT(RANDOM(1)*^%range%)+^%LowLimit%+1)$"
                          ^!Continue Your random number is "^%rNum%"
                        • Manuel
                          MANUEL give me a randozime number between intervals numbers But I don t have idea that to do it EB ... MANUEL Ok, it s work ok. But another question... It is
                          Message 12 of 23 , Nov 27, 1999
                          • 0 Attachment
                            MANUEL
                            give me a randozime number between intervals numbers
                            But I don't have idea that to do it

                            EB
                            >^!Set %LowLimit%=5; %HiLimit%=12
                            >^!Set %range%="^$Calc(^%HiLimit%-^%LowLimit%)$"
                            >^!Set %rNum%="^$Calc(INT(RANDOM(1)*^%range%)+^%LowLimit%+1)$"
                            >^!Continue Your random number is "^%rNum%"

                            MANUEL
                            Ok, it's work ok. But another question...
                            It is possible that remember one number that I use, and then in other
                            time don't give the same.

                            By example, I excute the clip and it's give me 232
                            but I don't the number 232 in other time.

                            Thanks.
                            --
                            Manuel, from Spain
                            manumail@...
                          • Eb Guenther
                            Manuel, ... Yes, but NOT within the random number function. You re talking about a fairly complex problem. One solution which doesn t generate used up numbers
                            Message 13 of 23 , Nov 27, 1999
                            • 0 Attachment
                              Manuel,
                              >>^!Set %LowLimit%=5; %HiLimit%=12
                              >>^!Set %range%="^$Calc(^%HiLimit%-^%LowLimit%)$"
                              >>^!Set %rNum%="^$Calc(INT(RANDOM(1)*^%range%)+^%LowLimit%+1)$"
                              >>^!Continue Your random number is "^%rNum%"
                              >
                              >MANUEL
                              >Ok, it's work ok. But another question...
                              >It is possible that remember one number that I use, and then in other
                              >time don't give the same.
                              >
                              >By example, I excute the clip and it's give me 232
                              >but I don't the number 232 in other time.

                              Yes, but NOT within the random number function.

                              You're talking about a fairly complex problem.
                              One solution which doesn't generate used up numbers
                              is to keep the available numbers in a database.

                              1. set up the random number generator to return
                              the INDEX to a database record.
                              You'll be generating an INDEX in range of 1..HiLimit,
                              so you don't need a separate Range variable.
                              2. Let your clip return the CONTENT of the record
                              at INDEX,
                              3. DELETE that record (the number you have used up).
                              4. DECREMENT HiLimit, to allow for the smaller database.


                              Now the database no longer contains the number you have
                              just generated, and the limit reflects the smaller database.


                              Good luck, this is a bigger problem than it looks on the surface.


                              Eb
                            • Jody
                              Hi Manuel, ... I think you want to have it do more than below, but it will not let you pick the same number twice in a row. If you want it to never let you
                              Message 14 of 23 , Nov 27, 1999
                              • 0 Attachment
                                Hi Manuel,

                                > Ok, it's work ok. But another question... It is possible that
                                > remember one number that I use, and then in other time don't
                                > give the same.

                                I think you want to have it do more than below, but it will not
                                let you pick the same number twice in a row. If you want it to
                                never let you pick the same number twice it would require
                                something more complicated.

                                H=Eb's Revisted
                                :Loop
                                ^!Set %LowLimit%=5; %HiLimit%=12
                                ^!Set %range%="^$Calc(^%HiLimit%-^%LowLimit%)$"
                                ^!Set %rNum%="^$Calc(INT(RANDOM(1)*^%range%)+^%LowLimit%+1)$"
                                ^!If ^%p_LastNum% = ^%rNum% Loop
                                ^!Set %p_LastNum%=^%rNum%
                                ^!Skip Your random number is "^%rNum%" Do another?
                                ^!Goto End
                                ^!Goto Loop

                                Bye for now,
                                Jody Adair
                                Prov. 3:5-7; 4:23

                                http://www.sureword.com/sojourner
                                http://www.sureword.com/kjb1611
                                http://www.sureword.com/notetab
                              • Jody
                                Hi Manuel, Can one of you Cliperts explain to me why my check to see if a number was used appears to randomly decide if it was used or not? I added comments
                                Message 15 of 23 , Nov 27, 1999
                                • 0 Attachment
                                  Hi Manuel,

                                  Can one of you Cliperts explain to me why my check to see if
                                  a number was used appears to randomly decide if it was used or
                                  not? I added comments to the way I think it should be working.

                                  H=Randomly-Random
                                  ^!ClearVariables

                                  :Restart
                                  ^!ClearVariable %List%

                                  ; sets up the array
                                  ^!SetDelimiter ^%nl%
                                  ^!SetArray %List%=^%RanNum%
                                  ^!Set %Count%=^%List0%
                                  ^!Set %Index%=0
                                  ; random number between 0-3 for simplicity
                                  ^!Set %RanNum%=^$Calc(rnd(3);0)$

                                  :Loop
                                  ; This is the check to see if the number was used. I looks
                                  ; like to me that it would loop through the list in the array
                                  ; and if the current random number is found goes to New. If
                                  ; all the list did not match, then skips to append the not
                                  ; found number to the total list %RanNumT%.
                                  ^!Inc %Index%
                                  ^!If ^%Index% > ^%Count% Skip
                                  ^!If ^%List^%Index%% = ^%RanNum% New else Loop
                                  ^!Append %RanNumT%=^%RanNum%

                                  ; adds delimiter so sorting can be done removing dups.
                                  ^!Append %RanNumT%=^%nl%
                                  ^!Skip Your random number is: ^%RanNum% Do another?
                                  ^!Goto End
                                  ^!Goto Restart

                                  :New
                                  ; resets RanNum to new list
                                  ^!Set %RanNum%=^%RanNumT%
                                  ^!Set %RanNum%=^$StrSort("^%RanNum%";True;True;True)$
                                  ; Now, why doesn't it come down here everytime it sees a
                                  ; match (???) instead of just some of the time? Once the
                                  ; list is filled "0-4" then it should come here everytime -
                                  ; at least that is what I'm trying to make it do.
                                  ^!Info [L]Current: ^%List^%Index%%^pList:^p^%RanNum%
                                  ^!Goto Restart
                                • Manuel
                                  JODY ... MANUEL Of Course¡. I use link such as [*234] that opens a file Jody-234.txt My idea is to put a numer a each file, such as registry. Then I can find
                                  Message 16 of 23 , Nov 28, 1999
                                  • 0 Attachment
                                    JODY
                                    >Can one of you Cliperts explain to me why my check to see if
                                    >a number was used appears to randomly decide if it was used or
                                    >not?

                                    MANUEL
                                    Of Course¡.

                                    I use link such as [*234] that opens a file Jody-234.txt

                                    My idea is to put a numer a each file, such as registry. Then I can
                                    find a file by the number. And the best It's that I can rename the
                                    file in other momento, but the importante is the name, is similar to
                                    client code.

                                    I can rename Jody-234 to Jody Adair-234.txt

                                    Jody is for me -234

                                    I use it for made manuales. I make a clip to give a secuencial number
                                    but I thought was interesting the pc give a randomize number.

                                    Here it's my clip (I'm a novate :)
                                    numero-registro
                                    ;abre el fichero numero-de-registro.txt de Mis Documentos
                                    ^!OPEN "c:\Mis Documentos\numero-de-registro.txt"
                                    ;va al final de la linea y añade +1 para sumar
                                    ^!Keyboard END #+1 = #
                                    ;Selecciona toda la linea y ejecuta la suma
                                    ^!Keyboard SHIFT+HOME CTRL+E
                                    ;Selecciona el resultado
                                    ^!Keyboard SHIFTDOWN CTRL+LEFT
                                    ;Copia el resultado a memoria
                                    ^!Keyboard CTRL+C
                                    ;Muetras en pantalla el numero en Info
                                    ^!Info: El Número de registro es: ** ^$GetClipboard$ **
                                    ;Selecciona todo el texto
                                    ^!Toolbar Select All
                                    ;Pega el numero de registro
                                    ^!Keyboard CTRL+V
                                    ;Graba el documento con el nuevo numero y graba
                                    ^!Save
                                    ;Cierra el documento
                                    ^!Toolbar Close Document

                                    END OF THE CLIP

                                    Notetab is wonderful I use from two years ago. I use it all day.

                                    Another example:
                                    LIBRERIA DE CLIPS
                                    -----------------
                                    1. Da un número al azar [001*] * 26/11/99
                                    2. Copiar path cabecera [002*] * 27/11/99
                                    3. Contadores de tiempo [003*] * 27/11/99

                                    I have all files in one directory...

                                    --
                                    Manuel, from Spain
                                    manumail@...
                                  • Eb Guenther
                                    ... Hi Jody, There are a couple of things. First, you need to exclude 0 in your random function (add 1 to result): ^!Set %RanNum%=^$Calc(rnd(3)+1;0)$ Second,
                                    Message 17 of 23 , Nov 28, 1999
                                    • 0 Attachment
                                      >Can one of you Cliperts explain to me why my check to see if
                                      >a number was used appears to randomly decide if it was used or
                                      >not?


                                      Hi Jody,

                                      There are a couple of things.

                                      First, you need to exclude "0" in your random
                                      function (add 1 to result):

                                      ^!Set %RanNum%=^$Calc(rnd(3)+1;0)$

                                      Second, you should work with Integers, rather than
                                      implied integers.

                                      Third, your reassignment of the previous results to
                                      a brand new list (on restart) does not make sense.

                                      I don't know what your goals are, but suppose you
                                      need to use a longer range of numbers, say 1000.

                                      Every used number you add to the array adds to the
                                      search time, making th eloop slower as your used
                                      list gets larger.


                                      The indirect approach I suggested to Manuel is MUCH
                                      faster with large pools of numbers, because it never
                                      has to search at all! It only has to test for the
                                      begin or end of the array, to delete the appropriate
                                      delimiter.

                                      In addition to speed gains, that method does not limit
                                      you to numbers. You can use strings, dates, filepaths,
                                      anyhting you can put into an array!

                                      Furthermore, you can have duplicates, selectively, yet!
                                      For example, you could put a deck of cards in an array.
                                      You could even stack the deck with twice as many Aces as
                                      Kings, etc.

                                      See my addendum for a working version (NTP 4.6),
                                      which lends itself to collecting the random data
                                      by wizard, or import from a file, and so on.

                                      Cheers,


                                      Eb

                                      Here is a stand-alone, non-repeating, random DATA
                                      generator clip:

                                      ==== Begin clip ====
                                      H="WorkingRandomMemory"

                                      ; _____________ long line begin _____________
                                      ^!Info [L]@ R a n d o M e m o r y^%NL%¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯^%NL%by Eb
                                      Guenther <ntp@...>^%NL%Random number generator with
                                      Memory^%NL^%NL%Run from an empty document!^%NL%
                                      ; ¯¯¯¯¯¯¯¯¯¯¯¯¯ long line end ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

                                      ^!SetArray %List%=Ace ;Ace ;King;Queen;Jack
                                      ^!Set %MaxIndex%=^%List0%

                                      :Again
                                      ^!Set %Index%=^$Calc(Int(rnd(^%MaxIndex%)+1))$
                                      ^!InsertText ^%List^%Index%%^%TAB%from (^%List%)^%NL%
                                      ^!Set %List^%Index%%=
                                      ^!If ^%Index%=1 FirstEl
                                      ^!If ^%Index%=^%MaxIndex% LastEl Else AnyOther
                                      :LastEl
                                      ^!Dec %List0%
                                      ^!Goto Remaining
                                      :FirstEl
                                      ^!SetArray %List%=^$StrDelete("^%List%";1;1)$
                                      ^!Goto Remaining
                                      :AnyOther
                                      ^!SetArray %List%=^$StrReplace(";;";";";"^%List%";N;N)$
                                      :Remaining
                                      ^!Dec %MaxIndex%
                                      ^!If ^%List0%>0 Again
                                      ^!InsertText ^%NL%

                                      ==== end of clip ====
                                    • Jody
                                      Hi Eb, ... My reasoning was to add the number used to it so that it would not be used again. ... a much better method sho nuff. I was in a learning process
                                      Message 18 of 23 , Nov 28, 1999
                                      • 0 Attachment
                                        Hi Eb,

                                        > Third, your reassignment of the previous results to a brand new
                                        > list (on restart) does not make sense.

                                        My reasoning was to add the number used to it so that it would
                                        not be used again.

                                        > The indirect approach I suggested to Manuel is

                                        a much better method sho'nuff. I was in a learning process
                                        myself. ;) ........and still am.

                                        Thanks for the help, but I still can't get it to recognize a used
                                        number. Ernie had pointed out to me that I was using
                                        SetDelimiter instead of SetListDelimter - oops! That seemed to
                                        help, but not a fix. Also, the RND between 1-3 returns a 4 as
                                        well and an occaional 9. <g>

                                        c ya,
                                        Jody

                                        The whole world doth err save you
                                        and me and even thou doest err some!

                                        http://www.sureword.com/sojourner
                                        http://www.sureword.com/mm
                                      • Claes Gauffin
                                        Hello Eb, Jody ... This is truly beautyful! Such an elegant solution to a problem which, as already remarked, is by no means trivial. One of the cases where
                                        Message 19 of 23 , Dec 1, 1999
                                        • 0 Attachment
                                          Hello Eb, Jody

                                          At 17:39 1999-11-28 -0600, you wrote:


                                          >
                                          >Here is a stand-alone, non-repeating, random DATA
                                          >generator clip:
                                          >

                                          This is truly beautyful! Such an elegant solution to a problem which,
                                          as already remarked, is by no means trivial. One of the cases where
                                          the manual action (drawing lots without replacement) is much simpler
                                          than the computerized simulation.

                                          Once again being a meddling busybody, I couldn't keep my sticky fingers
                                          away. The following only reduces the lines of code somewhat and adds a
                                          rudimentary input interface.

                                          Regards /Claes

                                          ^!ClearVariable %string%
                                          ^!ClearVariable %result%
                                          ^!SetListDelimiter ^p
                                          ^!Set %max%=^?[Maximum, if you want to pull numbers 1 - max=0]
                                          ^!set %items%=^?[else specify any items, separated with blanks]
                                          ^!If ^%max%=0 items
                                          ^!set %n%=1
                                          ^!set %string%=1

                                          :numbers
                                          ^!Inc %n%
                                          ^!if ^%n%>^%max% stringdone
                                          ^!append %string%=^%NL%^%n%
                                          ^!goto numbers

                                          :items
                                          ^!Set %string%=^$StrReplace(" ";"^p";"^%items%";True;False)$

                                          :stringdone
                                          ^!SetArray %List%=^%string%
                                          ^!Set %MaxIndex%=^%List0%

                                          :Again
                                          ^!Set %Index%=^$Calc(Int(rnd(^%MaxIndex%)+1))$
                                          ^!Append %result%=^%List^%Index%%^%NL%
                                          ^!Set %List^%Index%%=^%SPACE%
                                          ^!Set %List%=^$StrSort("^%List%";N;Y;N)$
                                          ^!SetArray %List%=^$StrDelete("^%List%";1;3)$
                                          ^!Dec %MaxIndex%
                                          ^!If ^%List0%>0 Again
                                          ^!InsertText ^%result%
                                        • Claes Gauffin
                                          Hello Eb, Jody It is a kind of natural law, that you are never as clear-sighted as the moment after you submit something. I realised the obvious point that the
                                          Message 20 of 23 , Dec 1, 1999
                                          • 0 Attachment
                                            Hello Eb, Jody

                                            It is a kind of natural law, that you are never as clear-sighted as the
                                            moment after you submit something.

                                            I realised the obvious point that the number of lines of code naturally is
                                            less important than the speed of the result. And Eb's original version is
                                            significantly faster than my variant, if you accumulate the result in a
                                            variable, rather than continously output it.

                                            Sorry about my butting in, Eb.

                                            Regards /Claes
                                          • Eb Guenther
                                            Hi Claes, ... I m not offended by someone modifying my code, especially if they then compliment me on my original . And if you look below, your version
                                            Message 21 of 23 , Dec 1, 1999
                                            • 0 Attachment
                                              Hi Claes,

                                              >It is a kind of natural law, that you are never as clear-sighted as the
                                              >moment after you submit something.
                                              >
                                              >I realised the obvious point that the number of lines of code naturally is
                                              >less important than the speed of the result. And Eb's original version is
                                              >significantly faster than my variant, if you accumulate the result in a
                                              >variable, rather than continously output it.
                                              >
                                              >Sorry about my butting in, Eb.

                                              I'm not offended by someone modifying my code, especially
                                              if they then compliment me on my original <grin>.
                                              And if you look below, your version gave me THE clew on
                                              how to get rid of those pesky 5 extra GOTOs -- that
                                              SPACE you put in place of the used element!

                                              Tack så mycket.

                                              So I changed the URDG (unique random data gen) as follows:

                                              1. End the data array with an empty element, i.e. an ";",
                                              just to make each element identical, if set to SPACE.
                                              2. Replace the hit element with a TOKEN (you used SPACE)
                                              (I tried a space, but got funny results because my
                                              data contained spaces. Then decided that this step
                                              required a UNIQUE token -- "#" in the sample code).
                                              3. The array now has a consistent pattern "#;" to delete
                                              in any element position.


                                              ;----- Start self-contained clip -----
                                              H="YARYDG"

                                              ;Yet Another Random Unique Data Generator
                                              ;Ver 11:22 12/1/99, Eb Guenther <ntp@...>

                                              ;Replace the first line with your preferred method
                                              ;of data Input (empty element at end!)
                                              ^!SetArray %List%=A;K;Q;J;T;9;8;7;6;5;4;3;2;
                                              ^!Set %MaxIndex%=^%List0%; %result%=Seq:
                                              ^!Dec %MaxIndex%
                                              :Again
                                              ^!Set %Index%=^$Calc( Int( Random( 1 ) * ^%MaxIndex% + 1 ) )$
                                              ^!Append %Result%=^%TAB%^%List^%Index%%
                                              ^!Set %List^%Index%%=#
                                              ^!SetArray %List%=^$StrDelete("^%List%";^$StrPos("#";"^%List%";N)$;2)$
                                              ^!Dec %MaxIndex%
                                              ^!If ^%List0%>1 Again
                                              ^!InsertText ^%Result%^%NL%
                                              ;----- End self-contained clip -----

                                              On my antique PC this takes about 110 mS, about 18% faster
                                              than my previous version! Anyone with a screamer out there
                                              wanna give me an incentive to get a new PC for X-mass?
                                              Loop the clip XX times, and divide the elapsed second by XX.
                                              Do I hear 10 mS? Better?

                                              AND the clip is simpler and easier to read.


                                              Regards,


                                              Eb
                                            • Jody
                                              Hi Eb, Manuel, and Claes, ... You did a great job! Really! I think I have it the way Manuel first requested it now with some options to make it not as
                                              Message 22 of 23 , Dec 1, 1999
                                              • 0 Attachment
                                                Hi Eb, Manuel, and Claes,

                                                > I'm not offended by someone modifying my code, especially if
                                                > they then compliment me on my original <grin>.

                                                You did a great job! <g> Really! I think I have it the way
                                                Manuel first requested it now with some options to make it not as
                                                Manuel specific. ;)

                                                I have the list the script picks from in an ini file now which is
                                                made after the Setup Clip is done. This is so a year down the
                                                road the used numbers, or should I say what is left is remembered
                                                - provided Windows doesn't eat your drive. ;->

                                                When the last number is used you are told to run setup again to
                                                build a new list. There is an option to add a wrapper start and
                                                end around the number. Manuel's [#nnn] is default and no wrapper
                                                can also be used which I suppose would be most used. Leading
                                                zeros are added to smaller numbers for even alignment (no option
                                                there >:-þ~~~). I took about 12 seconds for me to generate an
                                                initial list of 6600 numbers. <vbs> There is a limit of 32kb in
                                                an ini file so once you get to that point you will get an error
                                                saying cannot write to RandNum.ini. There is an option to open
                                                that so you can easily delete it if you want.

                                                It may be viewed or copied at Snatch-A-Clip. It is all the way
                                                at the bottom unless you use the Quick Snatch. Make sure you
                                                read the first few lines if you go so you know what to do with
                                                the html popup.

                                                http://www.sureword.com/notetab/html/snatchclp.html

                                                Have fun... Back to beta testing. :)

                                                Happy Clip'n!
                                                Jody

                                                http://www.sureword.com/notetab

                                                The NoteTab Clip List...
                                                mailto:Ntb-Clips-Subscribe@...
                                                mailto:Ntb-Clips-UnSubscribe@...
                                              Your message has been successfully submitted and would be delivered to recipients shortly.