protected int nGoodInt (string sNumber) { sNumber = sNumber.Trim(); int Num; bool isNum = int.TryParse(sNumber, out Num); if (isNum) { return Num; } else { return 0; } }
protected System.Boolean IsNumeric(System.Object Expression) { if (Expression == null || Expression is DateTime) { return false; } if (Expression is Int16 || Expression is Int32 || Expression is Int64 || Expression is Decimal || Expression is Single || Expression is Double || Expression is Boolean) { return true; } try { if (Expression is string) { Double.Parse(Expression as string); return false; } else { Double.Parse(Expression.ToString()); return true; } } catch { return false; } }
Function GoodInt(s) ' Returns a "good" number, accounting for null values, etc. On Error Resume Next If len(s) > 0 and isNumeric(s) then s = csng(s) GoodInt= CLng(s) Else GoodInt= 0 End If If Err Then GoodInt= 0 End Function
Function | String | Value |
---|---|---|
GoodInt | 55 | 55 |
GoodInt | 55.55 | 56 |
GoodInt | 55.45 | 55 |
GoodInt | SomeText | 0 |
Last Updated on October 24, 2021