Below is some example Origin C code that addresses both of your questions.
1) Provides an example of how to create a nice dialog box to accept a number entered by user.
2) Divides the values in a column by the number user entered.
It assumes you have an active worksheet with data in column 2.
#include <Origin.h>
#include <GetNbox.h>
// Function to create dialog box
// dNum parameter is passed by reference to function meaning its value can be changed in function
// Function returns true if user clicks OK in dialog and false if they cancel dialog
bool MyNumDialog(double& dNum)
{
// Origin C macros to build custom dialog
GETN_BOX(tr)
GETN_NUM(dResult, "Enter a Value", dNum) // "Enter a Value" is the label for the actual control. You can change this.
// GetNBox() displays the dialog and returns true if user clicked OK and false if they canceled the dialog.
// Change "Dialog Title" and "Description Text" to whatever you wish
bool bRet = GetNBox(tr, "Dialog Title", "Description Text");
// User clicked OK, so change the variable passed by reference to the function and return true
// If control is empty and OK is clicked, the value is set to 0
if (bRet)
dNum = tr.dResult.dVal;
// Return result of calling GetNBox() (true or false)
return bRet;
}
void MyTestDlg()
{
double dd; // Decimal variable to hold value to divide column by
dd = 1.0; // You can set this to an initial value e.g. 1
// Pass dd variable by reference to dialog function
bool bOK = MyNumDialog(dd);
if (bOK)
printf("User entered: %f \n", dd);
else
{
printf("User cancelled dialog");
return;
}
// Make sure variable wasn't assigned 0- prevent divide by 0!
if(is_equal(0, dd))
{
printf("User entered 0. Cannot divide by 0!!!");
return;
}
// Assumes you have an active worksheet with data in columns 1 & 2
Worksheet wks = Project.ActiveLayer();
// Validate that there is an active worksheet
if (!wks)
{
printf("No active worksheet");
return;
}
// Dataset objects can be used to access column data
// Cols are indexed starting with 0, so 1 is second column
Dataset ds(wks, 1);
// Validate that there is a column 2
if (!ds)
{
printf("No Column 2");
return;
}
// Here is the actual (and simple) code to divide the column by the number user entered.
// It checks to see if there are values in column first
if (ds.GetSize() > 0)
ds /= dd;
}