Dim
Variables implicitly as variants
VB.NET is capable of assuming object type at compile time - with numerics being dimmed into 32-bit spaces this means that
Module M
Sub Main
Dim i As Byte
Dim j As Short
Dim k As Integer
Dim l As Long
For i=128To 2^8-1 Step 64
For j=2^7*i To 2^15-1 Step 64^2
For k=2^16*j To 2^31-1 Step 2^24
For l=2^31*k To 2^62-1 Step 2^48
Console.Write(i & j & k & l)
Next
Next
Next
Next
End Sub
End Module
Try it online! (266 bytes)
May be trimmed down by dim
ming i
, j
, k
as variants, (note that because the default numeric type of a variant is a 32 Bit Integer
l
must still be dim
med as a Long
as it shall hold a 64 bit value)
Module M
Sub Main
Dim i,j,k,l As Long
For i=128To 2^8-1 Step 64
For j=2^7*i To 2^15-1 Step 64^2
For k=2^16*j To 2^31-1 Step 2^24
For l=2^31*k To 2^62-1 Step 2^48
Console.Write(i &j &k &l)
Next
Next
Next
Next
End Sub
End Module
Try it online! (226 bytes)
or even further to 218 bytes by combining Next
statements
Module M
Sub Main
Dim i,j,k,l As Long
For i=128To 2^8-1 Step 64
For j=2^7*i To 2^15-1 Step 64^2
For k=2^16*j To 2^31-1 Step 8^8
For l=2^31*k To 2^62-1 Step 2^48
Console.Write(i &j &k &l)
Next l,k,j,i
End Sub
End Module
Try it online! (218 bytes)
For a total savings of 40 bytes without impacting the output.
I think that the tips for golfing in uBasic, Yabasic, Visual Basic and Visual Basic.NET are all pretty similar, possibly enough to dupe close. Even if they aren't, we don't need a tips page for every dialect of a language, such as separate pages for Java 7, 8 and 9. – caird coinheringaahing – 2018-02-15T07:50:07.847
Caird, this issue with that is that while logically similar they have completely different syntax - for instance, uBasic requires line numbers, does not require spacing between any commands and barely has strings, let alone proper graphics and events implemented where as for VB.NET there are not required line numbers, modules are required, you have to use
Console.Write
instead of?
, it has proper graphics implemented events out the wazoo and the entirety of the .NET library available to it - to say that they should be treated the same is simply illogical – Taylor Scott – 2018-02-15T17:53:50.640@cairdcoinheringaahing That said, I would agree that VB and VB.NET are very similar - I mean VB.NET is the replacement for VB, but they are completely different and distinct languages - that is, code written in VB may not run in VB.NET and code written in VB.NET may not run in VB. Further between the two there is currently 20 years worth of continuous professional development time between them, and this is reflected in the paradigms of writing in the two – Taylor Scott – 2018-02-15T17:59:40.663