'********************************************************************** '在窗体中添加两个command按钮和两个text文本框和一个list控件 ' 'read按钮作用为将text1文本框中的浮点数转换为4个字节的整形在list1中显示 ' 'set按钮是将list1中的4个字节的数还原为一个浮点数在text2中显示 ' '注:该示例只能在vb6中使用(因为vb5不支持Lset函数,需要自己写该函数) '**********************************************************************Private Type A_Single aa As Single End TypePrivate Type A_Byte bb(0 To 3) As Byte End TypeDim Da As A_Single Dim By As A_BytePrivate Sub Form_Load() Text1.Text = "" Text2.Text = "" List1.Clear Text2.Locked = True End SubPrivate Sub Read_Click() Dim Arry_Out(0 To 3) As ByteIf Not IsNumeric(Text1.Text) Then Exit SubDa.aa = Text1.Text LSet By = Da Arry_Out(0) = By.bb(0) Arry_Out(1) = By.bb(1) Arry_Out(2) = By.bb(2) Arry_Out(3) = By.bb(3)List1.Clear List1.AddItem Hex(Arry_Out(0)) List1.AddItem Hex(Arry_Out(1)) List1.AddItem Hex(Arry_Out(2)) List1.AddItem Hex(Arry_Out(3))End SubPrivate Sub Set_Click() By.bb(0) = "&h" & List1.List(0) By.bb(1) = "&h" & List1.List(1) By.bb(2) = "&h" & List1.List(2) By.bb(3) = "&h" & List1.List(3)LSet Da = By Text2.Text = Da.aa End Sub
用等号不可以吗?
1、不知道你的copymemory是怎么声明的,请不要用Byval传递by(0),sng两参数
2、by字节数组中,是按低位在前,高位在后排列的,不要弄反了。最好,把你的代码贴出来。
'在窗体中添加两个command按钮和两个text文本框和一个list控件
'
'read按钮作用为将text1文本框中的浮点数转换为4个字节的整形在list1中显示
'
'set按钮是将list1中的4个字节的数还原为一个浮点数在text2中显示
'
'注:该示例只能在vb6中使用(因为vb5不支持Lset函数,需要自己写该函数)
'**********************************************************************Private Type A_Single
aa As Single
End TypePrivate Type A_Byte
bb(0 To 3) As Byte
End TypeDim Da As A_Single
Dim By As A_BytePrivate Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
List1.Clear
Text2.Locked = True
End SubPrivate Sub Read_Click()
Dim Arry_Out(0 To 3) As ByteIf Not IsNumeric(Text1.Text) Then Exit SubDa.aa = Text1.Text
LSet By = Da
Arry_Out(0) = By.bb(0)
Arry_Out(1) = By.bb(1)
Arry_Out(2) = By.bb(2)
Arry_Out(3) = By.bb(3)List1.Clear
List1.AddItem Hex(Arry_Out(0))
List1.AddItem Hex(Arry_Out(1))
List1.AddItem Hex(Arry_Out(2))
List1.AddItem Hex(Arry_Out(3))End SubPrivate Sub Set_Click()
By.bb(0) = "&h" & List1.List(0)
By.bb(1) = "&h" & List1.List(1)
By.bb(2) = "&h" & List1.List(2)
By.bb(3) = "&h" & List1.List(3)LSet Da = By
Text2.Text = Da.aa
End Sub
LSet By = Da
其中by对应一个byte数组 da是个字符串