⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frstatistics.frm

📁 使用 VB 编写访问 WinCC 软件的 SQL server 数据库的代码。
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frStatistics 
   Caption         =   "Statistics from csv file"
   ClientHeight    =   5250
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7830
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   5250
   ScaleWidth      =   7830
   WindowState     =   2  'Maximized
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   90
      Top             =   4740
      Visible         =   0   'False
      Width           =   7575
      _ExtentX        =   13361
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.TextBox txtExportFile 
      Height          =   330
      Left            =   3210
      Locked          =   -1  'True
      TabIndex        =   6
      Text            =   "csv-File"
      ToolTipText     =   "Path and name of the csv file you want to import"
      Top             =   975
      Width           =   4365
   End
   Begin VB.CommandButton cmdExecute 
      Caption         =   "Execute"
      Height          =   375
      Left            =   90
      TabIndex        =   4
      Top             =   1410
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "Select one of the following options"
      Height          =   1170
      Left            =   90
      TabIndex        =   1
      Top             =   150
      Width           =   3000
      Begin VB.OptionButton optTag 
         Caption         =   "Tag statistic"
         Height          =   195
         Left            =   150
         TabIndex        =   3
         Top             =   765
         Width           =   1410
      End
      Begin VB.OptionButton optAlarm 
         Caption         =   "Alarm statistic (Hit list)"
         Height          =   195
         Left            =   150
         TabIndex        =   2
         Top             =   390
         Value           =   -1  'True
         Width           =   1935
      End
   End
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "frStatistics.frx":0000
      Height          =   2880
      Left            =   90
      TabIndex        =   0
      Top             =   1860
      Width           =   7560
      _ExtentX        =   13335
      _ExtentY        =   5080
      _Version        =   393216
      AllowUpdate     =   0   'False
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "WinCC Statistics"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1031
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1031
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Label Label1 
      Caption         =   "Read from CSV file:"
      Height          =   285
      Left            =   3225
      TabIndex        =   5
      Top             =   630
      Width           =   2730
   End
End
Attribute VB_Name = "frStatistics"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' ---------------------------------------------------------------
' Author: RABP        17.06.2003
' Modul : frStatistics
' Abst. : Modul for statistics out of the exported csv file
'       : Alarms- Hit list for alarms with count and duration time
' =================================================================
' Changes:
' AKr       15.12.2004
' Akr       06.12.2004
' =================================================================
Dim m_Mod As Long, sCsv As String
Private Sub checkit()

  Select Case m_Mod

    Case TAGLOGG
      sCsv = g_Path & g_FilT
    Case ALALOGG
      sCsv = g_Path & g_FilA
  End Select
  txtExportFile.Text = sCsv
  
End Sub

Private Sub cmdExecute_Click()

  Err.Clear
  On Error Resume Next

  Dim strPath As String
  Dim strFileName As String
  SplitPathAndFileName txtExportFile.Text, strPath, strFileName
    
  Dim sSQL As String
  
  Select Case m_Mod
    Case ALALOGG ' Alarm Hitlist

      sSQL = " SELECT MsgNr, Count(MsgNr) as CNT, Sum(TimeDiff) AS Total FROM [" & strFileName & "]" & _
             " GROUP BY MsgNr " & _
             " ORDER BY MsgNr"
      
    Case TAGLOGG

      sSQL = "SELECT ValueID, Count(*) as [COUNT],AVG(RealValue) AS [AVG], Min(RealValue) As [MIN], Max(RealValue) As [MAX] FROM [" & strFileName & "]" & _
             " GROUP BY ValueID " & _
             " ORDER BY ValueID"
    
  End Select

  Adodc1.ConnectionString = MakeConnectionString(strPath)
  Adodc1.RecordSource = sSQL
  Adodc1.Refresh

  Set DataGrid1.DataSource = Adodc1.Recordset

  If Err.Number <> 0 Then
    MsgBox "Error has occured. Make sure that the file " & strPath & strFileName & " exists.", 48, "Error"
    Err.Clear
  End If

  On Error Resume Next

End Sub

Private Sub cmdJob_Click(Index As Integer)

End Sub

Private Sub Form_Load()

  CheckSchemaIniFile

  m_Mod = g_Mod
  If m_Mod = ALALOGG Then
    optAlarm.Value = True
  Else
    optTag.Value = True
  End If
  checkit
End Sub

Private Sub optAlarm_Click()
  m_Mod = ALALOGG
  checkit
End Sub

Private Sub optTag_Click()
  m_Mod = TAGLOGG
  checkit
End Sub

Private Function MakeConnectionString(strPath As String) As String

  Dim strConnectionString As String

  strConnectionString = "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _
                        "DBQ=" & strPath & ";" & _
                        "DefaultDir=" & strPath & ";" & _
                        "Uid=Admin;Pwd=;"
  
  MakeConnectionString = strConnectionString
  
End Function

Private Sub CheckSchemaIniFile()

  Const c_str_Schema_Ini = "Schema.ini"
  Dim fso
  Dim strIniFile As String
  
  strIniFile = g_Path & c_str_Schema_Ini
  Set fso = CreateObject("Scripting.FileSystemObject")
  If (fso.FileExists(strIniFile) = False) Then
    WriteSchemaIniFile strIniFile
  End If

End Sub

Private Sub WriteSchemaIniFile(strFile As String)
  
  Dim aIniSections(2)
  Dim i As Integer
    
  aIniSections(1) = g_FilA
  aIniSections(2) = g_FilT

  Open strFile For Output As #1
  For i = 1 To UBound(aIniSections)
    Print #1, "[" & aIniSections(i) & "]"
    Print #1, "ColNameHeader=True"
    Print #1, "Format=Delimited(" & g_c_CSV_Delimiter & ")"
  Next
  Close #1
  
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -