Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Joselito Watiwat
  Where is Joselito Watiwat?
 Manila
 Philippines
 Joselito Watiwat
 To: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 Tags
Subject: RE: Strange error
Thread ID: 104017 Message ID: 104240 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Errors & Debugging
Date: Monday, August 14, 2006 7:32:51 AM         
   


> > > Here is one that I have never run into before. I have an app called Child Maintenance where we enter the data on children from the developing world that we sponsor (we are a child sponsorship organization similar to World Vision except we are Catholic.)
> > >
> > > The app is a basic file maintenance form. On the left hand side of the form, I have a drop down list that allows the user to select a search criteria. Directly underneath, I have a searchtext textbox and directly underneath that, I have a listbox where I present a candidate list. The user selects the type of search to perform from the dropdown and then enters the text to search for in the textbox. In the .Valid of the textbox, I initiate the search using a DO CASE construct - one case for each search type. If the search is successful, the app displays the matching children in the listbox. The search procedure automatically selects the last item in the list and issues a ThisForm.ChildList.Click() In the .Click, I call a custom form method that displays that child's information. In this method, the app SEEK()s the child's project and sub-project in the project.dbf and subproject.dbf tables (don't blame me for the use of a reserved word as a table name - I inherited it.) If either of these SEEK()s fail, an error message is displayed.
> > >
> > > One of the search types that I have is "ChildID." This searches for the childID assigned at the project (not the child record ID field.) The child ID has an input mask of [!!!9999999] and there is an index on the ChildID field. When I populate the candidate list, I use a SEEK()/SCAN WHILE construct. A user enters "ABC" and the app will find all of the chidren where the child ID starts with "ABC" - so far all works well. The users are now entering child records with a child ID starting with YPK. If the ChildID index is set, YPK1041 is the last child record. When I enter YPK into the search text box, the candidate list fills appropriately, it automatically .Click()s and the child information is displayed but at this point, and only on this record, the app tells me that it cannot SEEK() that child's project or sub-project. If I then click child YPK1040 the app works perfectly. If I again, click child YPK1041, the SEEK()s on project and sub-project work perfectly. If I go back up to the searchtext and enter YPK again, the SEEK()s fail again.
> > >
> > > My first thought was "there has to be a data problem." I compaired YPK1040 to YPK1041 and found that the project and subproject ID's were identical in both child records. I add a new child record, YPK1042. Now YPK1041 works perfectly and YPK1042 has the error.
> > >
> > > Worse still, this code has not changed in 18 months and this error just showed up this week. I KNOW this code works. As any body else run into problems with "the last logical record for that index?"
> > >
> > > The appropriate code is as follows:
> > >
*** SearchText.Click()
> > > lnRetVal = 0
> > > This.parent.ChildList.Clear 
> > > n = 0
> > > IF !EMPTY(ALLTRIM(This.Value))
> > > 	DO Case
> > > 	CASE This.parent.SearchType.Value = 1	&& Child ID
> > > 		SELECT Child
> > > 		SET ORDER TO TAG ChildID
> > > 		IF SEEK(UPPER(ALLTRIM(This.Value)))
> > > 			SCAN WHILE ChildID = UPPER(ALLTRIM(This.Value)) 
> > > 				n = n + 1
> > > 				lcName = ALLTRIM(Child.firstname-(" "+ ;
> > > 								 Child.middle)-(" "+ ;
> > > 								 Child.family))
> > > 				This.parent.ChildList.AddItem(Child.ChildID,n,1)
> > > 				This.Parent.ChildList.List(n,2) = lcName 
> > > 				This.Parent.ChildList.ItemData(n) = Child.childno
> > > 			ENDSCAN 
> > > 			IF This.Parent.ChildList.ListCount > 0
> > > 				ThisForm.DisplayChild
> > > 				This.Parent.ChildList.Selected(This.Parent.ChildList.ListCount) = .t.
> > > 				This.Parent.ChildList.Click 
> > > 				lnRetVal = 1
> > > 			ELSE
> > > 				MESSAGEBOX("Could not find a child with this ID.",16,"Search Failed")
> > > 				lnRetVal = -1
> > > 			ENDIF 
> > > 		ELSE
> > > 			MESSAGEBOX("Could not find this child ID",16,"Search Failed")
> > > 			lnRetVal = -1
> > > 		ENDIF 
> > > 	CASE...
> > > ENDCASE
> > > 
> > > *** ChildList.Click()
> > > SELECT child
> > > SET ORDER TO TAG ChildNo
> > > FOR i = 1 TO This.ListCount
> > > 	IF This.Selected(i)
> > > 		lnChildNo = This.ItemData(i)
> > > 		IF SEEK(lnChildNo)
> > > 			ThisForm.DisplayChild
> > > 		ELSE
> > > 			MESSAGEBOX("Could not seek this child",16,"Technical Error")
> > > 			...
> > > 		ENDIF
> > > 	ENDIF
> > > ENDFOR
> > > 
> > > *** ThisForm.DisplayChild()
> > > SELECT Project
> > > SET ORDER TO TAG ProjectNo
> > > IF SEEK(Child.ProjectNo)
> > > 	lcProject = Project.projectid
> > > ELSE
> > > 	MESSAGEBOX("Could not seek project",16,"Technical Error")
> > > 	lcProject = ""
> > > ENDIF
> > > SELECT SubProject
> > > SET ORDER TO TAG SubNo
> > > IF SEEK(Child.subno)
> > > 	lcSubProject = Subproject.subproject
> > > ELSE
> > > 	MESSAGEBOX("Could not seek sub-project",16,"Technical Error")
> > > 	lcSubProject = ""
> > > ENDIF
> > > 

> > >
> > > Any ideas - I am stumped.
> > >
> > > Ken
> > > You shall know the truth - and the truth shall set you free. (John 8:33)

> >
> >
> > Hi Ken,
> > The obvious question that I have to ask... and I base this on
> > you stating this worked; "Worse still, this code has not
> > changed in 18 months"
> > Have you reindexed the tables to ensure that we are not
> > running into a phantom end of file marker?
> > Secondly, I question having the search operation in the valid
> > event? I take it you are not validating the user inputs at this
> > point in time, and if you were going to valdiate the user's
> > input I would probably go with an INDEXSEEK()function call to
> > validate if in fact a match was found. As you well know the
> > INDEXSEEK() does not move the record pointer and really is the
> > funtion to use and returns a .T., or .F. if the seek operation
> > was successful. Based upon this function's return value you can
> > the display a user definable messagebox for what-ever you need.
> >
> > Please let me know what you find out, as reviewing your code
> > I personally do not see a coding error. My first evaluation
> > is as you mentioned, "there has to be a data problem."
> >
> > Pete from the Great White North. (Only in Canada, ay.) Over and Out ...

>
> Hi Pete,
>
> We just reindexed at the end of the month, but I suspect you may be right here - the problem showed up about a week after the last reindexing so I will try that next. It will be a pain in the A$$ to reindex as we have to inform all of the projects that we are about to shut down their favorite app for about an hour. Do you know how hard it is to tell Sr. So and So in the outer reaches of wherever that she has to log off for an hour? You would think that nuns would be more understanding! :)
>
> As to the .valid() question, I typically use a "FindIt" button - actually, I have a table based search class that has a searchtype combo, a searchText textbox a "FindIt" command button and a grid to display the search results in. It is a much better setup - no case statements, no adding code when we need a new type of search, all I need do is add another record to my ChildSearch table.
>
> I inherited the original form and it has, shall we say, "evolved" over time. It still works but it really isn't my favorite way to do things. And yes, I agree - the .Valid() really isn't the place for that sort of code. Oh well, as soon as I can get a "RoundToIt" that too will change.
>
> As to an index seek vs a seek? It doesn't really matter here - I need to move to the last record that I find anyway. If I don't find a record, the user has to enter another search.
>
> You shall know the truth - and the truth shall set you free. (John 8:33)


2 things you may try to consider:

1) Set exact on|off
2) You may have two values in your combo box depending on what column you bound the actual.

thisform.combobox.value
thisform.combobox.displayvalue

If you select from the list then "this.value" gets the actual ID_code but if you enter a value directly in the combobox it is in the "this.displayvalue" property.

Sometimes these two little things are taken for granted and caused trouble.

Hope it helps.


Joselito Watiwat - Philippines

ENTIRE THREAD

Strange error Posted by Ken Murphy @ 8/10/2006 8:18:29 PM
RE: Strange error Posted by Pete Sass @ 8/10/2006 9:37:39 PM
RE: Strange error Posted by Ken Murphy @ 8/10/2006 10:32:45 PM
RE: Strange error Posted by Joselito Watiwat @ 8/14/2006 7:32:51 AM
RE: Strange error Posted by Sergey Karimov @ 8/10/2006 9:38:33 PM
RE: Strange error Posted by Ken Murphy @ 8/10/2006 10:44:39 PM
RE: Strange error Posted by Sergey Karimov @ 8/10/2006 11:25:40 PM
RE: Strange error Posted by Ken Murphy @ 8/11/2006 1:33:41 AM
RE: Strange error Posted by Andy Kramek @ 8/10/2006 11:15:31 PM
RE: Strange error Posted by Ken Murphy @ 8/11/2006 1:47:56 AM
RE: Strange error Posted by Andy Kramek @ 8/11/2006 11:34:21 AM
RE: Strange error Posted by Ken Murphy @ 8/11/2006 12:02:50 PM
RE: Strange error Posted by Pete Sass @ 8/16/2006 10:21:42 PM
RE: Strange error Posted by Ken Murphy @ 8/17/2006 1:53:54 AM
RE: Strange error Posted by Ken Murphy @ 8/21/2006 7:06:31 PM
RE: Strange error Posted by David Hall @ 8/23/2006 12:06:06 PM
RE: Strange error Posted by Ken Murphy @ 8/23/2006 2:45:16 PM
RE: Strange error Posted by David Hall @ 8/31/2006 5:38:45 PM
RE: Strange error Posted by Ken Murphy @ 8/31/2006 6:17:39 PM
RE: Strange error Posted by Jim Winter @ 8/31/2006 6:44:57 PM
RE: Strange error Posted by tushar @ 8/31/2006 7:06:07 PM
RE: Strange error Posted by Ken Murphy @ 8/31/2006 7:41:37 PM
RE: Strange error Posted by tushar @ 8/31/2006 7:46:59 PM
RE: Strange error Posted by Ken Murphy @ 8/31/2006 8:11:52 PM
RE: Strange error Posted by tushar @ 8/31/2006 9:05:03 PM
RE: Strange error Posted by Jim Winter @ 8/23/2006 3:30:45 PM
RE: Strange error Posted by David Hall @ 9/11/2006 4:19:02 PM
RE: Strange error Posted by Ken Murphy @ 9/11/2006 4:35:59 PM
RE: Strange error Posted by David Hall @ 9/12/2006 11:10:28 AM