Forgive this repost, but I'm not seeing my original post appearing…
On Apr 11, 2007, at 4:14 PM, Charles Yeomans wrote:
> On Apr 11, 2007, at 4:48 PM, Daniel Stenning wrote:
>
>
>> Anyone know how (in the shortest amount of code ) to get the
>> integer value
>> of an OSType - say 'abcd' ?
>>
>
> Here's a function that does not use a MemoryBlock.
>
> Function OSTypeToUInt32(x as OSType) As UInt32
> dim char() as String = SplitB(x, "")
> return ((AscB(char(0))*256 + AscB(char(1)))*256 + AscB(char(2)))
> *256 + AscB(char(3))
> End Function
>
> You could eliminate the split to array, replacing char(i) by MidB(x,
> i + 1).
>
> Function OSTypeToUInt32(x as OSType) As UInt32
> return ((AscB(MidB(x, 1))*256 + AscB(MidB(x, 2)))*256 + AscB(MidB
> (x, 3)))*256 + AscB(MidB(x, 4))
> End Function
>
Unless I'm overlooking something, I think Charles' examples are
missing POW. Here's the (somewhat verbose/old-school) function I use:
Dim i, theLong, aChar As Integer
for i=4 downTo 1
aChar=Asc(Mid(theOSType, i, 1))
theLong=theLong+(aChar*(Pow(256, 4 - i )))
next
return theLong
And come to think of it, I think that all of these examples will fail
if used on Windows. In that case, you'd need to make the i-loop go in
the opposite direction (1 to 4).
hth,
Erick
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>