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'  ?
>
> The only way I have been able to do this is to copy the OSType into a
> memoryblock to read out the integer equivalent, but this seemed way  
> too
> messy.
>
>  I have ended up just using a 4 byte memoryblock instead of the  
> OSType and
> using the conversion methods to convert between  4 char string and  
> integer
> format, but would much rather just be able to use OSType..
>


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


If these aren't simple enough, perhaps you should file a feature  
request for automatic conversion between OSType and UInt32.


Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to