Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Call CopyMemory(TempDbl,TempBytes,8)
解决方案 »
- 如何自动下载某个文件~~~
- 串口通讯问题
- 我现在在做统计每个月的消费额:要用到的字段
- Ado的Recordset保存文件,然后用另一个库的Recordset读出这个文件,但是EditMode为零我无法在此库更新该如何是好?
- 还是image控件的问题!!
- 问两个问题,关于CopyMemory和DC的。
- 各路的神仙鬼怪圣贤高手,不管修炼时间多长,大可进来看看(请进关于Image的问题)
- datagrid 控件行数据实现累加问题
- 如何改变adodc控件中的数据库的路径?在线等
- 高分求解:如何“杀”自动跳出的IE广告窗口?
- HTML Heple WORK...的使用方法??????
- 请问怎样把数据报表中的内容导出到excel中?
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)Call CopyMemory(TempBytes,TempSng,4)
1.那个浮点数用16进制表示
2.将这个数转换成字符型
3.裁减字符型
4.分别转换成byte型。
到此。
不知道能不能实现,祝你成功!!
编译的时候告诉我TempBytes类型不匹配
我的TempBytes定义的是
Dim TempBytes(3) As Byte
不知道对不对
第一步我不太会啊
Dim TempSng As SingleTempSng=……
Call CopyMemory(TempBytes(0),TempSng,4)
Dim TempSng As SingleTempSng=……
Call CopyMemory(VarPtr(TempBytes(0)), VarPtr(TempSng), 4)
Dim TempSng As SingleTempSng=……
Call CopyMemory(Byval VarPtr(TempBytes(0)),Byval VarPtr(TempSng), 4)
BTW:下午散分
数组(是数组,不是数组元素)本来就是指针,再加上 传址,变成两个指针。
所以,应该写成:Call CopyMemory(Byval TempBytes,TempSng,4)
但,习惯上写成:Call CopyMemory(TempBytes(0),TempSng,4)
代码大概就是下面这样了,不过我没测试(写的很马虎,不好意思):
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
Hex函数数可以取 浮点型 的16进制值吗?
我记得QB中说 是把 浮点型 取整 再转化为16进制值。
VB不一样吗?
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
KiteGirl(小仙妹) 想法奇特 10分
其余人等 5分