Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jun Tangunan
  Where is Jun Tangunan?
 Cabanatuan
 Philippines
 Jun Tangunan
 To: mohammed qasem
  Where is mohammed qasem?
 amman
 Jordan
 mohammed qasem
 Tags
Subject: RE: interactivechange
Thread ID: 189291 Message ID: 189366 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Other
Date: Thursday, August 14, 2008 3:48:21 PM         
   


-- snipped --

Hi Mohammed,

A couple of pointers:

Declare your variables local. Local variables are auto released when you leave the method you are in.

Local lcName1, lcName2, lcName3, lcName4, lnName1, lnName2, lnName3, lnName4
lcName1 = Alltrim(Thisform.text1.Value)
lcName2 = Alltrim(Thisform.text2.Value)
lcName3 = Alltrim(Thisform.text3.Value)
lcName4 = Alltrim(Thisform.text4.Value)


When you are using the length of the values of textboxes for repeated condition basis, put them likewise in a variable for easier readability and reference like:

lnName1 = Len(lcName1)
lnName2 = Len(lcName2)
lnName3 = Len(lcName3)
lnName4 = Len(lcName4)



Use EMPTY() instead of = "". Empty can work also on numeric values. EMPTY() can be = 0 too.

*CASE lcName1<>"" AND lcName2 <>""   AND lcName3 <>"" AND lcName4<>"" AND ;
  LEN(ALLTRIM(lcName1)) >= 3 AND LEN(ALLTRIM(lcName2)) >= 3 AND;
  LEN(ALLTRIM(lcName3)) >= 3 AND LEN(ALLTRIM(lcName4)) >= 3


Don't needed the !EMPTY() or <>"" above anymore as when the length is more than zero, it is not empty. That is redundant.

Check below what remains of your original CASE. Also place semicolon to connect the commands to the next line (row) for better readability too.

Do Case
Case lnName1 >= 3 And lnName2 >= 3 And  lnName3 >= 3 And lnName4 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 And ;
		name2=lcName2 And  name3=lcName3 And  name4=lcName4;
		into Cursor lcResultTable

Case lcName4=="" And lnName1 >= 3 And  lnName2 >= 3 And lnName3 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 And name2=lcName2;
		And  name3=lcName3 Into Cursor lcResultTable


* An alternative to testing for two or more empty string is to use the 
* variables that holds the length and add those as follows:

Case (lnName3 + lnName4) = 0 And lnName1 >= 3 And lnName2 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where   name1=lcName1 And name2=lcName2 And  name3=lcName3;
		into Cursor lcResultTable

Case (lnName2 + lnName3 + lnName4) = 0  And lnName1 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 ;
		into Cursor lcResultTable

Case Empty(lcName2) And Empty(lcName3) And lnName1 >= 3 And lnName4 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 And  name4=lcName4;
		into Cursor lcResultTable

Case Empty(lcName2) And Empty(lcName4) And lnName1 >= 3 And lnName3 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 And  name3=lcName3;
		into Cursor lcResultTable

Case Empty(lcName2) And lnName1 >= 3 And lnName3 >= 3 And lnName4 >= 3
	Select F4,F1,name4,name3,name2,name1 From x2 Where name1=lcName1 And name3=lcName3;
		And name4=lcName4 Into Cursor lcResultTable
Endcase

Go Top
Thisform.Grid1.RecordSource="lcResultTable"
Thisform.Grid1.Visible=.T.


Last, I don't know how you populate your grid but it seems you are recreating the cursor for every searches (if you use lostfocus) or key press (if you use interactive change). That would have an impact in the grid because it will be forced to be recreated each time you recreate the cursor itself. References and bindings inside the grid will be lost too. For a thorough reading of the trick to be used as an alternative to what I suspect you currently have, go to the BLOG section of foxite; and search for Andy Kramek's safe select. That will make your grid refresh faster and better.

Afterthought last, LOL! :-U

Please enclose your VFP commands with Code Block Tags for better syntax coloring and indentation. It can be achieved by highlighting the commands and then pressing Ctrl + L (sometimes this may erase everything) OR by clicking the code block tag icon above just next to New icon OR by typing < VFP > before your codes and ending it with < /VFP > (Remove the spaces between the "<" and "VFP" and ">".

I hope I have given you enough pointers so you can design your codes better. ;-)

Jun Tangunan

"Get out of the past and look in the future."
http://weblogs.foxite.com/sandstorm36/

ENTIRE THREAD

interactivechange Posted by mohammed qasem @ 8/14/2008 9:39:28 AM
RE: interactivechange Posted by Jun Tangunan @ 8/14/2008 10:13:21 AM
RE: interactivechange Posted by mohammed qasem @ 8/14/2008 10:49:10 AM
RE: interactivechange Posted by Jun Tangunan @ 8/14/2008 3:48:21 PM