This page is not for Visual Basic .NET Tips or VBA tips

Visual Basic (VB or VB6) is an object-oriented and event-driven dialect of that was developed and released by Microsoft in 1991. The last release of Visual Basic came as Visual Basic 6.0 in 1998, and the language was declared a legacy language in 2008. Visual Basic .NET replaced Visual Basic in 2002.

All answers on this site that are written in Visual Basic are assumed to be written for Visual Basic 6.0 unless otherwise stated.

Some helpful links

You may compile and execute Visual Basic code using Visual Studio Community.

There is no online resource for compiling VB code.

  • \$\begingroup\$ IDK VB, but isn't this just codegolf.stackexchange.com/questions/5175/… \$\endgroup\$
    – Pavel
    Commented Feb 15, 2018 at 7:27
  • \$\begingroup\$ @Pavel The short answer is no, there are several differences between VB and VBA, including, but not limited to the availability of the certain packages, data types, non-variant arrays, threading and proper graphics in VB that are not available to VBA and version specific tweaks available to VBA - such as the Cells command in Excel VBA. You can find out more about the difference here \$\endgroup\$ Commented Feb 15, 2018 at 18:09
  • \$\begingroup\$ consider using the normal [tips] format from other tips questions as the main part of your question (applies also to the other recent tip question) \$\endgroup\$
    – Uriel
    Commented Feb 15, 2018 at 20:55
  • \$\begingroup\$ @Uriel you mention a [tips] format but as far as I can see there are several that are currently in use on the site, could you please be a bit more specific about exactly what format you are referring to? \$\endgroup\$ Commented Feb 15, 2018 at 21:02
  • \$\begingroup\$ like the one on codegolf.stackexchange.com/questions/54/…. I think that is the one I've seen the most. Language info usually goes into the showcase question, not the tips. \$\endgroup\$
    – Uriel
    Commented Feb 15, 2018 at 21:06

2 Answers 2


Use DefXXX statements when declaring multiple variables

The statement

DefDbl A-D

Defines all variables that start with A through D as being of the type Double, which means this can shorten cases such as

Dim A As Double
Dim B As Double
Dim C As Double
Dim D As Double

Similar commands exist for the following types

DefBool     ''  Boolean
DefByte     ''  byte
DefCur      ''  Currency
DefDate     ''  Date
DefDbl      ''  Double
DefDec      ''  Decimal
DefInt      ''  Integer
DefLng      ''  Long
DefObj      ''  Object
DefSng      ''  Single
DefStr      ''  String
DefVar      ''  Variant

Use Console.Write over Console.WriteLine

There is quite a large amount of overhead code necessary to get a snippet of code to execute in VB, and by default this overhead is configured to take up quite a large amount of bytes - for instance

Module M
Sub Main
Console.WriteLine("Hello, World!")
End Sub
End Module

May be golfed down by 4 bytes by the Console.Write(...) command over Console.WriteLine(...).

Module M
Sub Main
Console.Write("Hello, World!")
End Sub
End Module
  • \$\begingroup\$ Tips question are usually required not to offer whitespace and name shortening tips, as they apply for all languages and go under the generic tip question. I don't think this answer should appear here. \$\endgroup\$
    – Uriel
    Commented Feb 15, 2018 at 20:55
  • \$\begingroup\$ @Uriel - you are completely correct, I've modified the response; please continue to let me know anything I can do to improve this resource. \$\endgroup\$ Commented Feb 15, 2018 at 20:58
  • \$\begingroup\$ I still don't think that existence of Write method is worth an answer, but that's debatable. anyway, please refrain from long codes. You could make just fine with only the central line - it just clutters pages \$\endgroup\$
    – Uriel
    Commented Feb 15, 2018 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.