hexagon logo

GetVariableValue Problem

Dear guys:

about the method "GetVariableValue",the help file says like this--PC-DMIS variables only hold values during execution; at learn time PC-DMIS variables have a value of zero. The GetVariableValue and SetVariableValue methods only change a variable's value during the script's execution. If you want to permanently change a value of a variable inside PC-DMIS, you should use the PutText method instead.

when my mouse enter the parameter,it shows the result on the screen.but how can i get that value?(offline software,but the program has been run before)



string ReturnValue="";
Variable tmpVarValue;
pcdPartProgram = pcdSession.ActivePartProgram;
tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
{
ReturnValue = tmpVarValue.StringValue;
}
else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
{
ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
}
else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
{
ReturnValue = tmpVarValue.LongValue.ToString("F3");
}

then i get 0.000,whie the shown result is -0.071.and i wanna get the value -0.071



Parents
  • Can't see the tiny screenshot btw.



    Have you checked you are catching the Type properly?

    string ReturnValue="";
    Variable tmpVarValue;
    pcdPartProgram = pcdSession.ActivePartProgram;
    tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
    if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
    {
    messagebox.show("String")
    ReturnValue = tmpVarValue.StringValue;
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
    ​​​​​​​messagebox.show("Double")
    {
    ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
    ​​​​​​​messagebox.show("Long")
    {
    ReturnValue = tmpVarValue.LongValue.ToString("F3");
    }

    Have you tried it at runtime?
Reply
  • Can't see the tiny screenshot btw.



    Have you checked you are catching the Type properly?

    string ReturnValue="";
    Variable tmpVarValue;
    pcdPartProgram = pcdSession.ActivePartProgram;
    tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
    if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
    {
    messagebox.show("String")
    ReturnValue = tmpVarValue.StringValue;
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
    ​​​​​​​messagebox.show("Double")
    {
    ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
    ​​​​​​​messagebox.show("Long")
    {
    ReturnValue = tmpVarValue.LongValue.ToString("F3");
    }

    Have you tried it at runtime?
Children
No Data