Mengingat posting saya sebelumnya dari float ke hex, nah sekarang saya ingin shared dari hex ke Float maupun sebaliknya,

Option Explicit

Private Type TSingle
  Sng As Single
End Type

Private Type TLong
  Lng As Long
End Type

Public Function Long2Float(ByVal value As Long) As Single
Dim s As TLong, d As TSingle
  s.Lng = value
  LSet d = s
  Long2Float = d.Sng
End Function

Public Function Float2Long(ByVal value As Single) As Long
Dim s As TSingle, d As TLong
  s.Sng = value
  LSet d = s
  Float2Long = d.Lng
End Function

'~~~ All the functions and other things ends here
'~~~ We are going to use it.

Private Sub Command1_Click()  '~~~ On clicking the CommandButton
  '~~~ Declaring variables
  Dim sHex As String
  Dim Sng As Single
  Dim Lng As Long
 
  '~~~ Sample HEX string
  sHex = "&H3F8CCCCD"
 
  '~~~ Converting it into Float
  Sng = Long2Float(sHex)
  MsgBox "Hex to Float: " & Sng   '~~~ Displaying it
 
  '~~~ Converting it into Long
  Lng = Float2Long(Sng)
  MsgBox "Float to Long: " & Hex(Lng) '~~~ Displaying it
End Sub


0 Comments:

Post a Comment



Share |