Welcome Guest
Log In | Register )
You last visited December 7, 2016, 5:34 am
All times shown are
Eastern Time (GMT-5:00)

Program language loops

Topic closed. 9 replies. Last post 7 years ago by KnuckleHead.

Page 1 of 1
PrintE-mailLink
KnuckleHead's avatar - box

United States
Member #73037
April 3, 2009
147 Posts
Offline
Posted: December 12, 2009, 4:45 pm - IP Logged

Afternoon all,

I'm trying to automate my files to automaticly enter the current draw data, but I'm now at the point that I don't understand how to create the logic loops for the language. Does anyone out there understand how to create program language loops?

Once I can see an example of how they'er desgined, I can normally figure em out and then modify them to work.

Can anyone assist? If so, I can attempt to post examples here...

Thanks ahead of time for any interest.

          The only DUMB question is the one question you DID NOT ask...

    time*treat's avatar - radar

    United States
    Member #13130
    March 30, 2005
    2171 Posts
    Offline
    Posted: December 13, 2009, 1:52 am - IP Logged

    You may get useful replies if you specify the application/language you are programming in and where you are trying to pull the draw data from. Wink

    In neo-conned Amerika, bank robs you.
    Alcohol, Tobacco, and Firearms should be the name of a convenience store, not a govnoment agency.

      KnuckleHead's avatar - box

      United States
      Member #73037
      April 3, 2009
      147 Posts
      Offline
      Posted: December 13, 2009, 3:52 pm - IP Logged

      Afternoon time*treat,

      Sorry about that, I'm using Lotus 123 script which is very simular to Excel VBA.

      I haven't been able to figure out how to construct the "loops" that tell the computer what to look for and do. Since I don't have a lot of experience in computer lanuage, my understanding of what is needed is probably incorrect.

      Below is what I have so far. (I haven't been able to figure out how to post a "screen shot" here for visual understanding along with the script, if I could I would.) I've colored the text as it appears in the script editor.

       

      Sub Pat_Map_test

          [PAT_MAP].Goto     'GoTo "Pattern Mapping" section.   
          [PAT_MAP].Select
          [A:K10].Select     'Select #1 from row #10 and copy.   
          Selection.CopyToClipboard
      'GoTo row #12 to match contents of cell A:U7 (current numbers row - cell A:U7 contains the number 9).   
           [A:E12].Select        'Cell A:E12 contains the number 1.
      '(This is where I think a loop needs to be to match the correct number.)   
           [A].MoveCellPointer $Right,1    'Cell A:F12 contains the number 2.
          [A].MoveCellPointer $Right,1    'Cell A:G12 contains the number 3.
          [A].MoveCellPointer $Right,1    'Cell A:H12 contains the number 4.
          [A].MoveCellPointer $Right,1    'Cell A:I12 contains the number 5.
          [A].MoveCellPointer $Right,1    'Cell A:J12 contains the number 6.
          [A].MoveCellPointer $Right,1    'Cell A:K12 contains the number 7.
          [A].MoveCellPointer $Right,1    'Cell A:L12 contains the number 8.
          [A].MoveCellPointer $Right,1    'Cell A:M12 contains the number 9 and matches cell A:U7 (current numbers row).
      '(Once the loop matches the correct number, drop down to the date row.)
          [A].MoveCellPointer $Down,4    'Move down to row #16 (date row).
      'This is where the script needs to determine if the cell is blank...   
      '    If blank - paste and continue with up and down moves.
      '    If not blank - change text color and ignore up and down moves.
          Selection.Paste ,,,,,,
      'This sequence of moves places the correct number into cell A:M16 (date row cell).
          [A].MoveCellPointer $Up,4
          Selection.CopyToClipboard
          [A].MoveCellPointer $Down,4
          Selection.Paste ,False,PasteData,,,,    'Change cell A:M16 contents to match cell A:U7 (current numbers row).
      End Sub 

       

      If you or anyone else can describe how to post the screen shot, it would probably help to see the sheet and the script to better understand what I'm trying to do.

      Thanks for the interest.

                The only DUMB question is the one question you DID NOT ask...

        RJOh's avatar - chipmunk
        mid-Ohio
        United States
        Member #9
        March 24, 2001
        19826 Posts
        Offline
        Posted: December 13, 2009, 5:39 pm - IP Logged

        Generally speaking a programmer can't program a computer to do a task he doesn't understand how to do himself.  First figure out what you would have to do to accomplish the task and then it will be easier to write a set of instructions for the computer to do the same.

         * you don't need to buy more tickets, just buy a winning ticket * 
           
                     Evil Looking       

          KnuckleHead's avatar - box

          United States
          Member #73037
          April 3, 2009
          147 Posts
          Offline
          Posted: December 13, 2009, 6:40 pm - IP Logged

          Evening RJOh,

          I know what I want it to do, but not how to tell it what to do. Does that make sense?

                    The only DUMB question is the one question you DID NOT ask...

            RJOh's avatar - chipmunk
            mid-Ohio
            United States
            Member #9
            March 24, 2001
            19826 Posts
            Offline
            Posted: December 13, 2009, 8:13 pm - IP Logged

            Evening RJOh,

            I know what I want it to do, but not how to tell it what to do. Does that make sense?

            Yes, but how would you do it if you only had paper and pencil.  I program using GWBasic and many times when I want to program a routine I first do it using paper and pencil recording each step (flow chart).  Once I understand what I need and what I have to do, programming it is easier.  Also explaining it to others is easier too.

             * you don't need to buy more tickets, just buy a winning ticket * 
               
                         Evil Looking       

              time*treat's avatar - radar

              United States
              Member #13130
              March 30, 2005
              2171 Posts
              Offline
              Posted: December 13, 2009, 9:12 pm - IP Logged

              Afternoon time*treat,

              Sorry about that, I'm using Lotus 123 script which is very simular to Excel VBA.

              I haven't been able to figure out how to construct the "loops" that tell the computer what to look for and do. Since I don't have a lot of experience in computer lanuage, my understanding of what is needed is probably incorrect.

              Below is what I have so far. (I haven't been able to figure out how to post a "screen shot" here for visual understanding along with the script, if I could I would.) I've colored the text as it appears in the script editor.

               

              Sub Pat_Map_test

                  [PAT_MAP].Goto     'GoTo "Pattern Mapping" section.   
                  [PAT_MAP].Select
                  [A:K10].Select     'Select #1 from row #10 and copy.   
                  Selection.CopyToClipboard
              'GoTo row #12 to match contents of cell A:U7 (current numbers row - cell A:U7 contains the number 9).   
                   [A:E12].Select        'Cell A:E12 contains the number 1.
              '(This is where I think a loop needs to be to match the correct number.)   
                   [A].MoveCellPointer $Right,1    'Cell A:F12 contains the number 2.
                  [A].MoveCellPointer $Right,1    'Cell A:G12 contains the number 3.
                  [A].MoveCellPointer $Right,1    'Cell A:H12 contains the number 4.
                  [A].MoveCellPointer $Right,1    'Cell A:I12 contains the number 5.
                  [A].MoveCellPointer $Right,1    'Cell A:J12 contains the number 6.
                  [A].MoveCellPointer $Right,1    'Cell A:K12 contains the number 7.
                  [A].MoveCellPointer $Right,1    'Cell A:L12 contains the number 8.
                  [A].MoveCellPointer $Right,1    'Cell A:M12 contains the number 9 and matches cell A:U7 (current numbers row).
              '(Once the loop matches the correct number, drop down to the date row.)
                  [A].MoveCellPointer $Down,4    'Move down to row #16 (date row).
              'This is where the script needs to determine if the cell is blank...   
              '    If blank - paste and continue with up and down moves.
              '    If not blank - change text color and ignore up and down moves.
                  Selection.Paste ,,,,,,
              'This sequence of moves places the correct number into cell A:M16 (date row cell).
                  [A].MoveCellPointer $Up,4
                  Selection.CopyToClipboard
                  [A].MoveCellPointer $Down,4
                  Selection.Paste ,False,PasteData,,,,    'Change cell A:M16 contents to match cell A:U7 (current numbers row).
              End Sub 

               

              If you or anyone else can describe how to post the screen shot, it would probably help to see the sheet and the script to better understand what I'm trying to do.

              Thanks for the interest.

              OK, you're looking for the Lotus version of a for-next loop, simply called a for loop, in Lotus.

              Do a search engine lookup of Lotus 123 macros, hit the 'lynnbob' page/link.

              At 7.4 {For}, they provide 

              {for counter-location,start-number,stop-number,step-number,starting-location}

              Bookmark/save/printout that page. Lots of other good info there.

              Also, you'll need the {If} command. It's there, too.

              In neo-conned Amerika, bank robs you.
              Alcohol, Tobacco, and Firearms should be the name of a convenience store, not a govnoment agency.

                KnuckleHead's avatar - box

                United States
                Member #73037
                April 3, 2009
                147 Posts
                Offline
                Posted: December 14, 2009, 12:57 pm - IP Logged

                Morning RJOh & time*treat,

                RJOh, as to your suggestion about paper and pencil, I comprehend that very well. I already have what I want to do figured out. Just not the "how to" in computer language. I'm lacking very badly in the computer language comprehending department. Generally, if I can't "record" what I want the program to do, I'm lost trying to figure it out.

                time*treat, great site. I had not discovered that site before. Thank you. Weeks appears to do everything in macros, and I think that Lotus has a way to convert the macros to script language. I think that what I'm looking at is some kind of a "Forall" loop that includes a "Do" command. I'm still looking thru the help files. I never thought that what I do manually would be so diffuclt to automate...

                I attempted to post the screen shot again of the sheet I'm attempting to automate, but to no avail. I don't understand what/why it won't allow the posting.

                Thank you both for the interest.

                          The only DUMB question is the one question you DID NOT ask...

                  time*treat's avatar - radar

                  United States
                  Member #13130
                  March 30, 2005
                  2171 Posts
                  Offline
                  Posted: December 17, 2009, 6:32 pm - IP Logged

                  There's plenty of free info on the web, if you prefer that over books.
                  With the possible exception of OpenOffice, I think for older languages / app versions, books are the way to go.

                  Reference books that are a few versions out-of-date can be had for way cheap. Big Smile

                  You can build a small library of older books (with plenty of still-usable info*) for less that what one of them cost when new.

                  *Loop and branching syntax are pretty much the same in version_now as they were in version_1 of whatever you use.

                  In neo-conned Amerika, bank robs you.
                  Alcohol, Tobacco, and Firearms should be the name of a convenience store, not a govnoment agency.

                    KnuckleHead's avatar - box

                    United States
                    Member #73037
                    April 3, 2009
                    147 Posts
                    Offline
                    Posted: December 23, 2009, 4:34 pm - IP Logged

                    Afternoon all,

                    For anyone who's been reading this post, below is the code that works in Lotus 123. I'm sure it could be adjusted for Excel if needed.

                    Sub CheckCell_1(TargetRange As range, MatchCell As range, CopyCell As range, rows As Long, Where As Variant)
                    'Check for a number in a range, then move up or down and insert a value
                    'or colorize. MatchCell and CopyCell must be single-cell ranges.   
                    '
                    '    Place this script by itself in the Globals section.
                    '    Place this line in the actual script to call the sub. >>> CheckCell_1 [E12..M12], [U7], [K10], 4, $Down
                    '   
                        Dim Current As Sheet, match As Long    'local variables
                        Set Current = CurrentDocument.CurrentSheet
                        match& = MatchCell.CellValue   'the comparison value
                       
                        Forall Cl In TargetRange.Cells
                            If Cl.CellValue = match& Then
                                Cl.Select
                                Current.MoveCellPointer Where, rows&
                                If Selection.Contents = "" Then
                                    Selection.Contents = CopyCell.Contents
                             'format the cell here, if necessary
                                Else
                                    Selection.Font.FontColor.ColorName = "red"
                                End If
                                Exit Sub
                            End If
                        End Forall
                    'Optional message box if no match was found:
                        Msgbox |No match for "| & MatchCell.Contents & |" was found in range "| _
                        & TargetRange.CoordinateString & |".|,48,|Sub CheckCell_1: No Match|
                    End Sub

                     

                    I hope this helps anyone else with a need...

                    Thanks to everyone who provided suggestions.

                    Merry, Merry and Happy, Happy to all.

                              The only DUMB question is the one question you DID NOT ask...