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

📄 main.frm

📁 用于ERP系统和PLC控制器之间的数据交互
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form Frm_Main 
   Caption         =   "生产计划下载"
   ClientHeight    =   5310
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9315
   Icon            =   "main.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5310
   ScaleWidth      =   9315
   StartUpPosition =   3  '窗口缺省
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   330
      Left            =   7095
      Top             =   2535
      Visible         =   0   'False
      Width           =   1620
      _ExtentX        =   2858
      _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            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Timer Timer_plus 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   7080
      Top             =   465
   End
   Begin VB.Label L_CX 
      Caption         =   "Label2"
      Height          =   270
      Left            =   1515
      TabIndex        =   1
      Top             =   825
      Width           =   840
   End
   Begin VB.Label Label1 
      Caption         =   "MUB20"
      Height          =   240
      Left            =   810
      TabIndex        =   0
      Top             =   840
      Width           =   540
   End
End
Attribute VB_Name = "Frm_Main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1

Dim WithEvents AnOPCServer As OPCServer
Attribute AnOPCServer.VB_VarHelpID = -1
Dim WithEvents ConnectedOPCServer As OPCServer
Attribute ConnectedOPCServer.VB_VarHelpID = -1
Dim ConnectedServerGroup As OPCGroups
Dim WithEvents ConnectedGroup As OPCGroup
Attribute ConnectedGroup.VB_VarHelpID = -1

Dim OPCItemCollection As OPCItems
Dim OneOPCItem As OPCItem
Dim ItemCount As Long
Dim OPCItemIDs(10) As String
Dim ItemServerHandles() As Long
Dim ItemServerErrors() As Long
Dim ClientHandles(10) As Long
Dim Server_Name As String
Dim Node_Name As String
Dim Tag_Name(50) As String
Dim Tag_Count As Integer  'Tag_Count <=50

Public Sub Connect_OPCServer()
    Dim ConnectedServerName As String
    Dim ConnectedNodeName As Variant


    On Error GoTo ShowOPCConnectError
    Set ConnectedOPCServer = New OPCServer
    
    ConnectedServerName = OPCServerName.Text
    ConnectedNodeName = OPCNodeName.Text
    
    ConnectedOPCServer.Connect ConnectedServerName, ConnectedNodeName
        
    GoTo SkipOPCConnectError
    
ShowOPCConnectError:
    Set ConnectedOPCServer = Nothing
    Call DisplayOPC_COM_ErrorValue("Connect", Err.Number)
SkipOPCConnectError:

End Sub

Sub DisplayOPC_COM_ErrorValue(OPC_Function As String, ErrorCode As Long)
    Dim Response
    Dim ErrorDisplay As String
    ErrorDisplay = "The OPC function '" + OPC_Function + "' has returned an error of " + Str(ErrorCode) + " or Hex 0x" + Hex(ErrorCode)
    Response = MsgBox(ErrorDisplay, vbOKOnly, "OPC Function Error")
End Sub

Public Sub Read_Paramater()

End Sub

Private Sub Form_Load()
  Dim Connect_Str, SQL_Str As String
  Dim adocon As New ADODB.Connection
  Dim DB_rs As New ADODB.Recordset
  
  Connect_Str = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password = sa;Initial Catalog=Plan;Data Source=TURCK_L"
  adocon.Open Connect_Str '连接到数据库
  
  SQL_Str = "table1"
  DB_rs.Open SQL_Str, adocon, adOpenDynamic, adLockOptimistic, adCmdTable
  
  Set DB_rs = Nothing
  adocon.Close
  
End Sub

⌨️ 快捷键说明

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