I want a part of a procedure that will ask for a specific value for one field out of a larger group of records. I could have a separate procedure for each one of the values I want to select in this field, but I suspect there is a phrasing that would ask for me to type in the value for the records I want to select. How would I write that in a procedure?
The simplest way to get user entry is with the gettext statement. Use the value entered to make a selection with the select statement.
If the number of selection values in the group of records is not so many as to make it cumbersome, you could make a list of the values using the arraybuild( and probably the arraydeduplicate( functions, and display the list using a superchoicedialog statement for the user to choose a value from. The advantages of this approach are that the user doesn’t have to enter a value, and the programmer doesn’t have to handle wrong entries.
Thanks, but I am not sure what a lot of those terms mean. I am the programmer and the end user, so no one else is involved. It is not a problem for me to enter which particular records I want.
Here is the procedure as written so far.
field Quarter
sortup
select «Quarter(Text)» = “Fall 2024”
field Program
sortup
groupup
field Program
count
total
openform “Student List by Quarter”
printpreview
How would I write the procedure to ask me to enter a value, like Fall 2024?
Thanks for spending your time thinking about this…
let Choice = ""
gettext "Which quarter and year (eg, Fall 2024)?",Choice
ifselect «Quarter(Text)» = Choice
else
alertok Choice+" not found in Quarter field"
stop
endif
field Program
sortup
groupup
field Program
count
total
openform “Student List by Quarter”
printpreview
Here’s a slight variation on David’s procedure, which does the same thing; he beat me to it:
Replace your select statement with:
let lvQuarter=""
gettextdialog lvQuarter,
"Prompt","Enter the quarter and year: ",
"Width",120
Select «Quarter(Text)» = lvquarter
if info("empty")
alertsheet "No records found for quarter "+lvquarter
rtn
endif
Adding the indented lines just makes the code easier to read. I don’t think that the total statement will do anything. Total only operates on numeric fields.
I am not sure which of those words should be inserted in place of the select line. When I paste in the entire thing irt says Choice field or variable not found.
I suspect there is a convention you are using in making these suggestions that I do not understand. I am sorry , this must be very frustrating for you to attempt to help me…
Make sure the variable name Choice is spelt exactly the same way in the rest of the procedure as it’s spelt in the Let statement line, it is case sensitive.
Chuckie, there were some hidden formatting characters added by forum software to the code I sent you that prevented my code from working when you pasted it into Panorama. Here’s clean code you should be able to copy and paste reliably into a procedure.
field Quarter
sortup
let myChoice = “”
gettext “Which quarter and year (eg, Fall 2024)?”,myChoice
ifselect «Quarter(Text)» = myChoice
else
alertok myChoice+" not found in Quarter(Text) field"
stop
endif
field Program
sortup
groupup
field Program
count
total
openform “Student List by Quarter”
printpreview
I’ve changed the local variable name to myChoice to make it clearer that this is a name I defined or declared with the LET statement (let myChoice = “”). A variable is a place you can create to store a value in and recover a value from, the data in this case being the quarter and year requested. Tom’s variable name was lvQuarter. Read Panorama’s excellent introduction to variables in Help under “Variables”. Once you get the hang of them you’ll end up using variables all the time.
That is the name of a variable, which is essentially a storage locker for temporarily storing an item of data. @CooperT made up this name, it could be anything but you have to use the exact same name every you reference a variable. Here’s the help page about variables.
No, this is not true. You cannot ever calculate a total for a text field. That’s why the code would not run when you included the Total command.
The best way to include code in this forum is to indent it by 4 spaces. Then it will format nicely. If the code is already in a Panorama procedure, you can use the Source>Copy Indented Code menu command to easily copy your code with this indent applied.
If you are typing the code straight into the forum, you have to type the 4 spaces yourself manually.
Chuckie, here’s the code again, properly indented for you to copy, as Jim specifies.
field Quarter
sortup
let myChoice = “”
gettext “Which quarter and year (eg, Fall 2024)?”,myChoice
ifselect «Quarter(Text)» = myChoice
else
alertok myChoice+" not found in Quarter(Text) field"
stop
endif
field Program
sortup
groupup
field Program
count
total
openform “Student List by Quarter”
printpreview
There are a couple of ongoing minor issues with this code that I think go back to Chuckie’s original code.
field Program
sortup
groupup
The sortup is unnecessary, because groupup automatically performs a sortup. It doesn’t cause any problem, just wastes a little bit of time.
field Program
count
total
The field statement is unnecessary, because Panorama is already on the Program field.
Most likely the Program field is not numeric. So the total statement will not work.
If the Program field is numeric, then using the total statement immediately after count will just wipe out the count. So the count would be superfluous.