I have a pagepanel control with multiple pages each containing textfields in which numbers can be entered. If I place a button (called calculate for the purposes of this query) in the same window but outside the pagepanel, I can use it to execute some code which takes the values of the various textfields and uses them in a number of equations to produce a result which is displayed in another textfield outside the page panel. My desire, however, is to place the calculate button and the output textfield in one of the pages of the page panel. When I do this I get a NAN (not a number) error. When I tracked this down I found that it was not recognising the textfields from other pages in the page panel. Does anybody know how I can fix this?
How do you talk to the textfield in the other page?
I just tried to place a button on page zero and a textfield on page 1. Here is what I do :
Sub Action()
TextField1.Text = "Test"
End Sub
When I click the button it changes the text in the TextField on the other page, so when I go to Page 1 the text has been changed. No error. As far as I can figure all controls in a PagePanel have access to each others like if they where on the same page.
The NaN error does not look like the kind of error you would get from an unrecognized control. It would be more like “This item does not exist”. Are you performing some mathematical operations which result you try to display in the TextField ? That seems more likely a NaN would occur in such code.
See http://documentation.xojo.com/index.php/Single where NaN is described for instance as occurring when an attempt is made to get the square root of a negative number.
I am performing a mathematical operation which will result in the display of the output in the textfield. The reason why I believe that it not reading the content of a textfield on another page is because when I run the code, the variable used in calculation is shown as zero in the debugging window. A simplified example of my code is as follows:
Dim x as double
Dim y as double
Dim z as double
x = val(textfield1.text) //on different page
y = val(Textfield2.text) //on different page
z = x * y
Textfield3.text = Format(z, “##0”)
The language reference recommends you use CDbl for handling numeric values you get from the user. That may help since your simplified example looks like it should work otherwise.
Are you guessing that the TextField is not being read properly because the value is 0? A better reason for why the value could be 0 is that it may contain a text character that is causing the text to get converted to 0 when the Val function is used.
You should instead assign TextField1.Text and TextField2.Text to string variables so you can easily see exactly what they are in the debugger.
[quote=115506:@Peter Scott]I am performing a mathematical operation which will result in the display of the output in the textfield. The reason why I believe that it not reading the content of a textfield on another page is because when I run the code, the variable used in calculation is shown as zero in the debugging window. A simplified example of my code is as follows:
Dim x as double
Dim y as double
Dim z as double
x = val(textfield1.text) //on different page
y = val(Textfield2.text) //on different page
z = x * y
Textfield3.text = Format(z, “##0”)[/quote]
As others have written, the issue maybe more a question of the way you turn the string into numeric. The first thing I would try is to get the string out of the TextFiel and show it in a msgbox or through system.debuglog. Then if you see the string you know the issue is not the control. Anyway, it is impossible to get a NaN from an unrecognized control.
Thanks everyone for your assistance. I followed Paul’s recommendation and found the problem as he described.
Text character in the field, right ?