zoukankan      html  css  js  c++  java
  • VB6各数据类型序列化和反序列化

    Private Sub Command1_Click()

    '序列化
    Dim var1 As Byte
    Dim var2 As Boolean
    Dim var3 As Integer
    Dim var4 As Long
    Dim var5 As Single
    Dim var6 As Double
    Dim var7 As String

    var1 = CByte(Text1.Text)
    var2 = CBool(Text2.Text)
    var3 = CInt(Text3.Text)
    var4 = CLng(Text4.Text)
    var5 = CSng(Text5.Text)
    var6 = CDbl(Text6.Text)
    var7 = Text7.Text

    Open "c:"aaa.txt" For Binary As #1
    Put #1, , var1
    Put #1, , var2
    Put #1, , var3
    Put #1, , var4
    Put #1, , var5
    Put #1, , var6
    Put #1, , var7
    Close #1
    End Sub

    Private Sub Command2_Click()

    '反序列化
    Dim var1 As Byte   '1
    Dim var2 As Boolean '2
    Dim var3 As Integer '2
    Dim var4 As Long '4
    Dim var5 As Single '4
    Dim var6 As Double '8
    Dim var7 As String '变长

    Open "c:"aaa.txt" For Binary As #1
    Get #1, , var1
    Get #1, , var2
    Get #1, , var3
    Get #1, , var4
    Get #1, , var5
    Get #1, , var6
    var7 = Space(LOF(1) - 21) '变长字符串长度=文件总长度-前面各类型所占长度
    Get #1, , var7
    Close #1

    Label1.Caption = CStr(var1)
    Label2.Caption = CStr(var2)
    Label3.Caption = CStr(var3)
    Label4.Caption = CStr(var4)
    Label5.Caption = CStr(var5)
    Label6.Caption = CStr(var6)
    Label7.Caption = CStr(var7)

    End Sub

    Private Sub Command3_Click()
        '数组序列化和反序列化
        Dim arr()     As Single
        Dim arr1()    As Single
        Dim i     As Long
        Dim j     As Long
        Dim h As Long
        Dim l As Long
        h = 1
        l = 2
        ReDim arr(h, l)
        For i = 0 To l
          For j = 0 To h
                arr(j, i) = 100.1
          Next j
        Next i
       
        Open "c:"aaa.txt" For Binary As #1
        Put #1, , arr
        Close #1
         
        ReDim arr1(h, l)
        Open "c:"aaa.txt" For Binary As #1
        Get #1, , arr1
        Close #1
    End Sub

  • 相关阅读:
    2016.7.22.noip2012D2
    2016.7.21.noip2014D2
    LIS最长上升子序列O(n^2)与O(nlogn)的算法
    vijos1910解方程
    vijos1909寻找道路
    viojs1908无线网路发射器选址
    P1907飞扬的小鸟
    P1906联合权值
    P1905生活大爆炸版 石头剪刀布
    poj1274(匈牙利算法)
  • 原文地址:https://www.cnblogs.com/lzhdim/p/1363423.html
Copyright © 2011-2022 走看看