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

📄 frmtiaoshi.frm

📁 CRC16效验码计算,很方便计使用,在MODBUS通讯中比较有用
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FRMTIAOSHI 
   Caption         =   "调试"
   ClientHeight    =   6780
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8610
   LinkTopic       =   "Form1"
   ScaleHeight     =   6780
   ScaleWidth      =   8610
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   11
      Left            =   5040
      TabIndex        =   29
      Text            =   "58"
      Top             =   2640
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   10
      Left            =   3720
      TabIndex        =   28
      Text            =   "58"
      Top             =   2640
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   9
      Left            =   2400
      TabIndex        =   27
      Text            =   "58"
      Top             =   2640
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   8
      Left            =   1080
      TabIndex        =   18
      Text            =   "58"
      Top             =   2640
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   7
      Left            =   5040
      TabIndex        =   17
      Text            =   "58"
      Top             =   1800
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   6
      Left            =   3720
      TabIndex        =   16
      Text            =   "58"
      Top             =   1800
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   5
      Left            =   2400
      TabIndex        =   15
      Text            =   "58"
      Top             =   1800
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   4
      Left            =   1080
      TabIndex        =   14
      Text            =   "58"
      Top             =   1800
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   495
      Left            =   5040
      TabIndex        =   6
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text5 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   960
      TabIndex        =   5
      Text            =   "3"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text6 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3000
      TabIndex        =   4
      Text            =   "Text6"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   0
      Left            =   1080
      TabIndex        =   3
      Text            =   "1"
      Top             =   960
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   1
      Left            =   2400
      TabIndex        =   2
      Text            =   "90"
      Top             =   960
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   2
      Left            =   3720
      TabIndex        =   1
      Text            =   "2"
      Top             =   960
      Width           =   1095
   End
   Begin VB.TextBox Text1 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Index           =   3
      Left            =   5040
      TabIndex        =   0
      Text            =   "58"
      Top             =   960
      Width           =   1095
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据12"
      Height          =   195
      Index           =   11
      Left            =   5400
      TabIndex        =   26
      Top             =   2400
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据11"
      Height          =   195
      Index           =   10
      Left            =   3840
      TabIndex        =   25
      Top             =   2400
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据10"
      Height          =   195
      Index           =   9
      Left            =   2520
      TabIndex        =   24
      Top             =   2400
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据9"
      Height          =   195
      Index           =   8
      Left            =   1200
      TabIndex        =   23
      Top             =   2400
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据8"
      Height          =   195
      Index           =   7
      Left            =   5400
      TabIndex        =   22
      Top             =   1560
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据7"
      Height          =   195
      Index           =   6
      Left            =   3960
      TabIndex        =   21
      Top             =   1560
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数6"
      Height          =   195
      Index           =   5
      Left            =   2640
      TabIndex        =   20
      Top             =   1560
      Width           =   270
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据5"
      Height          =   195
      Index           =   4
      Left            =   1320
      TabIndex        =   19
      Top             =   1560
      Width           =   450
   End
   Begin VB.Label Label4 
      Caption         =   "Label4"
      Height          =   375
      Left            =   1560
      TabIndex        =   13
      Top             =   5040
      Width           =   495
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据1"
      Height          =   195
      Index           =   0
      Left            =   1320
      TabIndex        =   12
      Top             =   720
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据2"
      Height          =   195
      Index           =   1
      Left            =   2640
      TabIndex        =   11
      Top             =   720
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据3"
      Height          =   195
      Index           =   2
      Left            =   3960
      TabIndex        =   10
      Top             =   720
      Width           =   450
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "数据4"
      Height          =   195
      Index           =   3
      Left            =   5400
      TabIndex        =   9
      Top             =   720
      Width           =   450
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "数的个数"
      Height          =   195
      Left            =   1320
      TabIndex        =   8
      Top             =   3720
      Width           =   720
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "Label3"
      Height          =   195
      Left            =   3000
      TabIndex        =   7
      Top             =   3600
      Width           =   480
   End
End
Attribute VB_Name = "FRMTIAOSHI"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim XMT(0 To 12)
Dim CT, CH, CL, C1, C2 As Integer
Dim i, j, N As Integer
Dim CRC16, CRCTMP As Long


'CRCTMP = &H1
'Label4.Caption = CRCTMP / 2
CRCTMP = &HFFFF
N = Text5.Text
For i = 1 To N
XMT(i) = "&H" & Text1(i - 1).Text   '&H表示16进制
Next i

For i = 1 To N
 CRCTMP = CRCTMP Xor XMT(i)
  For j = 1 To 8
   CT = CRCTMP And &H1                   '和1求与看最后一位是不是0,
    CRCTMP = Int(CRCTMP / 2)
    CRCTMP = CRCTMP And &H7FFF
    If CT = 1 Then
    CRCTMP = CRCTMP Xor &HA001
    CRCTMP = CRCTMP And &HFFFF
    End If
  Next j
 Next i
 
 C1 = CRCTMP And &HFF
 C2 = (CRCTMP And &H7F00) / 256
' If CL = 1 Then C2 = C2 Or &H80
 Text6 = Hex$(C1) & "/" & Hex$(C2)
 Label3.Caption = CRCTMP
End Sub


⌨️ 快捷键说明

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