?
Solved

How to access individual bytes in Single

Posted on 2003-03-11
3
Medium Priority
?
181 Views
Last Modified: 2010-04-07
I have a single that I want to access each individual byte of. How can I do this?

dim stuff as single


var1 = stuff.byte0
var2 = stuff.byte1
var3 = stuff.byte2
var4 = stuff.byte3

Thanks
0
Comment
Question by:DavidBonfoey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
TigerZhao earned 200 total points
ID: 8116119
Declare Sub CopyMemoryLpToLp Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As Long, ByVal pSrc As Long, ByVal ByteLen As Long)

Sub Main()
    Dim stuff As Single
    Dim ba(0 To 3) As Byte

    stuff = 1234.5678
   
    CopyMemoryLpToLp VarPtr(ba(0)), VarPtr(stuff), 4&
   
    Debug.Print ba(0)
    Debug.Print ba(1)
    Debug.Print ba(2)
    Debug.Print ba(3)
End Sub
0
 
LVL 2

Expert Comment

by:spauljoseph
ID: 8117405
Use this.

Dim sngVar as Single
Dim bytVar() as Byte


bytVar = StrConv(CStr(sngVar),vbFromUnicode)

Debug.Print bytVar(0)
....

0
 

Author Comment

by:DavidBonfoey
ID: 8119869
Thanks!

Works great!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question