# Posts by nomel

Re: Convert Byte Array Containing Floating Point To Single

Ahhh!!! Perfect! Much much much faster.

I'm dealing with 4 million data points...so....thank you!!!!!!!!!!!!   Re: Convert Byte Array Containing Floating Point To Single

ohhh...very nice shg!! I didn't realize you could convert the fraction that way.

One problem though, you have to change the exponent to -126 if it's denormalized.

The denormalized hex value 00400000h should be come out to be about 5.9×10^-39, but with your function, it is about 2.9X10^-39.

Besides that, I'm using yours! Re: Dynamically Update Chart Source Range

I found the problem! I removed some references and the same macro started working.

Re: Convert Byte or Integer To Floating Point Number

Yes, while running to get coffee between tests in the lab. Still my mistake, I'll try to be more courteous.

Re: Convert Byte or Integer To Floating Point Number

I haven't said thanks yet because I'm still at work and have been very busy.

Thanks for the interest and help mike. The simplified description I gave was simplified to just help explain what the standard defined, not for implementation. There are other details (in the link I provided) like normalization, and the significant must be converted to a binary fraction before that equation can be used. Those pesky little details And that example I made up ends up being around 6.06x10^-25. So small Here is the finished function. I've tested it against the examples on the wikipedia page I linked to:

What a terribly inefficient and backwards way to get a number that's already in memory back into memory! :roll:

Re: Convert Byte or Integer To Floating Point Number

like i said...the details can be googled...or you could follow the link i provided at the beginning.

Re: Convert Byte or Integer To Floating Point Number

the IEEE 754 standard (wikipedia link) is the standard that describes how floating point numbers are stored in a computers memory. having a standard allows programs to read numbers sent by other programs or computers.

each variable is stored in the computers memory as a binary number.
for ascii strings, this is something like
[integer number of chars][byte][byte][byte][byte][byte]...etc. where each byte represents the acsii code for the letter (see asc and chr functions).

for numbers, storing as a string wouldn't make any sense, you would be using a whole byte (a number between 0 and 255) to store a value that is only between 1 and 10! So instead, the number is stored in binary, base 2 rather than base 10. for integers, this is fairly direct since any integer can be converted to a binary number. 255d = 11111111b, 56d = 111000b, etc. But what happens if you have a fraction of a number, or a fraction of a number plus an integer (like 3 + .14159 = 3.14159)?

That's where floating point comes in. It allows you to take an integer number (24 bit number for single), then *move* the decimal place to nearly wherever you want it...a *floating* decimal place...a floating point number! The standard describes how to store the information for where the decimal place goes, etc. Slightly simplified, it is in the following format:

[sign bit (+/-)][8 bit decimal place position][23 bit integer]

in this simplified example, for the number 5.12342134, the 24 bit integer (the first bit is always 1, and is hidden) would contain 512342134, and the decimal place position byte would say to put the decimal place after the 5. the sign bit would be 0 for positive. this gives the 32 bits total is how single type numbers are stored in memory.

the details can be googled. i'll post the function i'm making to convert that byte array in a bit Re: Convert Byte or Integer To Floating Point Number

it's a standard IEEE 32 bit floating point number...the same type used in excel for single. the data in the byte array is the data from memory for the number...how the single is actually stored in the computers memory as ones and zeros. not sure how giving an example will help cause it's an arbitrary bit pattern depending on the number....but here you go:

so, anyone know what somefunction is? i'm probably the only person that's ever needed to do this in excel I have a feeling I'll have to study the IEEE standard and make a function myself.

Re: Convert Byte or Integer To Floating Point Number

this is not the ascii representation, it's a binary representation of the floating point number.

the byte array will contain the 32 bit representation of a floating point number, so a total of four elements. the output will be a single. so something like

function bytetosingle(bytearray() as byte) as single

in vb.net, this function exists. It is BitConverter.ToSingle(bytearray() as byte, offset).

in delphi or c, I would use a memory pointer, but I'm not sure how to do it in vb. any ideas, or do I have to get all low level (and very slow)?

Hello,

I have a byte array that contains a 4 byte floating point number. How would I convert this byte array to the single typed floating point number it contains?

Thanks for any help!

Re: Custom Moving Focus In Exel

If you open the worksheet in the vba editor, you can select the worksheet and the change method from the dropdown lists at the top. This is called every time a cell changes. It tells you the range of all the cells that have changed.

Putting the following code will do what you described...but only when a change occurs...just pressing return in row 1 or 5 will do nothing, you have to change the contents of a cell in row 1 or 5, then press return.

Code
``````Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then  'make sure only one cell is selected...if there's a range, then, ignore.
Select Case Target.Cells.Item(1).row   'get the row of the first (and only) cell in the selection.
Case 1 'change happened in row 1
Cells(4, Target.Cells.Item(1).Column).Select
Case 5 'change happened in row 5
Cells(6, 1).Select
End Select
End If
End Sub``````

You can have it detect a change in selection using the selectionchange method of the worksheet, but, it gets messy since it triggers any time a selection happens.

I don't know of an easy way to detect a keypress...but maybe someone else does.

Re: Setting Category Labels On A Created Chart

*bump*

Re: Dynamically Update Chart Source Range

Isn't making a named range the same as setting a label to a range? I don't see why that would work if these methods (putting in a direct range rather than a label to the same range) don't work. I think it's more to do with syntax, since even recording a macro that changes the category labels and playing it back fails with an error.

Re: Creating Selection List

Yes you could do it using the worksheet selection change event.
Each time the selection is changed (cell is clicked) it will give you the range of the selection (the cell if only a cell is clicked). From there, you could show a userform (formname.show) that you added the inventory selections too, then just set the cell to the total cost and close the form after clicking an 'ok' button on the form.

Re: Dynamically Update Chart Source Range

What do you mean?

Did you look at my examples of what I have used?

Re: Setting Category Labels On A Created Chart

Quote from Sicarii

something like?

Code
``````With ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "This is X"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "This is Y"
End With``````

Not quite. I'd like the category labels, not the axis titles. If you look at the source data properties of a chart, and go to the series list, it's the section called "category (X) axis labels" under the series data.

I have tried recording a macro where I select this option in the source data properties window, then select the cells as usual.

It gives the following code:

Code
``ActiveChart.SeriesCollection(1).XValues = "='LineReg Graphs'!R9C1:R23C1"``

When I play it back it gives me an error! So, even excel doesn't know how Not sure what to do. I'm sure SOMEONE has run into this before.

Re: Format Total Hours to Days, Hours &amp; Minutes

if you know the hours,
mod(hours,23) will give you days, (hours - mod(hours,23)*24) will give you the correct hours.

Re: Insert Data From Form Into Spreadsheet

"i have a user form in my spreadsheet that uses option buttons and text boxes for user entry. i need to take the values and true false entries from the option buttons and place them in cells."

This should get you started.

Re: Automate Chart With Regular Row Increments

If you noticed, the chart wizard was used with an existing chart (created one line before).

Again, *look up* and *use* the chart wizard. It lets you set the title, source data, etc.

Code
``activechart.chartwizard(blah blah)``

Hello,

How do I set the category labels on a chart I've created with chartobjects.add?

Thanks!