hexagon logo

Downloading the Assignment and saving the values in excel

I have a problem with the code, saving to excel works, but getting the value from assignment V1 causes an error


Sub Main()

Dim objExcel As Object
Dim objWorkbook As Object
Dim objWorksheet As Object

'Nazwa pliku Excel
Dim excelFileName As String
excelFileName = "Excel.xlsx"

'Ścieżka Do pliku Excel
Dim excelFilePath As String
excelFilePath = "T:\Kontrola_jakosci\PC-DMIS\Damian\" & excelFileName

'Jeśli plik Excel nie istnieje, utwórz nowy plik
If Dir(excelFilePath) = "" Then
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Add
    Set objWorksheet = objWorkbook.Sheets(1)

Else
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open(excelFilePath)
    Set objWorksheet = objWorkbook.Sheets(1)
End If

Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Part As Object
Set Part = App.ActivePartProgram
Dim Var As Object
Set Var = Part.GetVariableValue ("V1")

Dim i As Integer
objWorksheet.Cells(1, 1 ).Value =   "Wymiar x"

i = 1
Do Until objWorksheet.Cells(i,1).Value = empty
i = i +1
Loop

objWorksheet.Cells(i, 1 ).Value  =  Var


objWorkbook.Save
objWorkbook.Close

objExcel.Quit
Set objExcel = Nothing
Set objWorksheet = Nothing
Set objWorkbook = Nothing
End Sub​


Parents
  • Good day,

    "long" belongs to group of integers (no decimal range)

    "LOC2.D.MEAS" looks like a "Double" though

    try "Var.DoubleValue", that should work​


    PS:
    you can also use a script to read data directly from a dimmension-command (your "LOC2" is a dimmension-command).
    the detour via the variables is possible but unnecessarily prolonged
    there are a few examples in the code example section
Reply
  • Good day,

    "long" belongs to group of integers (no decimal range)

    "LOC2.D.MEAS" looks like a "Double" though

    try "Var.DoubleValue", that should work​


    PS:
    you can also use a script to read data directly from a dimmension-command (your "LOC2" is a dimmension-command).
    the detour via the variables is possible but unnecessarily prolonged
    there are a few examples in the code example section
Children
No Data