New call-to-action
Results 1 to 2 of 2

Thread: for each...next loops

  1. #1
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    491

    Default for each...next loops

    This is a bit of a general question, but I'm using in my web app, so...

    Is there any functional limit I'm not aware of regarding for each..next loops? Is there any problem nesting them? I don't see why either should be problematic, but I can't figure it out.

    I'm only cycling through about 57 records, so it should be able to handle it. Hopefully someone will see something I'm missing.

    PHP Code:
    dim spend_table as p
    dim bank_table 
    as p
    dim CompDiscInfo 
    as c
    dim EmployeeIDList 
    as c
    dim EmployeeCompDisc 
    as c
    dim hours_remaining 
    as n
    dim hours_to_post 
    as n
    dim hours_available 
    as n
    dim hour_check 
    as n
    DIM bank_list 
    AS C
    DIM find_result 
    AS N
    DIM indx 
    AS P
    DIM result 
    AS N

    spend_table 
    table.open("[PathAlias.ADB_Path]\compspent")
    bank_table table.open("[PathAlias.ADB_Path]\compbank")

    EmployeeIDList word_unique(table.external_record_content_get("[PathAlias.ADB_Path]\workhours","emp_id","emp_id","work_type='Comp Disc'.and.work_date>{3/11/2008}"),crlf())
    CompDiscInfo table.external_record_content_get("[PathAlias.ADB_Path]\workhours","work_id+'|'+work_date+'|'+work_hrs+'|'+emp_id","emp_id+work_date","work_type='Comp Disc'.and.work_date>{3/11/2008}")

    for 
    each EmployeeID in EmployeeIDList
        EmployeeCompDisc 
    filter_string(CompDiscInfo,EmployeeID)
        for 
    each Discharge in EmployeeCompDisc
            hour_check 
    tablesum("[PathAlias.ADB_Path]\compbank""hrs_earned>hrs_spent.and.between(comp_date, (addmonths({" word(Discharge,2,"|") + "},-3)+1), {" word(Discharge,2,"|") + "}-1).and.emp_id='" EmployeeID "'.and..not.is_del""hrs_earned")
            
    hours_remaining val(word(Discharge,3,"|"))
            if 
    hours_remaining <= hour_check then
                bank_list 
    table.external_record_content_get("[PathAlias.ADB_Path]\compbank","comp_id+'|'+comp_date+'|'+hrs_earned+'|'+hrs_spent","comp_date","hrs_earned>hrs_spent.and.between(comp_date, (addmonths({" word(Discharge,2,"|") + "},-3)+1), {" word(Discharge,2,"|") + "}-1).and.emp_id='" EmployeeID "'.and..not.is_del")
                for 
    each entry in bank_list
                    hours_available 
    val(word(entry,3,"|")) - val(word(entry,4,"|"))
                    if 
    hours_remaining <= hours_available then
                        hours_to_post 
    hours_remaining
                        hours_remaining 
    0
                    
    else
                        
    hours_to_post hours_available
                        hours_remaining 
    hours_remaining hours_available
                    end 
    if
                    
    spend_table.enter_begin()
                        
    spend_table.Comp_id alltrim(word(entry,1,"|"))
                        
    spend_table.Work_id alltrim(word(Discharge,1,"|"))
                        
    spend_table.Emp_id alltrim(EmployeeID)
                        
    spend_table.Spent_date ctod(alltrim(word(Discharge,2,"|")))
                        
    spend_table.Hrs_spent hours_to_post
                        spend_table
    .Is_chg = .t.
                        
    spend_table.Chg_by_id currentReviewer
                        spend_table
    .Chg_date date()
                        
    spend_table.Doc now()
                    
    spend_table.enter_end()

                    
    bank_table.index_primary_put("comp_id")
                    
    find_result bank_table.fetch_find(word(entry,1,"|"))
                    if 
    find_result 0 then
                        bank_table
    .change_begin()
                            
    bank_table.Is_chg = .t.
                            
    bank_table.Chg_by_id currentRviewer
                            bank_table
    .Chg_date date()
                            
    bank_table.Hrs_spent bank_table.Hrs_spent hours_to_post
                        bank_table
    .change_end()
                    else
                        
    result ui_msg_box("ERROR""Error posting to COMPBANK (" ut(str(find_result)) + ")",UI_OK_CANCEL)
                        if 
    result UI_CANCEL_SELECTED then
                            end
                        end 
    if
                    
    end if
                    if 
    hours_remaining 0 then
                        
    exit for
                    
    end if
                    
    statusbar.Set_Text(EmployeeID "|" Discharge "|" entry)
                
    next entry
            
    else
                
    result ui_msg_box("Lack of hours","There are not enough hours to use.\n\nMissing " ut(str(hours_remaining hour_check)) + "hours.",UI_OK_CANCEL)
                if 
    result UI_CANCEL_SELECTED then
                    end
                
    else
                    continue
                
    end if
            
    end if
        
    next Discharge
    next EmployeeID

    spend_table
    .close()
    bank_table.close()

    statusbar.clear()
    ui_msg_box("Complete","The compAction routine has completed."
    Stephen Pilon
    Associate Librarian
    Christendom College

  2. #2
    Member StephenP's Avatar
    Real Name
    Stephen Pilon
    Join Date
    Apr 2000
    Location
    Front Royal, Virginia
    Posts
    491

    Default Re: for each...next loops

    I like it when I can answer my own question. As I suspected, I was not seeing where I was getting trapped. All fixed for now, thanks.
    Stephen Pilon
    Associate Librarian
    Christendom College

Similar Threads

  1. connection build loops
    By Steve Hanson in forum Alpha Five Version 6
    Replies: 1
    Last Post: 02-28-2005, 04:15 AM
  2. USING LOOPS FOR VALUES IN XDIALOG BOXES
    By Willard in forum Alpha Five Version 6
    Replies: 0
    Last Post: 02-05-2005, 06:57 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
  •