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

UI (Not Responding) while script is running

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

  • UI (Not Responding) while script is running

    I have a script that runs when a file exists. The script parses the contents of the file and adds records to a table.

    While the script is running the UI cannot be used and says Not Responding.

    I have used the contents of the script in a thread but have the same result.

    Is there a way to run the script without interfering with the users ability to use the UI.

    Thanks,

    Keith

  • #2
    Re: UI (Not Responding) while script is running

    No
    There can be only one.

    Comment


    • #3
      Re: UI (Not Responding) while script is running

      Nice Stan

      BUT, if you show us your script, there may be ways to make it run faster...
      Robin

      Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

      Comment


      • #4
        Re: UI (Not Responding) while script is running

        Thanks for the help.

        Below is the content of the script:

        Code:
                                dim fptr as P
                                dim i_tbl as P
                                dim g_tbl as P
        			dim gp_tbl as P
        			dim fh_tbl as P
        			dim c_tbl as P
        			dim gb_tbl as P
        			dim bh_tbl as P
        			dim ih_tbl as P
        			
        			dim lot_id as C	
        			dim loadout as C	
        			dim flushed as C
        			dim batch as C
        			dim temp_str as C	
        			dim group as C	
        			dim group_id as C	
        			dim formula as C
        			dim customer as C
        			dim cust_id as C	
        			dim location as C
        			dim status as C	
        			dim s_date as C
        			dim bin as C
        			dim text as C
        			dim mix_id as C
        			dim order_id as C
        			dim mix_status as C
        			dim form_status as C
        			dim form_flushed as C
        			dim mixid_batch_ing as C
        			dim mixid_batch as C
        							
        			dim freefall as N
        			dim handadd_wt as N
        			dim	handadd_cost as N
        			dim act_wt as N
        			dim act_wt_bin_1 as N
        			dim act_wt_bin_2 as N
        			dim act_wt_bin_3 as N
        			dim tar_wt_bin_1 as N
        			dim tar_wt_bin_2 as N
        			dim tar_wt_bin_3 as N
        			dim act_wt_diff as N
        			dim freefall_bin_1 as N
        			dim freefall_bin_2 as N
        			dim freefall_bin_3 as N
        			dim jog_bin_1 as N
        			dim jog_bin_2 as N
        			dim jog_bin_3 as N	
        			dim tar_wt as N	
        			dim act_cost as N	
        			dim phase as N	
        			dim cur_phase as N	
        			dim act_total_wt as N	
        			dim act_weight_per_head as N	
        			dim head as N		
        			dim unground as N 	
        			dim cus_milling_cost as N
        			dim cus_batching_cost as N  
        			dim cus_delivery_cost as N		
        			dim loc_distance as N		
        			dim gb_ing_cost as N	
        			dim gb_inv_bal as N
        			dim start_pos as N
        			dim end_pos as N	
        			dim line_ctr as N
        			dim array_ctr as N
        			dim file_size as N
        			dim inv_left as N
        					
        			dim gb_ing_active as L	
        			dim result as L
        			dim delete_rec as L
        			
        			dim bin_2_inv as L
        			dim bin_3_inv as L
        			
        			dim bin_in_use as C	
        			dim result_mes as C
        			dim result_cnt as N
        			
        			dim date as D
        			dim time as T
        			
        			delete file_lines
        			dim file_lines[0] as C
        			
        			file.rename(ftp_path + "prodimp.dat",ftp_path + "prodimp_temp.dat")
        			
        			fptr = file.open(ftp_path + "prodimp_temp.dat",FILE_RO_SHARED)
        			file_size = fptr.bytes_get()
        			while .NOT. fptr.eof()			
        				file_lines[] = fptr.read_line()		
        			end while		        
        			fptr.close()
        				
        			line_ctr = file_lines.size()	 
        			
        			dim form_weight as N = 0
        			dim form_batches as N = 0
        			dim form_cost as N = 0
        			
        			dim batch_weight as N = 0	
        			dim batch_cost as N = 0
        			
        			dim milling_weight as N = 0
        			dim milling_cost as N = 0
        			dim batching_cost as N = 0
        			dim delivery_cost as N = 0
        			
        			dim array_size as N = 0
        			
        			FOR x = 1 to line_ctr
        				text = file_lines[x]
        				array_size = array_size + len(text) + 1 'add 1 for LF
        			NEXT
        			
        			if file_size <> array_size .and. file_size <> array_size + file_lines.size() then 'size of file is not the same as the array and the file could have been opened so a character is added for each line
        				file.rename(ftp_path + "prodimp_temp.dat",ftp_path + "errors\prodimp_error_size" + time("_MMddyyyy_0h0m0s",now()) + ".dat") 
        				'MESSAGE TO USER??		
        				end	  
        			end if
        			
        			FOR x = 1 to line_ctr
        				
        				sleep(.1)
        				
        				text = file_lines[x]
        				
        				if substr(text,1,3) = "100" then
        					
        					mix_status = "Finished" 
        					
        					start_pos = at(",",text,1) + 1;		end_pos = at(",",text,2);	mix_id = substr(text,start_pos,end_pos - start_pos);
        					start_pos = at(",",text,2) + 1;		end_pos = at(",",text,3);	order_id = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,3) + 1;		end_pos = at(",",text,4);	form_name = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,4) + 1;		end_pos = at(",",text,5);	temp_str = substr(text,start_pos,end_pos - start_pos);	date = stod(temp_str)			 						
        					start_pos = at(",",text,6) + 1;		end_pos = at(",",text,7);	temp_str = substr(text,start_pos,end_pos - start_pos)	;
        	
                                                temp_str = substr(temp_str,1,2) + ":" + substr(temp_str,3,2)	 + ":" + substr(temp_str,5,5);	time = ctodt(dtoc(date) + " " +  temp_str)			
        					
                                                start_pos = at(",",text,7) + 1;		end_pos = at(",",text,8);	loadout = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,8) + 1;		end_pos = at(",",text,9);	flushed = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,9) + 1;		end_pos = at(",",text,10);	batch = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,10) + 1;	end_pos = at(",",text,11);	group = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,11) + 1;	end_pos = at(",",text,12);	bin = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,13) + 1;	end_pos = at(",",text,14);	mix_status = substr(text,start_pos,end_pos - start_pos);
        					
        					'get formula information
        					fh_tbl = table.open("form_history") 
        					index = fh_tbl.index_primary_put("Mix_id") 
        					f_rec = fh_tbl.fetch_find(mix_id)
        					cust_id = fh_tbl.Customer_id
        					customer = fh_tbl.Customer_name
        					location = fh_tbl.Location_name			
        					formula = fh_tbl.Formula_name
        					form_loadout = fh_tbl.Loadout			
        					form_status = fh_tbl.Status
        					form_flushed = fh_tbl.Flushed
        					form_batches = fh_tbl.Batches
        					form_cost = fh_tbl.Cost
        					form_weight = fh_tbl.Weight							
        					fh_tbl.close()
        					
        					if f_rec < 0 then
        						formula = form_name
        					end if
        					
        					'get customer information
        					c_tbl = table.open("customers")
        					index = c_tbl.index_primary_put("Name") 
        					c_rec = c_tbl.fetch_find(customer)			
        					if c_rec > 0 then
        						cus_milling_cost = c_tbl.Milling_cost
        						cus_batching_cost = c_tbl.Batching_cost
        						cus_delivery_cost = c_tbl.Delivery_cost
        						cust_id = c_tbl.Customer_id
        					else
        						cus_milling_cost = set_milling
        						cus_batching_cost = set_batching
        						cus_delivery_cost = 0
        						cust_id = ""
        					end if
        					c_tbl.close()	
        					
        					'add "0" to batch if less than 100 and less than 10
        					if val(batch) < 100 then
        						batch = "0" + batch
        					end if
        						 
        					if val(batch) < 10 then
        						batch = "0" + batch
        					end if	
        					
        					mixid_batch = alltrim(mix_id) + alltrim(batch)	
        						    
        				end if
        				
        				if substr(text,1,3) = "200" then
        					
        					handadd_wt = 0	
        					freefall_bin_1 = 0
        					freefall_bin_2 = 0
        					freefall_bin_3 = 0
        					jog_bin_1 = 0
        					jog_bin_2 = 0
        					jog_bin_3 = 0
        										
        					start_pos = at(",",text,1) + 1;			end_pos = at(",",text,2);			ing_name = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,2) + 1;			end_pos = at(",",text,3); 			act_wt = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,3) + 1;			end_pos = at(",",text,4);			tar_wt = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,4) + 1;			end_pos = at(",",text,5);			bin_in_use  = substr(text,start_pos,end_pos - start_pos)			
        					start_pos = at(",",text,5) + 1;			end_pos = at(",",text,6);			act_wt_bin_1  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,6) + 1;			end_pos = at(",",text,7);			act_wt_bin_2  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,7) + 1;			end_pos = at(",",text,8);			act_wt_bin_3  = substr(text,start_pos,end_pos - start_pos)			
        					start_pos = at(",",text,8) + 1;			end_pos = at(",",text,9);			handadd_wt  = substr(text,start_pos,end_pos - start_pos)			
        					start_pos = at(",",text,9) + 1;			end_pos = at(",",text,10);			freefall_bin_1  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,10) + 1;		end_pos = at(",",text,11);			freefall_bin_2  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,11) + 1;		end_pos = at(",",text,12);			freefall_bin_3  = substr(text,start_pos,end_pos - start_pos)			
        					start_pos = at(",",text,12) + 1;		end_pos = at(",",text,13);			jog_bin_1  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,13) + 1;		end_pos = at(",",text,14);			jog_bin_2  = substr(text,start_pos,end_pos - start_pos)
        					start_pos = at(",",text,14) + 1;		end_pos = at(",",text,15);			jog_bin_3  = substr(text,start_pos,end_pos - start_pos)
        					'start_pos = at(",",text,15) + 1;		end_pos = at(",",text,16);			micro_flush  = substr(text,start_pos,end_pos - start_pos)			
        					
        					batch_weight = batch_weight + act_wt
        				 
        					' may use the following to fix the diffence in act wt when ing is the micro flush also
        					if act_wt > (act_wt_bin_1 + act_wt_bin_2 + act_wt_bin_3) then
        						
        						act_wt_diff = act_wt - (act_wt_bin_1 + act_wt_bin_2 + act_wt_bin_3)
        						
        						if bin_in_use = "1" then
        							act_wt_bin_1 = act_wt_bin_1 + act_wt_diff
        						else if bin_in_use = "2" then
        							act_wt_bin_2 = act_wt_bin_2 + act_wt_diff	
        						else if bin_in_use = "3" then
        							act_wt_bin_3 = act_wt_bin_3 + act_wt_diff
        						end if
        						
        					end if					
        					
        					if handadd_wt > 0 then
        						
        						tar_wt = tar_wt - handadd_wt
        						
        					end if				 
        				 	
        					result = .t.
        					
        					gb_inv_bal = 0
        					gb_ing_cost = 0				
        						
        					mixid_batch_ing = alltrim(mix_id) + alltrim(batch) + alltrim(ing_name)			
        					
        					'update ingredient parameters, inventories and grain banks	'find any records with same mix id and batch and name		
        					ih_tbl = table.open("ing_history")						
        					index = ih_tbl.index_primary_put("IdBatchIng")		
        					
        					rec = ih_tbl.fetch_find(mixid_batch_ing)
        					
        					if (rec <= 0) then 'rec > 0 indicates if ingredient from this mix id and batch was downloaded before			    
        						
        						'update grain bank for ingredient
        						gb_inv_bal = 0
        						gb_ing_cost = 0
        						gb_tbl = table.open("grain_bank")
        						gb_rec = gb_tbl.fetch_first()
        						if gb_rec = 0 then
        							while .NOT. gb_tbl.fetch_eof()
        								gb_ing_active = gb_tbl.Active
        								if gb_tbl.cust_id = cust_id .and. gb_tbl.Ingredient = ing_name .and. gb_tbl.Active = .t. then 'what if two records for the same ing??
        									gb_ing_cost = gb_tbl.Cost
        									gb_tbl.change_begin();
        									if (gb_tbl.Weight - gb_tbl.Wt_used) >= act_wt .or. (gb_tbl.Continuous = .t.)
        										gb_tbl.Wt_used = gb_tbl.Wt_used + act_wt	
        										gb_inv_bal = act_wt
        									else 'weight left in bank < act_wt
        										gb_inv_bal = gb_tbl.Weight - gb_tbl.Wt_used
        										if gb_inv_bal < 0
        											gb_inv_bal = 0
        										end if
        										gb_tbl.Wt_used = gb_tbl.Weight
        										gb_tbl.Active = .f.	
        									end if
        									gb_tbl.change_end()    
        								end if
        								gb_tbl.fetch_next()	
        							end while
        						end if
        						gb_tbl.close()	
        											
        						'update parameters for ingredient
        						i_tbl = table.open("ing")
        						index = i_tbl.index_primary_put("Name")			
        						i_tbl.fetch_find(ing_name)
        						i_tbl.change_begin()				
        						if i_tbl.unground = .t. then
        							milling_weight = milling_weight + act_wt				
        						end if
        						
        						if bin_in_use = "0" then
        							bin_in_use = "1"
        						end if
        												
        						i_tbl.bin_in_use = bin_in_use				
        						if i_tbl.Inv_needed - tar_wt >= 0 then
        							i_tbl.Inv_needed = i_tbl.inv_needed - tar_wt
        						else
        							i_tbl.Inv_needed = 0
        						end if			
        						ing_desc = i_tbl.Description
        						
        						'set cost / unit to grain bank or to average cost if needed
        						if gb_ing_cost = 0 .and. i_tbl.use_ave_cost = .t. then										
        							gb_ing_cost = i_tbl.cost										
        						end if	
        															
        						i_tbl.change_end(.T.)
        						i_tbl.close()
        						
        						'get number of inventory records for current ingredient
        						inv_rec_cnt = dbcount("ing_inv","Name",ing_name)
        						delete Irec
        					 	dim Irec[inv_rec_cnt] as p
        					 	Irec.clear()			  	
        					 	Irec.initialize_from_table("ing_inv","Name = " + quote(ing_name))				
        						'if bin 2 or bin 3 have no inventory records then add bin 2 and bin 3 actual weight to bin 1 actual weight - needed because inv may only be added to bin 1
        				  		'micro come in on a pallet and the whole inventory is added to ingredient plus bin 1 may be used more than bin 2 and 3
        						bin_2_inv = .f.
        				  	bin_3_inv = .f.
        				  	for y = 1 to inv_rec_cnt		  		
        				  		if Irec[y].bin = 2 .and. Irec[y].amount <> 0 then
        				  			bin_2_inv = .t.
        				  		end if
        				  		if Irec[y].bin = 3 .and. Irec[y].amount <> 0 then
        				  			bin_3_inv = .t.
        				  		end if
        				  	next
        				  		
        				  	if bin_2_inv = .f. then
        				  		act_wt_bin_1 = act_wt_bin_1 + act_wt_bin_2
        				  		act_wt_bin_2 = 0	
        				  	end if
        				  		
        				  	if bin_3_inv = .f. then
        				  		act_wt_bin_1 = act_wt_bin_1 + act_wt_bin_3
        				  		act_wt_bin_3 = 0	
        				  	end if		
        				  		
        						'get ingredient inventory list from ing_inv table		
        						rec_cnt = dbcount("ing_inv","Name",ing_name) + 3 'extra slot in array for each bin - needed if no inventory records for bins 1, 2 or 3			
        						delete Irec
        					 	dim Irec[rec_cnt] as p
        					 	Irec.clear()			  	
        					 	Irec.initialize_from_table("ing_inv","Name = " + quote(ing_name))			 		
        					 	Irec.sort("A","ID")	'Irec.sort("A","Date")
        					 	
        					 	if rec_cnt > 3 then 'inv records for ingredient
        					 		for y = 1 to rec_cnt
        					 			Irec[y].cost = Irec[1].cost
        					 		next
        					 	else 'no inv for ingredient
        					 		for y = 1 to rec_cnt
        					 			Irec[y].cost = 0.0	
        					 		next	
        						end if
        					 	 	
        				  	'add new fields to array pointer and update cost if needed   
        				  	for y = 1 to rec_cnt	  			
        							Irec[y].actual_wt = 0
        							Irec[y].actual_cost = 0					
        							'gb_ing_cost > 0 indicates grain bank cost or average cost in use for this ingredient
        							if gb_ing_cost > 0 then 
        								Irec[y].cost = gb_ing_cost
        							end if							
        							Irec[y].target_wt = 0										
        						next
        						
        						handadd_cost = Irec[1].cost				
        				  		
        				  	'need to add amount field and bin field to last 3 records since they are not initialized from table		  		
        				  	Irec[rec_cnt - 2].amount = 0
        				  	Irec[rec_cnt - 2].bin = 1
        				  	Irec[rec_cnt - 2].lot_id = ""
        				  	Irec[rec_cnt - 1].amount = 0
        				  	Irec[rec_cnt - 1].bin = 2
        				  	Irec[rec_cnt - 1].lot_id = ""
        				  	Irec[rec_cnt].amount = 0
        				  	Irec[rec_cnt].bin = 3
        				  	Irec[rec_cnt].lot_id = ""
        				  		
        				  		'update ingredient inventories and add actual, target and mix id to list 
        						if act_wt_bin_1 > 0 then	
        											
        							act_wt_balance = act_wt_bin_1										
        							
        							'go through list of inventory records for bin 1 of ingredient
        							for y = 1 to rec_cnt						
        								
        								'record used in bin 1 
        								if Irec[y].Bin = 1 .and. Irec[y].amount > 0 then							
        						  			
        						  			inv_left = Irec[y].amount - Irec[y].used
        						  			
        						  			If inv_left >= act_wt_balance then				  				
        						  				Irec[y].used = Irec[y].used + act_wt_balance
        						  				Irec[y].actual_wt = act_wt_balance
        						  				'Irec[y].target_wt = act_wt_balance				  								  				
        						  				'update record in ing_inv table using Irec and Irec.Id				  				
        						  				query.filter = "id = " + s_quote(Irec[y].id)
        										result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        										'to exit for loop later
        						  				act_wt_balance = 0 				  			
        						  			else 'inventory left < act wt used from bin 1				  				
        						  				
        						  				'only delete record if there are more records for bin 1 so go through the rest of the list
        										delete_rec = .F.
        										for z = y + 1 to rec_cnt								
        											if Irec[z].Bin = 1 .and. Irec[z].amount > 0 then
        												delete_rec = .T.
        											end if								
        										next							
        										
        										if delete_rec then
        											'debug(1)									
        											if inv_left > 0 then																			
        												
        												Irec[y].actual_wt = inv_left	
        												act_wt_balance = act_wt_balance - inv_left
        																														
        											else 'neg_balance = abs(inv_left)									
        												
        												Irec[y + 1].used  = Irec[y + 1].used + abs(inv_left)
        																						
        											end if
        											
        											Irec[y].used = Irec[y].amount
        											
        											'delete record from ing_inv table using Irec.Id 
        							  				query.filter = "id = " + s_quote(Irec[y].id)
        							  				result = record_delete("ing_inv",query.filter)				  				
        							  				'add record to inv_use_history since all the inventory is used (use Irec[]) include mix_id field?
        							  				result = record_add("ing_inv_history",date() + crlf() + ing_name + crlf() + Irec[y].bin	+ crlf() + Irec[y].lot_id + crlf() + Irec[y].amount + crlf() + Irec[y].used + crlf() + mix_id + crlf() + time,2)
        										else								
        											Irec[y].used = Irec[y].used + act_wt_bin_1
        						  					Irec[y].actual_wt = act_wt_bin_1
        						  					'Irec[y].target_wt = act_wt_balance				  								  				
        						  					'update record in ing_inv table using Irec and Irec.Id				  				
        						  					query.filter = "id = " + s_quote(Irec[y].id)
        											result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        											act_wt_balance = 0									
        										end if	
        									
        									end if
        												  			
        						  			'put into list used to add ing_history records
        						  			Irec[y].actual_cost = Irec[y].actual_wt * Irec[y].cost			  			
        						  		end if				  		
        						  		if act_wt_balance <= 0 then	'leave at end of for loop	
        						  			exit for	
        						  		end if			  			
        					  		next
        					  		
        					  		'records in ing_inv table did not cover all of the actual weight or no records for ingredient
        					  		if act_wt_balance > 0 then
        					  			'need to add an entry for balance of ingredient actual weight to Irec[]
        					  			Irec[rec_cnt - 2].actual_wt = act_wt_balance
        					  			'Irec[rec_cnt - 2].target_wt = act_wt_balance
        					  			Irec[rec_cnt - 2].actual_cost = Irec[rec_cnt - 2].actual_wt * Irec[rec_cnt - 2].cost	
        					  		end if					
        						end if
        						
        						if act_wt_bin_2 > 0 then
        							act_wt_balance = act_wt_bin_2					
        							'go through list of inventory records for bin 2 of ingredient
        							for y = 1 to rec_cnt						
        								'record used in bin 2 
        								if Irec[y].Bin = 2 .and. Irec[y].amount > 0 then							
        						  			
        						  			inv_left = Irec[y].amount - Irec[y].used				  			
        						  			
        						  			if inv_left >= act_wt_balance then				  				
        						  				Irec[y].used = Irec[y].used + act_wt_balance
        						  				Irec[y].actual_wt = act_wt_balance
        						  				'Irec[y].target_wt = act_wt_balance				  								  				
        						  				'update record in ing_inv table using Irec and Irec.Id				  				
        						  				query.filter = "id = " + s_quote(Irec[y].id)
        										result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        										'to exit for loop later
        						  				act_wt_balance = 0 				  			
        						  			else 'inventory left < act wt used from bin 2				  				
        						  				
        						  				'only delete record if there are more records for bin 2 so go through the rest of the list
        										delete_rec = .F.
        										for z = y + 1 to rec_cnt								
        											if Irec[z].Bin = 2 .and. Irec[z].amount > 0 then
        												delete_rec = .T.
        											end if								
        										next
        										
        										if delete_rec then
        											
        											if inv_left > 0 then
        												
        												Irec[y].actual_wt = inv_left	
        												
        												act_wt_balance = act_wt_balance - inv_left
        												
        											else 'neg_balance = abs(inv_left)
        											
        												Irec[y + 1].used  = Irec[y + 1].used + abs(inv_left)
        																						
        											end if
        											
        											Irec[y].used = Irec[y].amount				  						  			
        						  						  				
        							  				'delete record from ing_inv table using Irec.Id 
        							  				query.filter = "id = " + s_quote(Irec[y].id)
        							  				result = record_delete("ing_inv",query.filter)
        							  				'add record to inv_use_history since all the inventory is used (use Irec[]) include mix_id field?
        							  				result = record_add("ing_inv_history",date() + crlf() + ing_name + crlf() + Irec[y].bin	+ crlf() + Irec[y].lot_id + crlf() + Irec[y].amount + crlf() + Irec[y].used + crlf() + mix_id + crlf() + time,2)
        							  			
        							  			else
        							  			
        							  				Irec[y].used = Irec[y].used + act_wt_bin_2
        						  					Irec[y].actual_wt = act_wt_bin_2
        						  					'Irec[y].target_wt = act_wt_balance				  								  				
        						  					'update record in ing_inv table using Irec and Irec.Id				  				
        						  					query.filter = "id = " + s_quote(Irec[y].id)
        											result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        											act_wt_balance = 0
        											
        							  			end if				  			
        						  			
        						  			end if				  			
        						  			'put into list used to add ing_history records
        						  			Irec[y].actual_cost = Irec[y].actual_wt * Irec[y].cost			  			
        						  		end if				  		
        						  		if act_wt_balance <= 0 then	'leave at end of for loop	
        						  			exit for	
        						  		end if				  					  			
        					  		next
        					  		'records in ing_inv table did not cover all of the actual weight or no records for ingredient
        						  	if act_wt_balance > 0 then
        						  		'need to add an entry for balance of ingredient actual weight to Irec[]
        						  		Irec[rec_cnt - 1].actual_wt = act_wt_balance
        						  		'Irec[rec_cnt - 1].target_wt = act_wt_balance
        						  		Irec[rec_cnt - 1].actual_cost = Irec[rec_cnt - 1].actual_wt * Irec[rec_cnt - 1].cost
        						  	end if					
        						end if
        						
        						if act_wt_bin_3 > 0 then
        							act_wt_balance = act_wt_bin_3					
        							'go through list of inventory records for bin 3 of ingredient
        							for y = 1 to rec_cnt						
        								'record used in bin 3 
        								if Irec[y].Bin = 3 .and. Irec[y].amount > 0 then	
        															
        						  			inv_left = Irec[y].amount - Irec[y].used	
        						  						  			
        						  			if inv_left >= act_wt_balance then				  				
        						  				Irec[y].used = Irec[y].used + act_wt_balance
        						  				Irec[y].actual_wt = act_wt_balance
        						  				'Irec[y].target_wt = act_wt_balance				  								  				
        						  				'update record in ing_inv table using Irec and Irec.Id				  				
        						  				query.filter = "id = " + s_quote(Irec[y].id)
        										result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        										'to exit for loop later
        						  				act_wt_balance = 0 				  			
        						  			else 'inventory left < act wt used from bin 3				  				
        						  				
        						  				'only delete record if there are more records for bin 3 so go through the rest of the list
        										delete_rec = .F.
        										for z = y + 1 to rec_cnt								
        											if Irec[z].Bin = 3 .and. Irec[z].amount > 0 then
        												delete_rec = .T.
        											end if								
        										next
        										
        										if delete_rec then
        											
        											if inv_left > 0 then
        												
        												Irec[y].actual_wt = inv_left	
        												
        												act_wt_balance = act_wt_balance - inv_left	
        												
        											else 'neg_balance = abs(inv_left)
        											
        												Irec[y + 1].used  = Irec[y + 1].used + abs(inv_left)				
        												
        											end if
        											
        											Irec[y].used = Irec[y].amount
        													  				
        							  				'delete record from ing_inv table using Irec.Id
        							  				query.filter = "id = " + s_quote(Irec[y].id) 
        							  				result = record_delete("ing_inv",query.filter)
        							  				'add record to inv_use_history since all the inventory is used (use Irec[]) include mix_id field?
        							  				result = record_add("ing_inv_history",date() + crlf() + ing_name + crlf() + Irec[y].bin	+ crlf() + Irec[y].lot_id + crlf() + Irec[y].amount + crlf() + Irec[y].used + crlf() + mix_id + crlf() + time,2)
        							  			
        							  			else
        							  			
        							  				Irec[y].used = Irec[y].used + act_wt_bin_3
        						  					Irec[y].actual_wt = act_wt_bin_3
        						  					'Irec[y].target_wt = act_wt_balance				  								  				
        						  					'update record in ing_inv table using Irec and Irec.Id				  				
        						  					query.filter = "id = " + s_quote(Irec[y].id)
        											result = record_update("ing_inv",query.filter,"used =" + str(Irec[y].used,10,2) + crlf() + "last_mix_id =" + mix_id + crlf() + "time =" + time)
        											act_wt_balance = 0
        											
        							  			end if
        							  			
        						  			end if				  			
        						  			'put into list used to add ing_history records
        						  			Irec[y].actual_cost = Irec[y].actual_wt * Irec[y].cost			  			
        						  		end if				  		
        						  		if act_wt_balance <= 0 then	'leave at end of for loop	
        						  			exit for	
        						  		end if				  					  			
        					  		next
        					  		'records in ing_inv table did not cover all of the actual weight or no records for ingredient    
        						  	if act_wt_balance > 0 then
        						  		'need to add an entry for balance of ingredient actual weight to Irec[]
        						  		Irec[rec_cnt].actual_wt = act_wt_balance
        						  		'Irec[rec_cnt].target_wt = act_wt_balance
        						  		Irec[rec_cnt].actual_cost = Irec[rec_cnt].actual_wt * Irec[rec_cnt].cost
        						  	end if					
        						end if
        						
        						'set target weight - set target_wt to tar_wt for first record with act > 0 
        						for y = 1 to rec_cnt
        							if Irec[y].actual_wt > 0 then
        								Irec[y].target_wt = tar_wt
        								exit for	
        							end if							
        						next	
        						
        						'add Irec list to ing_history table 'set new field to True
        						dim rec_ing_cnt as N = 0
        						for y = 1 to rec_cnt
        							if Irec[y].actual_wt > 0 then
        								'add to ing_history table - WHAT IF RECORD HAS LESS INV (AMOUNT - USED) FOR THE ACTUAL WEIGHT???? ' old + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch) + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch + ing_name) + crlf() + ".t.",2)
        								result = record_add("ing_history",date + crlf() + mix_id + crlf() + Irec[y].lot_id + crlf() + ing_name  + crlf() + str(Irec[y].target_wt,10,4)\
        								+ crlf() + str(Irec[y].actual_wt,10,4) + crlf() + str(Irec[y].actual_cost,10,2) + crlf() + ing_desc + crlf() + batch\
        								+ crlf() + mixid_batch + crlf() + mixid_batch_ing + crlf() + ".t.",2)
        								rec_ing_cnt = rec_ing_cnt + 1
        							end if
        							sleep(.1)
        							'if result = .f. then
        							'	exit for
        							'end if					 
        						next
        						
        						'if handadd used for weigh hopper ingredient then add another line to ing_history table
        						if handadd_wt > 0 then
        							
        							handadd_cost = handadd_wt * handadd_cost
        											
        							result = record_add("ing_history",date + crlf() + mix_id + crlf() + "handadd" + crlf() + ing_name  + crlf() + str(handadd_wt,10,4)\
        							+ crlf() + str(handadd_wt,10,4) + crlf() + str(handadd_cost,10,2) + crlf() + ing_desc + crlf() + batch\
        							+ crlf() + mixid_batch + crlf() + mixid_batch_ing + crlf() + ".t.",2)
        							rec_ing_cnt = rec_ing_cnt + 1
        							sleep(.1)	
        							
        						end if
        							
        						'check for rec_hist_cnt of records? if not the same redo for next loop
        						rec_hist_cnt = dbcount("ing_history","IdBatching",mixid_batch_ing)
        						
        						if rec_hist_cnt <> rec_ing_cnt then
        							for y = 1 to rec_cnt
        								if Irec[y].actual_wt > 0 then
        									'add to ing_history table - WHAT IF RECORD HAS LESS INV (AMOUNT - USED) FOR THE ACTUAL WEIGHT???? ' old + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch) + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch + ing_name) + crlf() + ".t.",2)
        									result = record_add("ing_history",date + crlf() + mix_id + crlf() + Irec[y].lot_id + crlf() + ing_name  + crlf() + str(Irec[y].target_wt,10,4)\
        									+ crlf() + str(Irec[y].actual_wt,10,4) + crlf() + str(Irec[y].actual_cost,10,2) + crlf() + ing_desc + crlf() + batch\
        									+ crlf() + mixid_batch + crlf() + mixid_batch_ing + crlf() + ".t.",2)
        								end if
        								sleep(.1)
        								if result = .f. then
        									exit for
        								end if					
        							next
        							
        							'if handadd used for weigh hopper ingredient then add another line to ing_history table
        							if handadd_wt > 0 then
        							
        								result = record_add("ing_history",date + crlf() + mix_id + crlf() + "handadd" + crlf() + ing_name  + crlf() + str(handadd_wt,10,4)\
        								+ crlf() + str(handadd_wt,10,4) + crlf() + str(handadd_cost,10,2) + crlf() + ing_desc + crlf() + batch\
        								+ crlf() + mixid_batch + crlf() + mixid_batch_ing + crlf() + ".t.",2)
        								sleep(.1)	
        								
        							end if
        								
        						end if				
        						
        						'record was not added
        						if result = .f. then
        							result_mes = "ing"
        						   	goto record_error
        						end if
        										
        						'update bin freefalls - table: ing_bins				
        						if freefall_bin_1 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 1"
        							result = record_update("ing_bins",query.filter,"freefall =	" + str(freefall_bin_1,10,2))
        						end if
        						if freefall_bin_2 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 2"
        							result = record_update("ing_bins",query.filter,"freefall =	" + str(freefall_bin_2,10,2))
        						end if
        						if freefall_bin_3 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 3"
        							result = record_update("ing_bins",query.filter,"freefall = " + str(freefall_bin_3,10,2))	
        						end if	
        						
        						'update bin jog - table: ing_bins				
        						if jog_bin_1 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 1"
        							result = record_update("ing_bins",query.filter,"jog_on_time =	" + str(jog_bin_1,10,4))
        						end if
        						if jog_bin_2 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 2"
        							result = record_update("ing_bins",query.filter,"jog_on_time =	" + str(jog_bin_2,10,4))
        						end if
        						if jog_bin_3 > 0 then
        							query.filter = "name = " + s_quote(ing_name) + ".and. bin = 3"
        							result = record_update("ing_bins",query.filter,"jog_on_time = " + str(jog_bin_3,10,4))	
        						end if
        							
        					end if
        					
        					batch_cost = batch_cost + act_cost
        					
        					ih_tbl.close()
        								   
        				end if
        				
        				if x < line_ctr then
        					text = file_lines[x+1]
        				end if
        				
        				if (substr(text,1,3) = "100") .OR. ( x = line_ctr ) then 'download batch from previous 100 through last 200 line
        					'update group phase - check if batch has already been downloaded
        					
        					bh_tbl = table.open("batch_history")
        					index = bh_tbl.index_primary_put("IdBatch") 
        					
        					'rec = bh_tbl.fetch_find(mix_id + batch)
        					
        					rec = bh_tbl.fetch_find(mixid_batch)
        					
        					if (rec <= 0) then 'indicates if batch was downloaded before
        						if group <> "" then 'formula has a group assigned to it
        							g_tbl = table.open("Groups")
        							index = g_tbl.index_primary_put("Name")
        							g_tbl.fetch_find(group)
        							phase = g_tbl.Current_phase
        							group_id = g_tbl.Group_id
        							head = g_tbl.Total_Head
        							s_date = g_tbl.Start_date
        							if isdate(s_date) = .f. .or. s_date = "" then
        								g_tbl.change_begin()
        								g_tbl.Start_date = date()
        								g_tbl.change_end()    
        							end if				
        							gp_tbl = table.open("Group_formulas")
        							record_found = gp_tbl.fetch_first()
        							if record_found = 0 then 'there are group formulas listed
        								while .NOT. gp_tbl.fetch_eof()							
        									
        									if gp_tbl.Group_id = group_id .and. (gp_tbl.Formula = formula .or. gp_tbl.phase = phase) .and. g_tbl.Reduce_cur_phase = .t. then 'correct group and current formula ' 10/14/09
        										gp_tbl.change_begin()						
        										act_total_wt = gp_tbl.Act_total_weight
        										act_total_wt = act_total_wt + batch_weight
        										act_weight_per_head = gp_tbl.Act_weight_per_head
        										act_weight_per_head = act_weight_per_head + batch_weight/head
        										s_date = gp_tbl.Start_date
        										'update current phase for group
        										if act_total_wt > gp_tbl.Tar_total_weight - gp_tbl.Deviation then 'phase target weight is reached
        											status = "finished"
        											cur_phase = gp_tbl.Phase + 1
        											g_tbl.change_begin()
        											g_tbl.Current_phase = cur_phase
        											g_tbl.change_end()
        											gp_tbl.End_date = date()
        										else 'phase target weight has not been reached
        											status = "active"
        											if .NOT. isDate(s_date) then
        												gp_tbl.Start_date = date()
        											end if
        										end if																
        										gp_tbl.Act_weight_per_head = act_weight_per_head
        										gp_tbl.Act_total_weight = act_total_wt
        										gp_tbl.Status = status
        										gp_tbl.change_end()								
        										exit while
        									end if
        									
        									gp_tbl.fetch_next()
        								end while
        							end if
        							g_tbl.close()
        							gp_tbl.close()
        						end if				
        					end if
        					bh_tbl.close()
        					
        					'calculate milling cost
        					if set_units = "pounds" then 
        						milling_cost = (milling_weight/2000)*cus_milling_cost
        					else 
        						milling_cost = (milling_weight/1000)*cus_milling_cost 
        					end if			
        					'calculate batching cost
        					if set_units = "pounds" then 
        						batching_cost = (batch_weight/2000)*cus_batching_cost
        					else 
        						batching_cost = (batch_weight/1000)*cus_batching_cost 
        					end if			
        					
        					'put entries into ingredient history table for milling cost and batching cost ' old + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch + "Milling Charge") + crlf() + ".t.",2)
        					if milling_cost > 0 then
        						lot_id = ""
        					 	result = record_add("ing_history",date + crlf() + mix_id + crlf() + lot_id + crlf() + "Milling Charge" + crlf() + 0 + crlf() + 0\
        					 	+ crlf() + str(milling_cost,10,2) + crlf() + "Milling Charge" + crlf() + batch + crlf() + mixid_batch\
        					 	+ crlf() + mixid_batch + "Milling Charge" + crlf() + ".t.",2)
        									
        						batch_cost = batch_cost + milling_cost
        						if result = .f. then 'if result is false than goto end
        						   	result_mes = "ing_mill"
        						   	goto record_error
        						end if
        					end if
        										
        					if batching_cost > 0 then ' old + crlf() + Alltrim(LTRIM(TRIM(MIX_ID),"0") + batch + "Batching Charge") + crlf() + ".t.",2)
        						lot_id = ""				
        						result = record_add("ing_history",date + crlf() + mix_id + crlf() + lot_id + crlf() + "Batching Charge" + crlf() + 0 + crlf()\
        						+ 0  + crlf() + str(batching_cost,10,2) + crlf() + "Batching Charge" + crlf() + batch + crlf() + mixid_batch\
        						+ crlf() + mixid_batch + "Batching Charge" + crlf() + ".t.",2)
        						
        						batch_cost = batch_cost + batching_cost
        						if result = .f. then 'if result is false than goto end
        						   	result_mes = "ing_batch"
        						   	goto record_error
        						end if
        					end if
        					
        					'download batch
        					result = record_add("batch_history",date + crlf() + order_id + crlf() + mix_id + crlf() + batch\
        					+ crlf() + alltrim(customer) + crlf() + alltrim(group) + crlf() + alltrim(location) + crlf() + loadout \     
        					+ crlf() + formula + crlf() + batch_weight + crlf() + batch_cost + crlf() + flushed + crlf() + mixid_batch,2) 
        					'debug(1)
        					if result = .f. then 'if result is false than goto end
        					    result_mes = "batch"
        					   	goto record_error
        					end if			
        					
        					'set form weight and cost using batch weight and cost  				
        					form_weight = form_weight + batch_weight
        					form_cost = form_cost + batch_cost
        								
        					'batch > 1 may be mixer flush that was sent to another loadout
        					if val(batch) > 1 then ' may have to check if this was a "flush" batch instead of number of batch
        						loadout = form_loadout
        					end if					
        												
        					'decrease batch number since last batch may be a flush batch			
        					if flushed = "yes" then
        						batch = str(val(batch) - 1)   
        					end if
        					
        					'may want to see if formula history record exist so can be added if needed
        								
        					'update record in formula history - MAY DO WHAT THE FOLLOWING 4 STATEMENTS DO IN DATABASE RULES - JUST UPDATE STATUS AND TIME HERE?
        					query.filter = "mix_id = " + s_quote(mix_id)
        					
        					'IF FIELD CALC USED
        					result = record_update("form_history",query.filter,"date =" + date + crlf() + "batches =" + batch + crlf() + "loadout =" + loadout\
        					+ crlf() + "status =" + mix_status + crlf() + "flushed =" + flushed	+ crlf() + "bin =" + bin + crlf() + "time=" + time)
        					
        					'does mix id exist in form_history
        					dim no_rec as n
        					no_rec = dbcount("form_history","Mix_Id",mix_id)
        					
        					'if record does not exist (result = .f.)
        					if result = .f. .and. no_rec = 0 then
        						'add record to form_history
        						result = record_add("form_history","date =" + date + crlf() + "mix_id =" + mix_id + crlf()+ "formula_name =" + formula + crlf() + "group_name =" + group + crlf() \
        						+ "batches =" + batch + crlf() + "loadout =" + loadout + crlf()	+ "status =" + mix_status + crlf() + "flushed =" + flushed + crlf()\
        						+ "bin =" + bin + crlf() + "time =" + time)
        						'put mix_id into inc_mix_id
        						record_update("inc_mix_id",".t.","mix_id = " + mix_id)	
        					end if			
        											
        					'if result is false than goto end		
        					if result = .f. then
        						result_mes = "formula_" + mix_id
        					    goto record_error
        					end if	
        								
        					milling_weight = 0
        					batch_weight = 0
        					batch_cost = 0		    
        				end if
        				
        			NEXT
        			
        			'completed so rename temp file with date and time stamp
        			'file.rename("C:\Users\Admin\Documents\CBX\FTP files\prodimp_temp.dat","C:\Users\Admin\Documents\CBX\FTP files\prodimp" + time("_MMddyyyy_0h0m0s",now()) + ".dat")
        			file.rename(ftp_path + "prodimp_temp.dat",ftp_path + "prodimp" + time("_MMddyyyy_0h0m0s",now()) + ".dat")
        				
        			'delete duplicate records in batch_history table
        			bh_tbl = table.open("batch_history")
        			bh_tbl.delete_dups("IdBatch + Flush")
        			bh_tbl.close()	
        			
        			'delete duplicate records in ing_history table and update field New from true to false
        			ih_tbl = table.open("ing_history")		
        			ih_tbl.delete_dups("IdBatching + Target_Wt + Actual_Wt + Lot_id")
        			query.filter = "New = .t."
        			query.order = ""
        			query.options = ""
        			indx = ih_tbl.query_create()
        			update.fields = 1
        			update.field1 = "New"
        			update.expr1 = ".f."
        			ih_tbl.update()		
        			ih_tbl.close()
        			
        			'script_play("UpdateMessages")
        			
        			'send updated ingredient parameters to batching panel		
        			'script_play("Download_Ing_New")	
        			
        			'send updated group parameters to batching panel		
        			'script_play("Download_Group_New")
        			
        			'recalculated form_history fields
        			'Dim tbl as P
        			'Tbl = table.open("form_history")
        			'Tbl.recalc_calcFields()
        			'Tbl.close() 
        			
        			end
        				
        			record_error: 
        			
        				'delete records with new field of True
        				ih_tbl = table.open("ing_history")
        				ih_tbl.delete_range("New = .t.")
        				ih_tbl.close()
        				
        				'message so user can try again - may have user initiate the uploading of the records from prodim.dat instead of CBM timer
        				res = ui_msg_box("Import file error","There was a problem with production import file" + crlf(2) + "Do you want to try again? No - The file will be placed in the errors directory",UI_QUESTION_SYMBOL+UI_YES_NO)
        				if res  = UI_YES_SELECTED
        					'file.rename("C:\Users\Admin\Documents\CBX\FTP files\prodimp_temp.dat","C:\Users\Admin\Documents\CBX\FTP files\prodimp.dat")
        					file.rename(ftp_path + "prodimp_temp.dat",ftp_path + "prodimp.dat")
        				else
        					'file.rename("C:\Users\Admin\Documents\CBX\FTP files\prodimp_temp.dat","C:\Users\Admin\Documents\CBX\FTP files\errors\prodimp_error_" + result_mes + time("_MMddyyyy_0h0m0s",now()) + ".dat")
        					file.rename(ftp_path + "prodimp_temp.dat",ftp_path + "errors\prodimp_error_" + result_mes + time("_MMddyyyy_0h0m0s",now()) + ".dat")
        				end if
        						
        			end
        			
        		end if
        Attached Files
        Last edited by Al Buchholz; 09-15-2016, 10:39 AM. Reason: added code tags and code as an attachment

        Comment


        • #5
          Re: UI (Not Responding) while script is running

          Something tells me I shouldn't have asked...
          Robin

          Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

          Comment


          • #6
            Re: UI (Not Responding) while script is running

            Ha Ha. I thought the same thing.

            Script has quite a bit to do. Takes around 10 sec for a 1K file. The problem is any amount of "locking up" is not acceptable to the customer.

            I was really hoping threads would solve this.

            Thank You

            Comment


            • #7
              Re: UI (Not Responding) while script is running

              I've not used threads, but this example http://www.alphasoftware.com/documen...%20Example.xml suggests that you can disable the UI for a thread using
              Code:
              this_thread.ui_disable = .t.
              and lower the priority of a thread using
              Code:
              this_thread.set_priority(-2)
              which SHOULD result in a thread that doesn't interfere with the UI and doesn't stop the user doing his/her work. It also appears that you need a 'yield control' statement somewhere in the code to release control back to the foreground - see http://www.alphasoftware.com/documen...%20CONTROL.xml

              Comment


              • #8
                Re: UI (Not Responding) while script is running

                If you don't mind piecemeal comments (I can't process/comprehend the whole script at one time).

                I read this section

                Code:
                start_pos = at(",",text,1) + 1;		end_pos = at(",",text,2);	mix_id = substr(text,start_pos,end_pos - start_pos);
                		start_pos = at(",",text,2) + 1;		end_pos = at(",",text,3);	order_id = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,3) + 1;		end_pos = at(",",text,4);	form_name = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,4) + 1;		end_pos = at(",",text,5);	temp_str = substr(text,start_pos,end_pos - start_pos);	date = stod(temp_str)
                		start_pos = at(",",text,6) + 1;		end_pos = at(",",text,7);	temp_str = substr(text,start_pos,end_pos - start_pos)	;
                		
                		temp_str = substr(temp_str,1,2) + ":" + substr(temp_str,3,2)	 + ":" + substr(temp_str,5,5);	time = ctodt(dtoc(date) + " " +  temp_str)
                		
                		start_pos = at(",",text,7) + 1;		end_pos = at(",",text,8);	loadout = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,8) + 1;		end_pos = at(",",text,9);	flushed = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,9) + 1;		end_pos = at(",",text,10);	batch = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,10) + 1;	end_pos = at(",",text,11);	group = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,11) + 1;	end_pos = at(",",text,12);	bin = substr(text,start_pos,end_pos - start_pos)
                		start_pos = at(",",text,13) + 1;	end_pos = at(",",text,14);	mix_status = substr(text,start_pos,end_pos - start_pos);
                to be assigning values to the variables based on the text variable by looking "in between" commas as in

                mix_id is the value between the first and second commas.

                You can do the same with

                mix_id = word(text,2,",")
                order_id = word(text,3,",")

                etc.
                There can be only one.

                Comment


                • #9
                  Re: UI (Not Responding) while script is running

                  There is also another section with similar coding that can be changed similarly using word().

                  All of your while sections processing table records can be speeded up by enclosing them with batch_begin() .... batch_end() as in

                  Code:
                  gb_tbl.batch_begin()
                  while .NOT. gb_tbl.fetch_eof()
                  					gb_ing_active = gb_tbl.Active
                  					if gb_tbl.cust_id = cust_id .and. gb_tbl.Ingredient = ing_name .and. gb_tbl.Active = .t. then 'what if two records for the same ing??
                  						gb_ing_cost = gb_tbl.Cost
                  						gb_tbl.change_begin();
                  						if (gb_tbl.Weight - gb_tbl.Wt_used) >= act_wt .or. (gb_tbl.Continuous = .t.)
                  							gb_tbl.Wt_used = gb_tbl.Wt_used + act_wt
                  							gb_inv_bal = act_wt
                  						else 'weight left in bank < act_wt
                  							gb_inv_bal = gb_tbl.Weight - gb_tbl.Wt_used
                  							if gb_inv_bal < 0
                  								gb_inv_bal = 0
                  							end if
                  							gb_tbl.Wt_used = gb_tbl.Weight
                  							gb_tbl.Active = .f.
                  						end if
                  						gb_tbl.change_end()
                  					end if
                  					gb_tbl.fetch_next()
                  				end while
                  gb_tbl.batch_end()
                  There can be only one.

                  Comment


                  • #10
                    Re: UI (Not Responding) while script is running

                    You have several sections that conceivably open the same table three times in quick succession.

                    Code:
                    'update bin jog - table: ing_bins
                    			if jog_bin_1 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 1"
                    				result = record_update("ing_bins",query.filter,"jog_on_time =	" + str(jog_bin_1,10,4))
                    			end if
                    			if jog_bin_2 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 2"
                    				result = record_update("ing_bins",query.filter,"jog_on_time =	" + str(jog_bin_2,10,4))
                    			end if
                    			if jog_bin_3 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 3"
                    				result = record_update("ing_bins",query.filter,"jog_on_time = " + str(jog_bin_3,10,4))
                    			end if
                    It should be quicker to open the table once and close when done.

                    Code:
                    'update bin jog - table: ing_bins
                    			z_tbl = table.open("ing_bins",FILE_RW_EXCLUSIVE)
                    			if jog_bin_1 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 1"
                    				ix = z_tbl.query_create("N",query.filter)
                    				z_tbl.change_begin()
                    				z_tbl.jog_on_time =  str(jog_bin_1,10,4)
                    				z_tbl.change_end(.T.)
                    				ix.drop()
                    			end if
                    			if jog_bin_2 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 2"
                    				ix = z_tbl.query_create("N",query.filter)
                    				z_tbl.change_begin()
                    				z_tbl.jog_on_time = str(jog_bin_2,10,4)
                    				z_tbl.change_end(.T.)
                    				ix.drop()
                    			end if
                    			if jog_bin_3 > 0 then
                    				query.filter = "name = " + s_quote(ing_name) + ".and. bin = 3"
                    				ix = z_tbl.query_create("N",query.filter)
                    				z_tbl.change_begin()
                    				z_tbl.jog_on_time = str(jog_bin_3,10,4)
                    				z_tbl.change_end(.T.)
                    				ix.drop()
                    			end if
                    			z_tbl.close()
                    The z_tbl.query_create() will be much faster if ing_bins has an index on ing_name.
                    Last edited by Stan Mathews; 09-15-2016, 04:03 PM.
                    There can be only one.

                    Comment


                    • #11
                      Re: UI (Not Responding) while script is running

                      All the above are suggestions, not intended in any way as criticism of what you presently have. They represent things I think I know to be ways to speed up script execution.
                      There can be only one.

                      Comment


                      • #12
                        Re: UI (Not Responding) while script is running

                        Thank you for the suggestions. I will try them asap.

                        Comment


                        • #13
                          Re: UI (Not Responding) while script is running

                          Keith,

                          Opening or closing a table takes appreciably longer than you might think. It's often best to avoid opening and then closing the same table, over and over, each time through a FOR ... NEXT loop or each time through a WHILE ... END WHILE loop. Usually the code can be arranged to open the desired tables before the loop starts, and then close them after the loop finishes. This way the disk activity is diminished and scripts run faster.

                          -- tom

                          Comment

                          Working...
                          X