Macro for finding a first name

In the older version of Pan, I had (long ago) created a macro that made it easy to find the first name in my database.
It is called “.Find first name”

Here is the script:
Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message “No such name!”
endif

I would call the script by typing command/1 and up would come this window.

I am embarrassed to say I don’t remember how I created it, how I assigned those keys to activate it. I don’t see any mention of keys in the script. Does this sort of thing look familiar to anyone? Any idea how to duplicate in PanX

Thanks,
— Richard

I think you probably setup a hot key and gave it the code

Call ".Find first name"

Look for definehotkeys in the Help file to see how to do it in Pan X.

I tried altering the script to like this:

definehotkeys “global”,"command-1"
Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message "No such name!"
endif

But does nothing. Suggestion?

— Richard

Add a comma before the code parameter and quote all the code:

definehotkeys "global","command-1",
|||Global Name
GetText "What is first name?", Name
Find «Firstname»  BEGINSWITH  Name
if (not info("found"))
beep
message "No such name!"|||

endif

I tried changing the script as you suggest:

definehotkeys “global”,“command-1”,
"Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message “No such name!”"
endif

But when run I get “unknown statement” for the word “What” in line 3
(GetText “What is first name?”, Name)

Looks the same to me as to what you sent back, but something not right. You do mention quotes to add, which I did but in what you sent it does not look like quotes, more 3 vertical lines.

— Richard

Although @rpitcairn probably used hotkeys to do this in Panorama 6, I think it would be a lot simpler to rename the procedure so that it doesn’t start with a period, so that it is included in the Action menu. Then he could simply assign 1 as the command-key equivalent as described on another thread.

If you do use hotkeys with Gary’s code, you would probably need to put this code in the .Initialize procedure. The hotkey won’t work until the code is run. I really think it would be much simpler to just use the original procedure but rename it so that it appears in the Action menu.

Notice i used ||| (triple pipes) for quoting the code. When you have standard quotes as part of the code you can not quote the entire thing also using standard quotes .

I changed the name so no period starting and now in Action menu.
Tried putting triple pipes but likely wrong key as does not work, nothing happens when selected.
I guessed that a “pipe” line was the mark on the key that has backward slash on bottom and vertical line at the top of the key, so used shift with that key. Wrong one?

definehotkeys “global”,“command-1”,
|||Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message “No such name!”
endif|||

So then I tried this modification"

Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message “No such name!”
endif

but then get a message back on using it:

Lots of suggestions here, but none of them will really get you where you really want to go, so I’ll add my 2¢

Define the variable Name after declaring it.

Name=''

I’d also suggest that you not typically define your variables as Globals. File scopes will make your life better. Form scope would be fine here as well.

Global Name
Name = “”

GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message "No such name!"
endif

Robert Ameeti

For reasons that I’m not recognizing, the variable needs to be defined prior to your use of it in GetText. It may have worked in Pano 6 but apparently not in Pano X

As noted below, I’d also suggest a Local scope for your variable.

As your criteria was ‘BEGINSWITH’, I did take the liberty of editing your ‘not found’ message.

Note that in Pano X, use the ‘Key’ box to achieve the use of the number ‘1’ when using you Command key to trigger the procedure.

Robert Ameeti
(949) 422-6866

Robert, that works!
I am glad to take global off. Just eliminate that line? Is not saying “global” reduce it to a local search? OK, I am using the words here but not really understanding global vs. local. However, I do programming in Supercard and there if I say “global” it stays in memory after the script has run. Same here?

Also you say that you edited the “not found” message (original below) and I don’t see any difference in this script below and what you put in your message back to me. What edit did you do?
Global Name
GetText “What is first name?”, Name
Find «Firstname» BEGINSWITH Name
if (not info(“found”))
beep
message "No such name!"
endif

My first instinct was was that Panorama 6 also required the variable to be defined, but I checked and you are correct, it doesn’t. So I’ve added this to the list!


By the way @rpitcairn, Robert’s example is perfect. Just copy what he’s done exactly. Notice that he has set the Menu Item Keyboard Equivalent to 1.

All variables must be declared. Always define your variables to be as ‘local’ as you can. That way, you will not have conflict with accidental use elsewhere, especially if you are going to use simple naming such as ‘Name’. A Global variable will hang around through use during the running of other procedures, even when you are running procedures in other database files!!!

An even better variable naming scheme would be…

Local lName

; That was a lower case L in front of ‘Name’ for ‘local’. My using a lower case letter tells me the scope
; of the variable prior to the actual friendly name and this will remind you what the scope is at a later date.
; If you need a Global variable, it would be call ‘gName’.

There is no need to maintain the variables value after you have run your procedure. Declare it, Define it, Use it, then allow it to go away. The next time you need it, your code will go through the necessary process to get you what you want.

Your ‘Find’ code would select users with the name ‘Bobby’ when you have entered ‘Bob’ in your GetText message box. Thus I changed the error response text to read ‘No name starts with your entry.’

Robert Ameeti