What is UShort? (and how can I not use it?)

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

I imported a project from someone and they are using UShort. I am getting a
compiler error saying "Type 'UShot' is not defined". Since this is a VS
2008 project and I am on VS 2008, I am assuming this is a new datatype that
I don't have access to. What can I substitute for it (and still be safe?).
I tried changing it to sort and uint16 but not having much luck with error
messages.

Thanx,
 
Please check the spelling in your original post.

"UShort" is an unsigned short (16-bit) Integer. 'Unsigned' means that it
does not accept negative numbers. UShort is built-in to VB2008, but is not
CLS-compliant, according to the docs.

Have you got some option enabled that enforces CLS-compliance? If so I guess
you'll either need to widen to Int32 or treat it as Byte (binary) data.
 
You are right! A typo - I am on VS 2003, not 2008 so I need to
down-convert. What should I convert these to?
 
I imported a project from someone and they are using UShort.  I am getting a
compiler error saying "Type 'UShot' is not defined".  Since this is a VS
2008 project and I am on VS 2008, I am assuming this is a new datatype that
I don't have access to.  What can I substitute for it (and still be safe?).
I tried changing it to sort and uint16 but not having much luck with error
messages.

Thanx,

See this:

http://msdn2.microsoft.com/en-us/library/x68bebe2(VS.80).aspx

Unsigned (2-bit) integer that its range is 0 - 65535.

In this case, if you still have to use UShort, use math.abs to return
the absolute(non-negative) value. The data type range that you want to
use is up to you / your project.
 
Anil Gupte said:
You are right! A typo - I am on VS 2003, not 2008 so I need to
down-convert. What should I convert these to?

It depends on the scenario (p/invoke, ...).
 
oh thank goodness.. is this in the VB 2005 edition?

these unsigned ints were probably one of my favorite features of mySql

thanks

-Aaron
 
just not in SQL Server, right?

so now SQL Server wil match Visual Studio, right?

Thanks

-Aaron
 
just not in SQL Server, right?

so now SQL Server wil match Visual Studio, right?

I don't see any direct relation between SQL Server's type system and VB's
type system. 'UShort' is simply an alias for the BCL's 'UInt16' type, which
already existed in .NET 1.0. However, VB didn't provide built-in support
for this type in the language's syntax until VB 2005. Nevertheless it was
possible to use the type as 'UInt16' with some limitations in VB.NET
2002/2003.
 
I am not sure it is the same. I have been trying to translate someone's
program from VS 2008 to 2003 and I am having lots of problems in the code.

See the code below. I tried converting all UShorts to UInt16, then tried
some to Integer, and nothing is working. If you have any pointers I will
appreciate it.
Imports System
Imports System.Reflection
Imports WMFSDKWrapper


Public Class MetaDataReader

' WM file
Private mediaFilename As String

' Info attributes
Public Attributes As AttributeList


' Default constructor
Public Sub New(ByVal filename As String)
' Apply incoming data
mediaFilename = filename

' Create WMF reader
Dim MetadataEditor As IWMMetadataEditor
WMFSDKFunctions.WMCreateEditor(MetadataEditor)
MetadataEditor.Open(mediaFilename)
Attributes = New AttributeList

' Get Headers version 3
Dim HeaderInfo3 As IWMHeaderInfo3 = MetadataEditor
' HeaderInfo3 = (IWMHeaderInfo3)MetadataEditor;


' Read attributes
For Each AttributeName As String In AttributeList.Attributes
'HRESULT GetAttributeByName(
' WORD* pwStreamNum,
' LPCWSTR pszName,
' WMT_ATTR_DATATYPE* pType,
' BYTE* pValue,
' WORD* pcbLength
');

Dim pwStreamNum As UShort
Dim pType As WMT_ATTR_DATATYPE
Dim pcbLength As UShort
Try
HeaderInfo3.GetAttributeByName(pwStreamNum, AttributeName,
pType, Nothing, pcbLength)
Catch ex As Exception
Return
End Try


Dim pValue(pcbLength) As Byte
HeaderInfo3.GetAttributeByName(pwStreamNum, AttributeName,
pType, pValue, pcbLength)
Dim convertedValue As String = ConvertAttrToString(pValue,
pcbLength)

' Convert Attribute to string
Attributes.SetProperty(AttributeName, convertedValue)
Next

' Close WMF reader
MetadataEditor.Close()
End Sub


' Convert attribute to string
Public Function ConvertAttrToString(ByVal pValue() As Byte, ByVal
pcbLength As UShort) As String
Dim value As String = ""

If pcbLength = 0 Then
Return value
End If

' Convert from UTF-16LE BOM+ format
If Convert.ToInt16(pValue(0)) = Convert.ToInt16("FE", 16) _
And Convert.ToInt16(pValue(0)) = Convert.ToInt16("FF", 16) Then

value = "UTF-16LE BOM+"
If (pcbLength >= 4) Then
For index As Integer = 2 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If


' Convert from UTF-16BE BOM+ format
ElseIf Convert.ToInt16(pValue(0)) = Convert.ToInt16("FF", 16) _
And Convert.ToInt16(pValue(0)) = Convert.ToInt16("FE", 16)
Then

value = "UTF-16BE BOM+"
If (pcbLength >= 4) Then
For index As Integer = 2 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If


' Convert from UTF-16BE BOM+ format
Else

value = ""
If (pcbLength >= 2) Then
For index As Integer = 0 To pValue.Length - 4 Step 2
value += Convert.ToString(BitConverter.ToChar(pValue,
index))
Next
End If

End If

Return value
End Function

End Class
 
Microsoft just needs to offer consistency. Offering it in one place
but not others is -- pardon the french -- _RETARDED_.

I'm not talking about 'what is available'.
I am concerned with Microsoft not offering consistent datatypes.

I don't know if you know anything about datatypes in SQL Server. but
they are a _REALLY_ big deal.
being able to use an unsigned smallint would allow me to use the
smaller datatypes in about 4 times as many places.

that is a big deal when you're talking about the keys to data
warehouse tables.

-Aaron
 
Back
Top