Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Call CopyMemory(TempDbl,TempBytes,8)

解决方案 »

  1.   

    错了,是:
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Call CopyMemory(TempBytes,TempSng,4)
      

  2.   

    具体编码我没有但是思路我的想法是:
    1.那个浮点数用16进制表示
    2.将这个数转换成字符型
    3.裁减字符型
    4.分别转换成byte型。
    到此。
    不知道能不能实现,祝你成功!!
      

  3.   

    to:zyl910
    编译的时候告诉我TempBytes类型不匹配
    我的TempBytes定义的是
    Dim TempBytes(3) As Byte
    不知道对不对
      

  4.   

    to:chsl918
    第一步我不太会啊
      

  5.   

    Dim TempBytes(0 To 3) As Byte
    Dim TempSng As SingleTempSng=……
    Call CopyMemory(TempBytes(0),TempSng,4)
      

  6.   

    如果再不行,试一试:Dim TempBytes(0 To 3) As Byte
    Dim TempSng As SingleTempSng=……
    Call CopyMemory(VarPtr(TempBytes(0)), VarPtr(TempSng), 4)
     
      

  7.   

    错了,是:Dim TempBytes(0 To 3) As Byte
    Dim TempSng As SingleTempSng=……
    Call CopyMemory(Byval VarPtr(TempBytes(0)),Byval VarPtr(TempSng), 4)
      

  8.   

    我觉得可以先用一个LONG型的变量把SINGLE型的数字存进来,再用AND与上各个不同的数字分离出来各个字节,忘高手再指点一下看看有没有什么没想到的
    BTW:下午散分
      

  9.   

    (2002-1-23 21:24:52)错了的原因是:
    数组(是数组,不是数组元素)本来就是指针,再加上 传址,变成两个指针。
    所以,应该写成:Call CopyMemory(Byval TempBytes,TempSng,4)
    但,习惯上写成:Call CopyMemory(TempBytes(0),TempSng,4)
      

  10.   

    我也是chsl918(二雷)的思路
    代码大概就是下面这样了,不过我没测试(写的很马虎,不好意思):
    Function GetBytesByDouble(pDouble as Double,pBytes() as Byte)
      tHEXStr=Hex(pDouble)
      tHEXStr_Len=Len(tHEXStr)
      If tHEXStr_Len<8 Then 
        tHEXStr=Str(8-tHEXStr_Len,"0") & tHEXStr
      End If
      For tLoop=0 To 3
        pBytes(tLoop)=CByte("&H" & Mid(tHEXStr,tLoop*2+1,2))
      Next 
    End Function
      

  11.   

    To KiteGirl(小仙妹):
    Hex函数数可以取 浮点型 的16进制值吗?
    我记得QB中说 是把 浮点型 取整 再转化为16进制值。
    VB不一样吗?
      

  12.   

    下面这个例子恐怕只有小仙妹这种高级笨蛋才能发明出来。和人打赌还可以,但是实用起来就效率很低了(因为要用交换文件)。Private Sub Form_Load()
      Dim tBytes() As Byte
      Dim tDouble As Double
      tDouble = 1234.56789
      ReDim tBytes(0 To LenB(tDouble) - 1)
      BytesGetByDouble tDouble, tBytes()
      Text1.Text = DoubleGetByBytes(tBytes())
    End SubFunction DoubleGetByBytes(pBytes() As Byte) As Double
      'Byte数组变双精度。
      Dim tFileNumber As Integer
      Dim tOutDouble As Double
      tFileNumber = FreeFile
      Open "~DoubleGetByBytes.tmp" For Binary As #tFileNumber
        Put #tFileNumber, 1, pBytes()
        Get #tFileNumber, 1, tOutDouble
      Close #tFileNumber
      DoubleGetByBytes = tOutDouble
      Kill "~DoubleGetByBytes.tmp"
    End FunctionFunction BytesGetByDouble(pDouble As Double, pBytes() As Byte)
      '双精度变Byte数组。
      Dim tFileNumber As Integer
      tFileNumber = FreeFile
      Open "~BytesGetByDouble.tmp" For Binary As #tFileNumber
        Put #tFileNumber, 1, pDouble
        Get #tFileNumber, 1, pBytes()
      Close #tFileNumber
      Kill "~BytesGetByDouble.tmp"
    End Function
      

  13.   

    zyl910(910:分儿,我来了!) 给我的提示最大 40分
    KiteGirl(小仙妹) 想法奇特 10分
    其余人等 5分