hexagon logo

Is there a way to access a PC-DMIS array variable from PC-DMIS Basic?

Is there a way to access a PC-DMIS array variable from PC-DMIS Basic? The Help for GetVariableValue() doesn't mention arrays and indices.
  • Is that helps ? (from PCDBASIC 3.6)

    Variable.GetArrayUpperBound
    Syntax
    Return Value=expression.GetArrayUpperBound
    Return Value: This returns the upper bound if the variable is an array. Otherwise it
    returns zero.
    expression: required expression for object type Variable.


    Variable.GetArrayLowerBound
    Syntax
    Return Value=expression.GetArrayLowerBound
    Return Value: This returns the lower bound if the variable is an array. Otherwise it
    returns zero.
    expression: required expression for object type Variable.

    Variable.GetArrayIndexValue
    Syntax
    Return Value=expression.GetArrayIndexValue
    Return Value: This returns the array variable at the specified index position.
    expression: required expression for object type Variable.

    Variable.SetArrayIndexValue
    Syntax
    Return Value=expression.SetArrayIndexValue (Index, Variable)
    Return Value: This sets the array variable at the specified index position. Type
    Boolean.
    expression: required expression for object type Variable.
    Index: Long value specifying the index
  • Yes, found them in the Type Library, but still not sure how to get at them. Experimenting...

    OK, this seems to work! But GetArrayUpperBound returns the number of elements + 1, and it took a while to find the .PointValue which is necessary to get at the parts (XYZ) of the indexed value.

    Thanks!

    
    Sub Main
      Dim App As Object 
      Set App = CreateObject ("PCDLRN.Application")
      Dim Part As Object
      Set Part = App.ActivePartProgram
      Dim Var As Object
      Dim i_var As Object
    
      Set Var = Part.GetVariableValue ("PT")
      MsgBox Var.GetArrayUpperBound
      Set i_var = var.getarrayindexvalue(2).PointValue
      MsgBox i_var.x
    
    End Sub
    
    


  • GetArrayUpperBound returns the number of elements + 1


    You should try something like Option Base 1 at the start.
  • Doesn't affect anything. Probably only valid for BASIC arrays, not PC-DMIS ones.

    But maybe "Upper Bound" means "the first index that is not addressable", instead of the expected "the last index that is addressable" (or GetArrayLowerBound + <number of elements>Wink

    Anyway, it isn't important as long as it's consistent.
  • Sub Main()
    
      Dim App As PCDLRN.Application
      Set App = CreateObject("PCDLRN.Application")
      Dim Part As PCDLRN.PartProgram
      Set Part = App.ActivePartProgram
      Dim Var As PCDLRN.Variable
      Dim i_var As VariableArray
    
      Set Var = Part.GetVariableValue("PT")
      MsgBox Var.VariableType
    
    End Sub
    


    Output = 5.
    5 = VARIABLE_TYPE_ARRAY (according to the PCDLRN Object Library).

    What gives? It recognizes it as an array but can't manipulate it as one?
  • Every [to me] imaginable way gave "Error: Type mismatch". Doesn't mean there isn't any way to do it, but I couldn't find out how.