📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
WindowState = 2 'Maximized
Begin VB.CommandButton Command1
Caption = "计算CRC"
Height = 615
Left = 3600
TabIndex = 4
Top = 960
Width = 1695
End
Begin VB.TextBox Text1
Height = 2535
Left = 3360
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Text = "Form1.frx":0000
Top = 2160
Width = 3015
End
Begin MSComDlg.CommonDialog CDlg_File
Left = 1200
Top = 360
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Txt_CJ
Height = 3015
Left = 840
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 1800
Width = 2055
End
Begin VB.CommandButton readtable
Caption = "读取CRC32表"
Height = 615
Left = 840
TabIndex = 0
Top = 960
Width = 1815
End
Begin VB.Label Label2
Caption = "输入的字符串及生成CRC码:"
Height = 375
Left = 3480
TabIndex = 3
Top = 1800
Width = 2535
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Table_CRC(0 To 255) As Long '生成表
Public Function CRC32(aData() As Byte, ByVal aSize As Long) As Long
Dim i As Long, t1 As Long, t2 As Long, nAccum As Long
nAccum = 0
For i = 0 To aSize - 1
t1 = (nAccum And &H7FFFFF) * &H100
t2 = (nAccum) / &H1000000
nAccum = t1 Xor (Table_CRC((t2 Xor aData(i)) And &HFF))
Next i
CRC32 = nAccum
End Function
Private Sub Command1_Click()
Dim str1, str2 As String, i As Integer
Dim data(0 To 10) As Byte, t As Byte, k, j As Integer
k = 0
j = 0
For i = 0 To 9
data(i) = i + 48
Next i
t = data(k)
data(k) = data(j)
data(j) = t
Text1.Text = CRC32(data(), 10)
End Sub
Private Sub readtable_Click()
'==================================导入CRC32表的数据
Dim i As Long, j As Long, k As Long
Dim str1 As String, str2 As String, str3 As String, str4 As String
Dim File_No As Integer, strData
str1 = App.Path
str2 = "数据文件(*.txt)|*.txt"
With CDlg_File
.InitDir = str1
.FileName = ""
.DialogTitle = "打开"
.CancelError = False
.Filter = str2
.Flags = &H1004
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
str3 = .FileName
End With
On Error Resume Next
'--------------------------------------------------------
File_No = FreeFile(1)
Open str3 For Input As #File_No
str4 = ""
For i = 0 To 255
Line Input #File_No, str1
strData = Split(str1, ",")
str2 = strData(0)
Table_CRC(i) = strData(1)
str4 = str4 + str2 + " " + Str(Table_CRC(i)) + vbCrLf
Next i
Txt_CJ.Text = str4
Close #File_No
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -