2009-09-16

Decimal.Round 產出的錯誤信息

Decimal.Round(CType(txt.ToString(), Decimal), 2).ToString

之前在VS2003 .NET 1.1 Run的好好的程式,因為昇級到了VS2005 .NET 2.0 Sp2的環境之後
產生的錯誤訊息,因為VS2005之後就可以使用Math.Round這個Function所以大概只有昇級完會碰到這個問題吧,而且在編譯時不會有任何的錯誤,是在Run Time才會發現,所以才頭痛啊,言歸正傳

Decimal.Round只接受傳入的值為Decimal所以轉型一下就ok囉
Dim txt As Decimal = Ctype(txt.Tostring(), Decimal)
Decimal.Round(txt, 2).ToString()


如需叫用 Just-In-Time (JIT) 偵錯的詳細資料,
請參閱本訊息結尾處 (而非這個對話方塊) 的資訊。

************** 例外狀況文字 **********
System.Reflection.AmbiguousMatchException: Overload resolution failed because no Public 'Round' can be called without a narrowing conversion:
'Public Shared Function Round(d As Decimal, mode As System.MidpointRounding) As Decimal':
Argument matching parameter 'd' narrows from 'String' to 'Decimal'.
Argument matching parameter 'mode' narrows from 'Integer' to 'MidpointRounding'.
'Public Shared Function Round(d As Decimal, decimals As Integer) As Decimal':
Argument matching parameter 'd' narrows from 'String' to 'Decimal'.
於 Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, List`1 Candidates, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
於 Microsoft.VisualBasic.CompilerServices.OverloadResolution.ResolveOverloadedCall(String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
於 Microsoft.VisualBasic.CompilerServices.NewLateBinding.ResolveCall(Container BaseReference, String MethodName, MemberInfo[] Members, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, BindingFlags LookupFlags, Boolean ReportErrors, ResolutionFailure& Failure)
於 Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
於 wsERP2004.fm_QC_Raw_Sampling_W.fm_QC_Raw_Sampling_W_Load(Object sender, EventArgs e)
於 System.Windows.Forms.Form.OnLoad(EventArgs e)
於 System.Windows.Forms.Form.OnCreateControl()
於 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
於 System.Windows.Forms.Control.CreateControl()
於 System.Windows.Forms.Control.WmShowWindow(Message& m)
於 System.Windows.Forms.Control.WndProc(Message& m)
於 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
於 System.Windows.Forms.ContainerControl.WndProc(Message& m)
於 System.Windows.Forms.Form.WmShowWindow(Message& m)
於 System.Windows.Forms.Form.WndProc(Message& m)
於 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
於 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
於 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

0 comments: