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

📄 -

📁 MODBUS(CRC)校验例程示例1.0版
💻
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Vb数据转换实例"
   ClientHeight    =   3720
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5700
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3720
   ScaleWidth      =   5700
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.Frame Frame1 
      Caption         =   "据浮点数转换为字节数"
      Height          =   3435
      Index           =   1
      Left            =   2880
      TabIndex        =   7
      Top             =   120
      Width           =   2655
      Begin VB.CommandButton Command1 
         Caption         =   "开  始  转  换"
         Height          =   435
         Left            =   300
         TabIndex        =   10
         Top             =   2820
         Width           =   1995
      End
      Begin VB.TextBox Text4 
         Height          =   375
         Left            =   180
         TabIndex        =   9
         Text            =   "220.43"
         Top             =   840
         Width           =   2175
      End
      Begin VB.TextBox Text3 
         Height          =   375
         Left            =   180
         TabIndex        =   8
         Top             =   2220
         Width           =   2175
      End
      Begin VB.Label Label6 
         Caption         =   "转换的字节数据(由低至高)"
         Height          =   255
         Left            =   180
         TabIndex        =   13
         Top             =   1620
         Width           =   2235
      End
      Begin VB.Label Label5 
         Caption         =   "格式如下: 12-00-5C-43"
         Height          =   255
         Left            =   180
         TabIndex        =   12
         Top             =   1860
         Width           =   2055
      End
      Begin VB.Label Label4 
         Caption         =   "请输入浮点数:"
         Height          =   195
         Left            =   180
         TabIndex        =   11
         Top             =   420
         Width           =   1995
      End
      Begin VB.Line Line3 
         BorderColor     =   &H80000009&
         X1              =   0
         X2              =   2640
         Y1              =   1440
         Y2              =   1440
      End
      Begin VB.Line Line4 
         BorderColor     =   &H80000003&
         BorderWidth     =   2
         X1              =   -60
         X2              =   2580
         Y1              =   1440
         Y2              =   1440
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "字节数据转换为浮点数"
      Height          =   3435
      Index           =   0
      Left            =   60
      TabIndex        =   0
      Top             =   120
      Width           =   2655
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   180
         TabIndex        =   6
         Top             =   2160
         Width           =   2175
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   180
         TabIndex        =   4
         Text            =   "12-00-5C-43"
         Top             =   840
         Width           =   2175
      End
      Begin VB.CommandButton Command2 
         Caption         =   "开  始  转  换"
         Height          =   435
         Left            =   240
         TabIndex        =   1
         Top             =   2820
         Width           =   1995
      End
      Begin VB.Line Line2 
         BorderColor     =   &H80000009&
         X1              =   0
         X2              =   2640
         Y1              =   1440
         Y2              =   1440
      End
      Begin VB.Line Line1 
         BorderColor     =   &H80000003&
         BorderWidth     =   2
         X1              =   1
         X2              =   2640
         Y1              =   1440
         Y2              =   1440
      End
      Begin VB.Label Label3 
         Caption         =   "转换后的浮点数为:"
         Height          =   195
         Left            =   180
         TabIndex        =   5
         Top             =   1800
         Width           =   1995
      End
      Begin VB.Label Label2 
         Caption         =   "格式如下: 12-00-5C-43"
         Height          =   255
         Left            =   180
         TabIndex        =   3
         Top             =   600
         Width           =   2055
      End
      Begin VB.Label Label1 
         Caption         =   "请输入字节数据(由低至高)"
         Height          =   255
         Left            =   180
         TabIndex        =   2
         Top             =   360
         Width           =   2235
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'注开始使用前,清将“DataChange.dll”文件拷贝到windows目录下的system中
Private Declare Function InttoFloat Lib "DataChange.dll" (ByRef VbArray As Byte) As Single
Private Declare Sub FloattoInt Lib "DataChange.dll" (ByVal VbSingle As Single, ByRef VbArray As Byte)

'转换后的变量
Dim TmpStr As String
Dim TmpArray(3) As Byte
Dim Tmpf As Single

'浮点数据转换为字节格式
Private Sub Command1_Click()
    Tmpf = Val(Text4.Text)
    FloattoInt Tmpf, TmpArray(0)
    Text3.Text = Format(Hex(TmpArray(0)), "00") + "-" + Format(Hex(TmpArray(1)), "00") + "-" + _
                Format(Hex(TmpArray(2)), "00") + "-" + Format(Hex(TmpArray(3)), "00")
    
End Sub
'字节型数据转换为浮点数据
Private Sub Command2_Click()
    If Len(Text1.Text) <> 11 Then
        MsgBox "输入数据格式错误,请重新输入!   ", vbInformation + vbOKCancel, "提示"
        Exit Sub
    End If
    TmpArray(0) = Val("&h" + Mid(Text1.Text, 1, 2))
    TmpArray(1) = Val("&h" + Mid(Text1.Text, 4, 2))
    TmpArray(2) = Val("&h" + Mid(Text1.Text, 7, 2))
    TmpArray(3) = Val("&h" + Mid(Text1.Text, 10, 2))
    If TmpArray(3) = 255 Or TmpArray(3) = &H7F Then
        MsgBox "输入浮点数据错误,请重新输入!   ", vbInformation + vbOKCancel, "提示"
        Exit Sub
    End If
    Tmpf = InttoFloat(TmpArray(0))
    Text2.Text = Format(Tmpf, "0.000")
End Sub

⌨️ 快捷键说明

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