I have created a .pdi in which i need to enter real numbers in 2 textboxes then on clicking submit button i need to show a calculation performed on those two textbox values in third textbox. How to to get it done?
In VBA, you can access the string contents of a ProcessBook Text symbol by using TextSymbolName.Contents (after right clicking on it in build mode > Enable Scripting). For example: Text1.Contents
you can access the string contents of a Microsoft Forms 2.0 TextBox using TextBoxSymbolName.Text
To convert a string to a double, you'll need to use the built in VBA function CDbl
To handle the button click, you can set the button to execute a new macro:
typing in the name you want and hitting 'create':
Using a macro will put you in the Modules section of the VBA project, as opposed to the ThisDisplay page directly;
so you'll have to reference the symbols in the display by explicitly calling out the display it's in:
ThisDisplay.TextBox1.Text for example
In this macro, you can perform the necessary calculation, and use either .Contents or .Text, depending on the type of text symbol you're using, to display the value in the third box. This command will implicitly convert the double to a string, so you don't need to manually cast it before setting it.
Thanks a lot Kelsey Duffy for the help.
As I have no idea how to code in VB, I tried to code this as below but getting runtime error '424'. For your reference I am attaching my VB code and .pdi. Pls guide.
If you already have the two inputs coming in as PI tags or AF attributes, then I would strongly suggest using an AF analysis, or if necessary a performance equation, to hold the calculation output. This analysis would be an attribute, and could therefore be brought into any display on any visualization client, and if you migrate from ProcessBook to Vision, you will not have to start over (VBA code is stripped out when ProcessBook displays are rendered in or migrated to PI Vision.
There are also a number of security concerns for VBA code being enabled in general that this analysis approach will get around, in addition to the overheard of learning how VBA works and should be implemented.
As for the code that's written already, the code in Display_Open isn't executing anything, and the code is calculate() is not correctly referencing the textboxes; the calculate code needs to reference ThisDisplay.TextBox1.Text, or the Display_Open() code needs to perform a calculation (but then that calculation would only be performed when the display is opened). Also, the .Contents property is for ProcessBook text symbols, but it looks like you're using microsoft forms 2.0 textboxes, which need to be referenced by .Text. Lastly, in order to perform division on the numbers, you'll need to cast the strings as doubles, meaning that you would need to say something like CDbl(ThisDisplay.TextBox1.Text).
In general, I would strongly suggest doing these calculations in the form of an AF Analysis.
Dear Mr. Kelsey,
On referring ThisDisplay.TextBox1.Text in calculate() , I could be able to do the required calculation in my .pdi.
Thanks a lot.
Retrieving data ...