Alpha Video Training
Page 2 of 2 FirstFirst 12
Results 31 to 45 of 45

Thread: Date Script

  1. #31
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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

  2. #32
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default 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.

  3. #33
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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.

  4. #34
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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
    'I need the some condtions on here to create new record, by Workorder. 
    'The Previous records are still remained on the those variable fields. 		    
    	       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.

  5. #35
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default 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

  6. #36
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Date Script

    Reset the variables after the thdr.fetch_next() command


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

  7. #37
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default Re: Date Script

    Stan,

    Thank you. That is working fine.

  8. #38
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,168

    Default 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"

  9. #39
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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.

  10. #40
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default 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)

  11. #41
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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.

  12. #42
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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

  13. #43
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default 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.

  14. #44
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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
    'I need some conditions here or some where if vWeek is not same week as previous vWeek.
    	 next vWeek	
    end if
    'Write to table

  15. #45
    "Certified" Alphaholic
    Real Name
    John Koh
    Join Date
    Jan 2004
    Location
    Maryland, USA
    Posts
    1,062

    Default 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
    'I need another loop condition
    'How to make a breakdown condition for a week loop?
    'This scripts ran for every weeks and date
         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

Similar Threads

  1. Date dialog script & report script won't combi
    By rbierman@iowbar.org in forum Alpha Five Version 5
    Replies: 6
    Last Post: 12-07-2003, 07:40 AM
  2. Problem with date script
    By Glen Beer in forum Alpha Five Version 4
    Replies: 5
    Last Post: 08-25-2003, 06:50 PM
  3. Date Script
    By Mick Magnuson in forum Code Archive
    Replies: 0
    Last Post: 11-29-2001, 09:13 AM
  4. Date Format In Script
    By John Wood in forum Alpha Five Version 4
    Replies: 7
    Last Post: 02-24-2001, 12:50 PM
  5. Valid Date Script
    By Michael Humby in forum Alpha Five Version 4
    Replies: 3
    Last Post: 01-10-2001, 11:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •