Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate 2

Status
Not open for further replies.

Lewy

Technical User
Nov 16, 2001
170
GB
Hi everyone,

I know this should be simple but I am going around in circles trying to get a pushbuuton to bring up a form which asks for LastName and FirstName. On pressing OK I want to locate the record in a Customer table which matches the LastName and FirstName entered. The table contains amongst others a LastName and FirstName field.

Any help as always much appreciated.

Thanks,

Lewy
 
Langley,

You lost me on your last paragraph, where is he trying to control events on one form from another?

Lewy,

You're on the right track, we just need to figure out where the problem is. I know this is getting frustrating but we'll get you through it. How about stepping through the code using the debugger to see where the problem is occurring. At the beginning of your code in the left margin double click the mouse to insert a breakpoint (The keyboard shortcut is "Ctrl B") A red dot will show up in the margin and that line of code will be highlighted in red. Now when you run the code the debugger will open click the "Step Into" button to step through the code, this should help you isolate where in the code the problem is.
 
Okay, I went back and re-read your posts. You are calling this search form from the form you want to do the locate on. That makes it easier. Here is the button code for the CS2 form:

Code:
var
	f             Form	
	anyRetVal     AnyType
	myAr Array[]  String
	qLname,qFname String
	tc            tCursor
endVar

if NOT f.open("persrch.fsl") 
    then msgStop("Error opening Form", "Please make sure the form exists and try again.")
         return
endIf

anyRetVal = f.wait()

if anyRetVal.dataType() = "Logical" 
     then msgInfo("Cancelled","User closed search form improperly") 
          return
endif

anyRetval.breakApart(myAr)
qLname = myAr[1]
qFname = myAr[2]
tc.open("Cust1")

if qFname = "XXX" then
   if not tc.locate("Last Name", qLname)
      then msgInfo("Not Found",qLname+" not found.")
           tc.close()
           return
         else   yourMRO_or_TableframeObject.resync(tc)
                tc.close()
   endif

ELSE

   if not tc.locate("Last Name", qLname, "First Name", qFname)
      then msgInfo("Not Found",qFname+" "+qLname+" not found.")
           tc.close()
           return
      else   yourMRO_or_TableframeObject.resync(tc)
             tc.close()
endif


and here is the button code for the persrch form:


Code:
var
 sLname, sFname    string
 myRetVal          string
endvar

sLname = LastNameField.value
sFname = FirstNameField.value

if sLname = ""
   then msgStop("Error","Last name required")
        return
endif

if sFname = ""
   then sFname = "XXX"
endif

myRetVal = sLname+" "+sFname"

formReturn(myRetVal)
close()

Note that you will need to replace yourMRo_Or_TableframeObject with the real MRO name or Tableframe name.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Now that the board is working again, let me explain all that.

You open the search form and get the name to search for, sending it back to the calling form using formReturn. Since you only get to send back one value, you trick it by inserting a space between your two variables. The "XXX" assignment to the first name value lets the calling form know the user only wants a last name search.

After the search form closes, the calling form evaluates what it got from the fromReturn. If it's a logical value, then it assumes the user closed the form by clicking the X in the top right corner or by pressing a genuine cancel button (that retuyrns a logical false value). Then is tosses out the notice that no name was entered.

If it is a string value, then it sees if the first name value is "XXX". If it is, then it does the locate on the last name field only. If not, it does the compound locate.

If it does not find a match, it gives the "nothing found" message. Otherwise it resyncs your tableFrame or MRO to reposition it on the located record. If you are not using a tableFrame or MRO then shame on you, and you'll have to use a fieldName.

Does this make sense?

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

Sorry for not replying sooner to say many many thanks for all your help. Since my profession is an Optician, Paradox is a bit of a hobby for me and I have been writing my own 'Practice application' for some time now, but I have to do what I can between seeing clients. Thus I haven't had a chance to look at the code in detail yet or indeed try it out. One question of you, what do you mean by " If you are not using a tableFrame or MRO then shame on you", am I missing something here? Could my application be better?

Once again thanks, I will reply as soon as I have looked at the code.

Lewy
 
I understand, I wear about 10 different hats here and Paradox is just one of them.

I know it is tempting to just drop your fields on a page and go, but you really should consider using an MultiRecord Object (set to 1 Down and 1 Across). It's cleaner and more efficient because way you can centralize action events and so forth; not to mention being able to instantly place a scroll bar on it ;)

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

Still battling on with this code, almost there I hope. For the line of code "yourMRo_Or_TableframeObject.resync(tc)" As I haven't got an MRO or tableframe on the form, what do I need to add, the Name of the form, which form or whatever?

Can you also point me in the right direction for some GOOD lessons in Paradox.
thanks again.

Lewy
 
You will need to reference one of the fields on your form. Just click on one of them and look at the field name in the status bar at the bottom of the screen. For example, if you have a field object named LASTNAMEFLD, you would change:

yourMRo_Or_TableframeObject.resync(tc)

to

LASTNAMEFLD.resync(tc)

****

Mike Prestwood's Power Programming for Paradox series is one of the better sets of books on Paradox programming. You can Google for it or check out his site at
He sells new and used copies of his books.

Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

Almost there after entering a name on the persrch form and press the button I get the error message:

the specified array index is out of bounds.
The index is 2, and the array limit is 1.
pgeStock#Button19:pushbutton::24
qFname=myAr[2]

?????

Lewy
 
Did you cut and paste my code above? If so, there is a typo in the line:

myRetVal = sLname+" "+sFname"

Remove the last double-quote to make it:

myRetVal = sLname+" "+sFname


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Langley,

How can I thank you? Top Man..

And now to my next problem.......only kidding.

Regards,

Lewy
 
>How can I thank you?

Let's see... single malt scotch and cigars are my vices. ha ha.

Seriously, I was glad to help. Glad you got it sorted.



Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Lewy,

Congratulations, isn't learning fun...

Now that you've got it working I should mention that this is not the best approach to what you are trying to do, a much better way would be to.......

I started out the same way you are, trying to put a simple program together for my mail order business in my spare time. Now it's 10+ years and some 500,000+ lines of code later and I'm still at it.

Keep plugging
 
Kliot: What would the best approach be? (still looking for a form style interface to a full query for a big table)
 
Sorry it's taken so long to get back to you pesky work and a Visual Basic program I've been working on has had me tied up.

The only thing I don't really like about your form is it relies on correct spelling of names and what happens when you have two customers with the same name?

In my applications I have a form that pops up with a table on it containing the last name and first name fields. A secondary index is set on these fields and the form is filtered on the secondary index. I have an unbound field that the user types in the last name and as the user types the table filters down based on the name the user types. For example when the form opens it lists all customers, if you are looking for "Jones" as soon as you type in "J" the table filters down to "Ja.. to Jz.. and so on, this makes it easy to visually see if you are typing a name correctly and if there are more than one customers with the same name you will be able select the correct customer from that list.

The key to doing this is with setRange() and chr(255)

setRange(self, self + chr(255))


If this may be helpful for you let me know and post some code for you to play with.

Perrin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top