Typecast Constants
There are many cases in which numeric constants (i.e. 1, 2, etc) are used in looping structures. By placing a typecast character after the constant (i.e. 1&), you can ensure that conversions from integer to long or single to double do not slow down the looping speed. Below you can see an example of how typecast characters are coded.Program Code
Function RemoveNonPrintable(ByVal strIn As String) As String Dim i As Long ' To Read Each Character Of The Input String Dim j As Long ' Characters That Are Accepted Dim strChar As String ' ******************************************************************** ' This Also Demonstrates Two Key Concepts: ' (1) Pass a parameter By Value (original value does not get modified) ' (2) Typecast characters used in constants ' Typecast Characters: &=Long, %=Integer, !=Single, #=Double ' @=Currency, $=String ' ******************************************************************** j = 0 For i = 1& To Len(strIn) strChar = Mid$(strIn, i, 1&) Select Case Asc(strChar) Case 10, 13, Is >= 32 j = j + 1& Mid$(strIn, j, 1&) = strChar End Select Next RemoveNonPrintable = Left$(strIn, j) ' Shorter String Now
Data Types And Rounding
If you need exact accuracy and want to avoid using Rounding, use the Integer or Currency Data types. Also, you can use the CDec function to convert a Variant data type to a Decimal data type (You can't directly declare a Decimal Data Type). Here are some useful links:
Double Type in Excel
Currency Data Type
Decimal Data Type
Scaled Integer Data Types
Floating Point (Double) has the greatest range of numbers with the issue of Rounding.
.