2 Replies Latest reply on Apr 3, 2018 10:06 AM by tlucazea

    Piputvalx returns a "Must use reference to a value" message, need help

    tlucazea

      Good morning,

      After applying the PIputvalx macro, the message "Must use reference to a value" is appearing.

      No data is implemented in my tags.

      Need help to solve it, I don't find how to do.

       

      Thanks in advance

        • Re: Piputvalx returns a "Must use reference to a value" message, need help
          tramachandran

          When calling PIPutValX, ensure are you passing a cell reference to the cell containing the value instead of the value itself. Make sure the cell ranges are input correctly.

          The file PIexam64.xls is located at Program Files\PIPC\Excel. You can use this for testing and as a template.

            • Re: Piputvalx returns a "Must use reference to a value" message, need help
              tlucazea

              Thanks for your help,

               

              Using exactly the Piexam64.xls vba, it is not returning any info back (empty cell after running).

              I don't understand what is wrong

               

                'The following four variables are arguments to PIPutVal()
                 Dim sTagname As String  'Tagname
                 Dim stime As String     'Timestamp
                 Dim valueCell As Range  'Cell reference containing value to be written
                 Dim resultCell As Range 'Cell reference to hold result
                 Dim sServer3 As String   'PI3 server name
                 Dim apierr As Long
                 Dim rowstr As String
                 Dim buf As String
                 Dim Timeval As Double
                
                 Dim macroResult As Variant
                 Dim timeCell As Range 'Cell reference to hold time of putval
                  
                 'timestamp is in row 11, column 7 (cell G11)
                 If (IsNumeric(Worksheets("data").Cells(11, 7))) Then
                     Timeval = Worksheets("data").Cells(11, 7).Value
                     stime = Format(Timeval)
                 Else
                     stime = Worksheets("data").Cells(11, 7).Text
                 End If

                 'server is in G1
                 sServer3 = Worksheets("data").Cells(11, 1).Text
                
                    'resultCell is in row 15, column 7
                    Set resultCell = Worksheets("data").Cells(15, 7)
                    'valueCell is in row 13, column 7
                    Set valueCell = Worksheets("data").Cells(13, 7)
                    'tagname is in row 2, column 7
                    sTagname = Worksheets("data").Cells(2, 7).Text
                    'use the timestamp entered by user
                    stime = Worksheets("data").Cells(11, 7).Text
                   
                    'Call the PIPutVal() macro function
                    'Note that we pass just a , for the PIServer argument; i.e., we
                    'are using the default PIServer
                    macroResult = Application.Run("PIPutValx", sTagname, valueCell, stime, sServer3, resultCell)
                    'move down to the row number