Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
misc
exam.security
microsoft_update_catalog
msdn.annotations
msdn.drgui.discussion
msdn.duwamish
msdn.general
msdn.magazine
msdn.soaptoolkit
msdn.webservices
msdntraining
opsmgr.connectors
opsmgr.sp1
technet
technet.howtofeedback
technet.howtoneeds
technet.magazine
technet.technettalks
  
 
date: Fri, 29 Jul 2005 08:05:01 -0700,    group: microsoft.public.msdn.drgui.drguidotnet.discussion        back       


Could this be a bug in VB.NET ??   
In VS.NET 2003 (VB.NET): 
Microsoft Development Environment 2003 Version 7.1.3088 
Microsoft .NET Framework 1.1 Version 1.1.4322 SP1 

Here's a small piece of code which works fine: 

Private Sub Button3_Click(ByVal sender _ 
As System.Object, ByVal e As System.EventArgs) _ 
Handles Button3.Click 
' Convert a Decimal to an Int32 Array 
' and then back to a Decimal 
Dim dec1 As Decimal 
Dim dec2 As Decimal 
dec1 = Decimal.Parse(TextBox1.Text) 
Dim i32A As Int32() 
Dim i32B(4) As Int32 
i32A = Decimal.GetBits(dec1) 
Debug.Write(i32A(0).ToString & vbCrLf) 
Debug.Write(i32A(1).ToString & vbCrLf) 
Debug.Write(i32A(2).ToString & vbCrLf) 
Debug.Write(i32A(3).ToString & vbCrLf) 
i32B = i32A 
Debug.Write(i32B(0).ToString & vbCrLf) 
Debug.Write(i32B(1).ToString & vbCrLf) 
Debug.Write(i32B(2).ToString & vbCrLf) 
Debug.Write(i32B(3).ToString & vbCrLf) 
dec2 = New Decimal(i32B) 
TextBox3.Text = dec2.ToString() 
End Sub 
----- 
Input: 43683683.368268265 
----- 
Debug: 497381865 
10170900 
0 
589824 
497381865 
10170900 
0 
589824 
----- 
Output: 43683683.368268265 
----- 

And here's a similar piece which bombs and I can't figure 
out why: 

Private Sub Button3_Click(ByVal sender _ 
As System.Object, ByVal e As System.EventArgs) _ 
Handles Button3.Click 
' Convert a Decimal to an Int32 Array 
' then to an array of (unsigned) bytes 
' then back to an Int32 Array 
' and then back to a Decimal 
Dim dec1 As Decimal 
Dim dec2 As Decimal 
dec1 = Decimal.Parse(TextBox1.Text) 
Dim i32A As Int32() 
Dim i32B(4) As Int32 
i32A = Decimal.GetBits(dec1) 
Debug.Write(i32A(0).ToString & vbCrLf) 
Debug.Write(i32A(1).ToString & vbCrLf) 
Debug.Write(i32A(2).ToString & vbCrLf) 
Debug.Write(i32A(3).ToString & vbCrLf) 
Dim BA As Byte() 
Dim BB As Byte() 
Dim BC As Byte() 
Dim BD As Byte() 
BA = BitConverter.GetBytes(i32A(0)) 
BB = BitConverter.GetBytes(i32A(1)) 
BC = BitConverter.GetBytes(i32A(2)) 
BD = BitConverter.GetBytes(i32A(3)) 
i32B(0) = BitConverter.ToInt32(BA, 0) 
i32B(1) = BitConverter.ToInt32(BB, 0) 
i32B(2) = BitConverter.ToInt32(BC, 0) 
i32B(3) = BitConverter.ToInt32(BD, 0) 
Debug.Write(i32B(0).ToString & vbCrLf) 
Debug.Write(i32B(1).ToString & vbCrLf) 
Debug.Write(i32B(2).ToString & vbCrLf) 
Debug.Write(i32B(3).ToString & vbCrLf) 
dec2 = New Decimal(i32B) <-- Error is Here ** 
TextBox3.Text = dec2.ToString() 
End Sub 
----- 
Input: 43683683.368268265 
----- 
Debug: 497381865 
10170900 
0 
589824 
497381865 
10170900 
0 
589824 
----- 
Output: An unhandled exception of type 
'System.ArgumentException' occurred 
in mscorlib.dll 

Additional information: Decimal byte 
array constructor requires an array 
of length four containing valid 
decimal bytes. 
----- 

But note that the Debug lines still show the Int32 
arrays are identical. Any ideas?
date: Fri, 29 Jul 2005 08:05:01 -0700   author:   mdavidjohnson

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us