I am working on an legacy VBA/Excel app and stumbled over some lines of code where a long string (read from a file) is cut into pieces. Those lines look like this:
Range("E16").Value = Mid(line, 49, [6])
Obviously, writing [6]
means taking 6 characters, but I never saw this syntax to put square brackets around a number.
I did some tests and found out that putting those square brackets doesn't do any obvious to the number
Dim x As Double
x = 5.1
Debug.Print [2], [3.1], [-5], x
Debug.Print [3.1] * [x] * [-5]
>> 2 3.1 -5 5.1
>> -79.05
So, no truncation, no rounding, no abs-value.
I did some more tests to check if it does some magic similar to putting parentheses around a variable to prevent modifying a value that is passed by reference, but that's not the case:
x = 5.1: test2 x: Debug.Print x
x = 5.1: test2 (x): Debug.Print x
x = 5.1: test2 [x]: Debug.Print x
Sub test2(ByRef y As Double)
y = y * 2
End Sub
>> 10.2
>> 5.1
>> 10.2
Surprised that the compiler even accepts this syntax: What is the meaning of using those brackets?