Reputation: 8959
I'm in the process of a code review and have come across this:
Dim lngLen As Long
lngLen = 16&
I have done some reading and it appears to be that this is a way of casting the number to a long - is that correct?
But is that really necessary here as you can just assign lngLen
the value of 16 because it's a numeric value.
Also, following this code this is done:
Dim strCompName As String
strCompName = String$(lngLen, 0&)
I realize the String
method, from the Access help definitions, "returns a variant containing a repreating character string of the length specified."
So what does the $ do? And again is the & casting the 0 to a long?
Upvotes: 4
Views: 10790
Reputation: 61
Well as per you inquiry
Some people think Choosing the function that returns the correct type will be slightly more efficient and this makes faster executing code.
Well on the other hand some thinks It serves no useful purpose at all to add the type declaration suffix in the code when it was not declared with the suffix. Surely that does nothing but obfuscate the code.
String$ is a function
The $ at the end is a way of declaring the variable As String.
The & at the end is a way of declaring the variable As Long.
You are right i dont think these are necessary here.
Upvotes: 3
Reputation: 773
Hi you can check this question for a possible answer to your query.
Edit: Moreover, I was able to scour the internet for more resources and I found this VBA typing convention which originally found on this forum page.
Hopefully this would help you.
Upvotes: 5