There will be a hit in memory allocation
Public Type Car
Make As String
Model As String
Price As Currency
Km As Long
End Type
Sub Test()
Dim udtCar As Car
Dim Make As String
Dim Model As String
Dim Price As Currency
Dim Km As Long
Debug.Print "UDT", LenB(udtCar)
Debug.Print , "KM", LenB(udtCar.Km)
Debug.Print , "MAKE", LenB(udtCar.Make)
Debug.Print , "MODEL", LenB(udtCar.Model)
Debug.Print , "PRICE", LenB(udtCar.Price)
Debug.Print ""
Debug.Print , "KM", LenB(Km)
Debug.Print , "MAKE", LenB(Make)
Debug.Print , "MODEL", LenB(Model)
Debug.Print , "PRICE", LenB(Price)
End Sub
reports
UDT 20
KM 4
MAKE 0
MODEL 0
PRICE 8
KM 4
MAKE 0
MODEL 0
PRICE 8
I read the following as being unless you dimension prior to run time you will have to ReDim which in itself has a performance hit. Not that you can not do it.
You must declare all the variables you'll need at design time or you need a dynamic array that is resized with Redim Preserve, an awkward and expensive operation.
The other 2 points stand. because you are only assigning values you can not control what values are used or perform additional operations on the value.
Bookmarks