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