Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Date Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Re: Date Script

    Hi Everyone,

    Please, see below code and point out what was wrong.
    I'd like to save my result into table with start date.
    I also have the several problems with this scripts.
    (1) more than 7 days duration case. If the duration is more than a week period, I think, I have to create new record and save new Workoder_id, week number and dates. How can I do this?
    (2) Calculate it with Add_bus_days() and allowance for weekend days. I simply tried as "add_bus_days(vSdate-1+1) but Error message.

    (3) If I changed the existing records then How to revise the current records

    Code:
    dim thdr as p
    dim i as n
    dim vDur as n 
    dim vSDate as d
    dim vNext as c
    dim vDate as d
    
    dim tSch as p
    
    dim vSun as d
    dim vMon as d
    dim vtue as d
    dim vWed as d
    dim vThu as d
    dim vFri as d
    dim vSat as d
    
    tSch=table.open("wrkodr_schedule")
    thdr=table.open("wrkodr_hd",file_rw_shared)
        
    thdr.index_primary_put("Wrkodr_Id")
    thdr.fetch_first()
    while .not. thdr.fetch_eof()
    	vSDate=thdr.Plan_startdate
    	vDur=thdr.Plan_duration
    	vWrkOdr=thdr.Wrkodr_id
    
        if vdur>0 then  
    		for i =1 to vdur  'vsdate-1+i
    			vnext= vSdate-1+i  'How to get the business days(add_bus_days) with option, Allow or not on weekend.
    			vDate= ctod(vNext) 'Convert to Date
    		    vWeek= week(vDate) 'Convert to Week Number
    
    'If vDate = "Sunday" and Week(vNext)= Week(?) then store it to vSun for tempoary 'cdow(ctod(vNext))="Monday"
               	
             select
    		    case dow(vdate)=1 'If vdate ="sunday(1)" then save to vSun 
    		       vSun= vDate
    		    case dow(vdate)=2
    		       vMon=vDate
    		    case dow(vdate)=3
    		       vTue=vDate
    		    case dow(vdate)=4
    		       vWed=vDate
    		    case dow(vdate)=5
    		       vThu=vDate
    		    case dow(vdate)=6
    		       vFri=vDate
    		    case dow(vdate)=7 
    		       vSat=vDate
    		end select   	
    	 next i
    		else		
    		ui_msg_box("No Duration","Enter Duration Information")
    	end Next
    end if	    
    
    tSch=table.open("wrkodr_schedule")
    	     tSch.enter_begin()	
    	         tSch.Wrkodr_id=vWrkOdr	
    	         tSch.Week_number=vWeek	     
    		     tSch.Sun=vSun
    		     tSch.Mon=vMon
    		     tSch.Tue=vTue
    		     tSch.Wed=vWed
    		     tSch.Thu=vThu
    		     tSch.Fri=vFri
    		     tSch.Sat=vSat
    	     tSch.enter_end(.t.)	
    
    thdr.fetch_next()	
    end while
    			     			
    thdr.close()
    tSch.close()
    
    end

    Comment


      #32
      Re: Date Script

      vnext= vSdate-1+i 'How to get the business days(add_bus_days) with option, Allow or not on weekend.
      No.

      The whole purpose of add_bus_days() is to not allow on weekend.

      vnext = add_bus_days(vSdate-1,i)

      will sequence through

      vSdate
      vSdate+1
      vSdate+2
      up to
      vSdate+duration

      I simply tried as "add_bus_days(vSdate-1+1) but Error message.
      Because you didn't specify the second paramater of the function Add_Days as N.


      (1) more than 7 days duration case.
      Before you worry about how to create a new record, consider how you are going to display the new record. You currently have a browse with fields for Mon<->Sun. How does the information for the the next Mon get displayed?
      There can be only one.

      Comment


        #33
        Re: Date Script

        Good Morning, Stan

        Thank you for "Add_bus_days()" explanation.

        I think, If I have a field in the table (AllowWorkSat, AllowWorkSun) then I will write the script as here
        Code:
        If vDur>0 .and. vAllowWorkSat= .t. .and. vAllowWorkSun=.f.  then
                   vNext = vSdate-1+ i 
        else
                   vNext = Add_bus_days(vSdate-1, i)
        maybe, I can switch between Business and full week days.
        or any other opinion?

        I'd like to display it by a weekly date with week() function search and attached the screen shots for detail. I created the variables(days) and use the color equation and Display Format so that I can display the color and descriptions within a day and days.
        I modified the dates in the Work_schedule table in order to create this display purpose.

        Comment


          #34
          Re: Date Script

          Hi everyone,

          I tried several ways to get the right result but I still not sure how to get new record, by workOrder_id, on this scripts. When I tested and run the Debug, the previous records are still remained on the following new record.
          Code:
          'Date Created: 12-Dec-2009 08:22:31 PM
          'Last Updated: 06-Jan-2010 09:58:07 AM
          'Created By  : John Koh
          'Updated By  : John Koh
          
          debug(1)
          
          dim thdr as p
          dim i as n
          dim vDur as n 
          dim vSDate as d
          dim vNext as c
          dim vDate as d
          
          dim tSch as p
          
          dim vSun as d
          dim vMon as d
          dim vtue as d
          dim vWed as d
          dim vThu as d
          dim vFri as d
          dim vSat as d
          
          dim vIndex as p
          'dim vRecno as n
          dim vFind as c
          
          
          tSch=table.open("wrkodr_schedule")
          thdr=table.open("wrkodr_hd",file_rw_shared)
          'How to get current record?    
          	'vIndex=thdr.index_primary_put("Wrkodr_Id")
          	'vRecno=thdr.recno()
          	'thdr.fetch_first()
          	'vFind=thdr.fetch_find("vrecno")
          	
          'Entire Records with While ... End Function
          vIndex=thdr.index_primary_put("Wrkodr_Id")
          thdr.fetch_first()
          while .not. thdr.fetch_eof()
          
           	vSDate=thdr.Plan_startdate
          	vDur=thdr.Plan_duration
          	vWrkOdr=thdr.Wrkodr_id
           
          if vdur>0 then
             
          		for i =1 to vdur  'vsdate-1+i for Standard add_bus_days(vSdate-1,i) for only Bus_days
          			vnext= (vSdate-1+i)  
          			vDate= ctod(vNext) 'Convert to Date
          		    vWeek= week(vDate) 'Convert to Week Number
          [COLOR="Red"]'I need the some condtions on here to create new record, by Workorder. 
          'The Previous records are still remained on the those variable fields.[/COLOR] 		    
          	       select
          			    case dow(vdate)=1 'If vdate ="sunday(1)" then save to vSun 
          			       vSun= vDate
          			    case dow(vdate)=2
          			       vMon=vDate
          			    case dow(vdate)=3
          			       vTue=vDate
          			    case dow(vdate)=4
          			       vWed=vDate
          			    case dow(vdate)=5
          			       vThu=vDate
          			    case dow(vdate)=6
          			       vFri=vDate
          			    case dow(vdate)=7 
          			       vSat=vDate
          			       
          		  end select
          		next i
          	else		
          		ui_msg_box("No Duration","Enter Duration Information")
          	  end Next
          	
          'Moved to here in order to select a record by group of WorkOrder_id
          'It is not right place. Moved back to before Next i
                        	
          end if
                 tSch.enter_begin()	
          	         tSch.Wrkodr_id=vWrkOdr	
          	         tSch.Week_number=vWeek	     
          		     tSch.Sun=vSun
          		     tSch.Mon=vMon
          		     tSch.Tue=vTue
          		     tSch.Wed=vWed
          		     tSch.Thu=vThu
          		     tSch.Fri=vFri
          		     tSch.Sat=vSat
          	     tSch.enter_end(.t.)
          thdr.fetch_next()
          end while
          			     			
          thdr.close()
          tSch.close()
          'Save it to Schedule table. with WorkOrder_id and week() 
          
          end
          I want to get the result as here(1st Screen Shot )
          but I had as it( 2nd Screen Shot )

          Happy New Year.

          Comment


            #35
            Re: Date Script

            Code:
                       vNext = Add_bus_days(vSdate-1, i)
            I haven't read through the entire thread, but it seems to me that you are using vNext as a date variable while dimming it as a character. Are you sure that you want it to be character type?
            Code:
            dim cDate as C
            cDate = date() + 4 - 1
            ?cDate
            = "{01/09/2010}"
            
            ?cDate + 3
            = "{01/09/2010}3"
            
            dim dDate as D
            dDate = date() + 4 - 1
            ?dDate
            = {01/09/2010}
            
            ?dDate + 3
            = {01/12/2010}
            My 2 cents,
            Steve

            Comment


              #36
              Re: Date Script

              Reset the variables after the thdr.fetch_next() command


              vSun = {}
              vMon = {}
              vTue = {}
              vWed = {}
              vThu = {}
              vFri = {}
              vSat = {}
              There can be only one.

              Comment


                #37
                Re: Date Script

                Stan,

                Thank you. That is working fine.

                Comment


                  #38
                  Re: Date Script

                  I picked up on what Steve picked up on. Hard to see how it could be working.
                  Mike W
                  __________________________
                  "I rebel in at least small things to express to the world that I have not completely surrendered"

                  Comment


                    #39
                    Re: Date Script

                    Steve and Mike

                    How about this
                    Code:
                    dim vSdate as d ={1/1/10}
                    dim cdate as c
                    cdate= vSdate+1
                    ?cdate
                    = "01/02/2010"
                    
                    cdate = vSdate+2
                    ?cdate
                    = "01/03/2010"
                    
                    cdate = vsdate+3
                    ?cdate
                    = "01/04/2010"
                    
                    
                    
                    dim dDate as d
                    dDate=vSdate+1
                    ?dDate
                    = {01/02/2010}
                    
                    dDate = vSdate+2
                    ?dDate
                    = {01/03/2010}
                    
                    dDate= vSdate+3
                    ?dDate
                    = {01/04/2010}
                    I have the same result in the calculation.

                    Comment


                      #40
                      Re: Date Script

                      As long as you always do date arithmetic with date variables and realize that a conversion takes place when you assign a date to a character, it would work. I guess it's just my personal preference to represent dates with date type variables and convert them when necessary for dialogs, messages, etc.

                      Just beware that you should get an error with the expression:
                      Code:
                      vNext = add_bus_days(vNext,1)

                      Comment


                        #41
                        Re: Date Script

                        Steve and Mike

                        Additional comment. I want to figure out the period of date from the my work order start date and end date with the duration. After I followed the Stan's suggestion, I have the right result. See enclosed the attachment.

                        Code:
                        'If I have 3 duration date, then the vEnddate is 1/6/2010
                        
                        'Just vSdate only. vSdate - 1 day and add back 1 day with vSdate which is counted the duration
                        'I used the For ... next function, repeat it until end of the duration
                        
                        dim vSdate as d ={1/4/2010}
                        dim vNext as c
                        dim vEnddate as c
                        
                        vNext= (vSdate - 1 + 1)
                        ?vNext
                        = "01/04/2010"
                        '2nd duration date
                        dim vNext2 as c
                        vNext2= (vSdate - 1 + 2)
                        ?vNext2
                        = "01/05/2010"
                        
                        '3rd duration date
                        dim vEnddate as c
                        vEnddate= (vSdate - 1 + 3)
                        ?vEnddate
                        = "01/06/2010"
                        
                        'I have a Mondday field as Date type in the Table, 
                        'Now, I have to match the field type before save it into a table
                        Now, I have worry about how to breakdown and save to table when the duration is more than a week.

                        Comment


                          #42
                          Re: Date Script

                          Steve

                          Just beware that you should get an error with the expression:
                          Code:

                          vNext = add_bus_days(vNext,1)
                          When I tried "vNext = add_bus_days(vSdate-1, <Number of repeating>)" with For... Next Loop function, It seems fine. My vSdate is a Date type.

                          However before I change or use the add_bus_day() function, I have a few problems. case
                          (1) more than a week problem and
                          (2) If I changed the data then how to changed the previous records

                          Comment


                            #43
                            Re: Date Script

                            What you are using and what I warned you about are entirely different. I was just warning you not to use vNext as a date parameter or in date arithmetic since it is dimmed as a character.

                            Comment


                              #44
                              Re: Date Script

                              Hi,

                              How can I get new record when the duration is more than a week period?

                              Code:
                               
                              dim vEdate as d
                              dim vEdateWk as n
                              dim vSdateWk as n
                              vEdate = (vSDate-1+vDur)
                              vEdateWk = week(vEdate)
                              vSdateWk = week(vSDate)
                              
                              if vdur>0 .and. vSdateWk = vEdatewk then
                                  do some action here (as previous scripts)
                              else
                              
                              dim vWeekDur as n
                              dim vWeek as n
                              vWeekDur = vEdateWk-vSdateWk
                                 for vWeek = 1 to vWeekDur 'How to get 1st week and save it then repeat it until match with EndWeek?
                                 	   
                              	       for i =1 to vdur  
                              			vnext= (vSdate-1+i)  
                              			vDate= ctod(vNext) 
                              			vWeek= week(vDate) 
                              		 		    
                              			       select
                              					    case dow(vdate)=1 
                              					       vSun= vDate
                              					    case dow(vdate)=2
                              					       vMon=vDate
                              					    case dow(vdate)=3
                              					       vTue=vDate
                              					    case dow(vdate)=4
                              					       vWed=vDate
                              					    case dow(vdate)=5
                              					       vThu=vDate
                              					    case dow(vdate)=6
                              					       vFri=vDate
                              					    case dow(vdate)=7 
                              					       vSat=vDate
                              			       end select
                                 			       
                              		    Next i
                              [COLOR="Red"]'I need some conditions here or some where if vWeek is not same week as previous vWeek.[/COLOR]
                              	 next vWeek	
                              end if
                              'Write to table

                              Comment


                                #45
                                Re: Date Script

                                Good morning Everyone,

                                I have a script for my workorder schedule. I need your help on the 2nd condition script for many weeks.
                                When the work period is many weeks,
                                (1) count the first week date then save to table
                                (2) start next week with same work order then count and save to table.
                                (3) repeat #2 until end of the work period week.

                                'How to make a breakdown condition for the new week loop when the work period is more than 1 week?


                                Code:
                                'deleted all of the "dim" for shrink page
                                
                                tSch=table.open("wrkodr_schedule")
                                thdr=table.open("wrkodr_hd",file_rw_shared)
                                
                                vIndex=thdr.index_primary_put("Wrkodr_Id")
                                thdr.fetch_first()
                                while .not. thdr.fetch_eof()
                                
                                 	vSDate=thdr.Plan_startdate
                                	vDur=thdr.Plan_duration
                                	vWrkOdr=thdr.Wrkodr_id
                                	
                                vEdate = (vSDate-1+vDur)
                                vEdateWk = week(vEdate)
                                vSdateWk = week(vSDate)
                                vWeekDur = vEdateWk-vSdateWk
                                 
                                if vdur>0 .and. vSdateWk=vEdateWk then
                                   
                                       for i =1 to vdur  
                                		vnext= (vSdate-1+i)  
                                		vDate= ctod(vNext) 'Convert to Date
                                		vWeek= week(vDate) 'Convert to Week Number
                                	    select
                                	        case dow(vdate)=1 'If vdate ="sunday(1)" then save to vSun 
                                	        vSun= vDate
                                	        case dow(vdate)=2
                                	        vMon=vDate
                                		case dow(vdate)=3
                                		vTue=vDate
                                		case dow(vdate)=4
                                		vWed=vDate
                                		case dow(vdate)=5
                                		vThu=vDate
                                		case dow(vdate)=6
                                		vFri=vDate
                                		case dow(vdate)=7 
                                		vSat=vDate
                                		end select
                                	next i
                                 	        
                                elseif vdur>0 .and. vSdateWk<>vEdateWk then
                                [COLOR="Red"][B]'I need another loop condition
                                'How to make a breakdown condition for a week loop?
                                'This scripts ran for every weeks and date[/B][/COLOR]
                                     for w = vWeekDur to 0 step -1
                                            for i =1 to vdur  
                                	        vnext= (vSdate-1+i) 
                                		vDate= ctod(vNext) 
                                		vWeek= week(vDate)
                                		select
                                			case dow(vdate)=1 
                                			vSun= vDate
                                			case dow(vdate)=2
                                			vMon=vDate
                                			case dow(vdate)=3
                                			vTue=vDate
                                			case dow(vdate)=4
                                			vWed=vDate
                                			case dow(vdate)=5
                                			vThu=vDate
                                			case dow(vdate)=6
                                			vFri=vDate
                                			case dow(vdate)=7 
                                			vSat=vDate
                                		end select
                                	    next i
                                	 next w  
                                else
                                        
                                end if
                                
                                'Write to table
                                       tSch.enter_begin()	
                                	         tSch.Wrkodr_id=vWrkOdr	
                                	         tSch.Week_number=vWeek  
                                		     tSch.Sun=vSun
                                		     tSch.Mon=vMon
                                		     tSch.Tue=vTue
                                		     tSch.Wed=vWed
                                		     tSch.Thu=vThu
                                		     tSch.Fri=vFri
                                		     tSch.Sat=vSat
                                	     tSch.enter_end(.t.)
                                thdr.fetch_next()
                                'Clean previous 
                                    vSun={}
                                    vMon={}
                                    vTue={}
                                    vWed={}
                                    vThu={}
                                    vFri={}
                                    vSat={}
                                end while
                                			     			
                                thdr.close()
                                tSch.close()
                                
                                end

                                Comment

                                Working...
                                X