Example Script : Excel Access Script
Accessing Excel from the Script :


'This script creates an Excel file and writes data to sequential rows.

Imports System                        'Importing necessary classes.
Imports System.IO
Imports System.Windows.Forms
Imports Microsoft.VisualBasic

Namespace WinTr

Public Class MainClass

         Public Sub Load     'Load procedure is defining.
                                       'Script starts working within this procedure.
                                       'WinTr tags should be accessed from this procedure.
                                       'When this procedure finished working
                                       'WinTr tags can not be reached anymore from this script.

          '------- Script Start Line -------

               'Excel application object is defining.
           Dim Ex As Microsoft.Office.Interop.Excel.Application  
           Dim i As Integer

                'New Excel application is creating within the object.
           Ex = New Microsoft.Office.Interop.Excel.Application 
           Ex.Workbooks.Add()                 'Excel workbook is being created.
           Ex.Worksheets(1).cells(1, 1).value = "No"'Excel cells is being written.        
           Ex.Worksheets(1).cells(1, 2).value = "Date"
           Ex.Worksheets(1).cells(1, 3).value = "Level"

           For i = 0 To 10        ' for loop is created.

               'values are written to sequental Excel rows.
                    Ex.Worksheets(1).cells(i + 2, 1).value = i   

                    Ex.Worksheets(1).cells(i + 2, 2).value = i+1

                    Ex.Worksheets(1).cells(i + 2, 3).value = i+2

           Next

           Ex.Visible = True 

          '------- Script End Line -------

         End Sub

End Class

End Namespace


                                                                                                                                                                       Excel Access Script


'This script writes Tag's data to open Excel file.
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports Microsoft.VisualBasic

Namespace WinTr

Public Class MainClass

'Variables that will read and write WinTr tags should be defined as Public.
Public Tag_1 As Uint16           
Public Tag_2 As Uint16

Public Sub Load

          Try
            Dim exl As Object
            exl = GetObject(, "Excel.Application"

'object is created which will write opened "C:\Test.xls" file.
            exl = GetObject("C:\Test.xls")              
            Tag_2 +=1

'Tag_1's value is written to first column of Tag_2 indicated row.
            exl.Worksheets(1).cells(Tag_2, 1).value = Tag_1  

            exl.save()

         Catch ex As Exception 

            MessageBox.Show(Ex.ToString,Ex.Message)

            MsgBox("C:\Test.xls isn't open!")

        End Try

End Sub      

End Class

End Namespace






       
                                                        Another Method


                                                                                                                                                                               English                Turkish
Scada System        Scada Software        Free Scada            What is Scada
SCADA SOFTWARE