PDA

View Full Version : ui_get_text2 Question


ABC123

clafean
11-29-2014, 08:29 PM
I am trying to use ui_get_text2 to get a text string from the user and capture the cancel button. Here is a snippet

'DIM POM_Jobnum as c
POM_Jobnum = ui_get_text2("Job Number?","Enter the job number to load: ","","","14")
status = POM_Jobnum.lastbutton
showvar(status)

With the variable POM_Jobnum remarked out this works and status = "cancel"- which I believe is the way ui_get_text2 is supposed to work.

However, as soon as I dim the variable POM_Jobnum, it stops working. I typically work in an OPTION STRICT mode, so just not dimming the variable is an uncomfortable option.

What am I doing wrong?

clafean
11-29-2014, 08:41 PM
Just answered my own question:

dim request as a
DIM POM_Jobnum as c
'DIM lastbutton AS C
request = ui_get_text2("Job Number?","Enter the job number to load: ","","","14")
if request.lastbutton = "cancel" then
msgbox("Cancel pressed")
end
end if
showvar(status)
POM_Jobnum = request.value
showvar(POM_Jobnum)

Given the lack of documentation about ui_get_text2, I can only assume that this is working because it is right.

MoGrace
11-30-2014, 05:17 PM
If the cancel button is chosen then the return value is blank. Test for that condition first and end, else set the var.

request = ui_ get_text2(...)
if request = "" then
'user cancelled
end
else
yourvar = request
end if

Tim Kiebert
11-30-2014, 06:51 PM
Chuck, (and Robin)
ui_ get_text() returns a character value but ui_ get_text2() returns a pointer value.
That is why in the snippet on post 1 when the dim statement is uncommented the code fails. The result of ui_ get_text2() is trying to be placed into a character instead of a pointer. With the dim statement commented out POM_Jobnum gets implicitly set as a pointer by ui_get_text2(). So to get that code to work all you need to do is dim POM_Jobnum as P.

The code in post 2 works because you dimmed request as 'a' which allows request to receive the pointer data.
It is possible to click 'OK' and return an empty string if nothing was entered so you should still follow Robin's advice and check for an empty value unless that is allowed in your situation.

The benefit of using the '2' version is that we can check which button was actually pressed with out relying on the contents of the returned value. So if the user clicks OK with out entering something you can inform them with an error message and may be loop back to redisplay the dialog.

MoGrace
11-30-2014, 09:04 PM
Answering posts from my iPad always leaves me embarrassed. i should know better...if I had access to the program I would have checked it myself first.

clafean
12-02-2014, 11:12 AM
Tim and Robin,

Thank you for the help. In this particular case, the snippet I provided is wrapped in a while statement that is testing for input length so a blank entry is handled in a different way. Tim, your explanation is fantastic; I find it interesting that there is no entry for ui_get_text2 in any help source I have looked in.

Anyway,

Thanks again.

Chuck

Al Buchholz
12-02-2014, 04:28 PM
I find it interesting that there is no entry for ui_get_text2 in any help source I have looked in.


Not all documentation is in the help files. Just a fact.

Look in the release notes to see additional information including the ui_get_text2().

http://downloads.alphasoftware.com/A5V11Download/releasenotes.html

Tim Kiebert
12-02-2014, 06:13 PM
Chuck, your welcome

Al, thanks for the link.

While checking the release notes that Al referred us to I noticed something about the value that is returned when the Cancel button is clicked. This may not be news to some but thought I would bring it up here. So far we have been discussing checking for an empty string as an indication that the Cancel button was pressed. However, if you provide a default value then that value is returned when the Cancel button was pressed. This is also true for ui_get_text().

So the test should not be for an empty string but rather it should be for the default value specified in the function. (which may often be an empty string)