STDIN and STDOUT
Functions via input variables
Public Sub A(ByRef B as String)
May be reduced down to
ByRef calls are the default for VBA and thus implicit, and may (almost) always be dropped.
The type literal
b to be of the type
Other type literals
^ LongLong (64 Bit Only)
Furthermore, it is generally accepted that you may leave the input variable as the default type,
Variant and leave any type-based errors unhandled. Eg.
Sub E(F) in which
F is expected to be of type
Boolean (which would be passed to the routine like
E Array(True, False, False))
Subroutines and Immediate Window Functions via
VBA does not have a fully functional console and thus does not have any official STDIN, and thus allows for some play with passing input.
In excel, it is generally accepted to take input from a cell or range of cells, which may be done like
which implicitly puts the
.value from the cell
[A1] (which may also be referenced as
Example Problem: Display the input in a messagebox
Sub A:msgbox[A1]:End Sub
Via Immediates Window Function
Inputting Via Conditional Compilation Arguments
VBA Projects support taking arguments from the command line or via the VBAProject Properties (view via the project explorer -> [Your VBA Project] -(Right Click)-> VBAProject Properties -> Conditional Compilation Arguments)
This is largely useful for Error Code Challenges
Given the Conditional Compilation Argument
n=[some_value] this allows for executing code that will produce an error code, based off of the value of
note, this calls for an addition of 2 bytes to your code for the
n= in the conditional compilation arguments section of the VBAProject Properties Pane.
#If n=3 then
return '' Produces error code '3', Return without GoSub
#ElseIf n=20 then
resume '' Produces error code '20', Resume without Error
Outputting Via Function Value
Not Much to say here, the general form of quoted below is about as compact as it can be made.
Public Function A(b)
NOTE: in the vast majority of cases it is more byte convert the method to a subroutine and output to the VBE immediates window (see Below)
Functions via the VBE Immediates Window
Outputting to the VBE immediates window (AKA the VBE Debug Window) is a common output method for VBA for text based challenges, however, it is important to remember that the
Debug.Print "Text" call may be substantially golfed.
is functionally identical to
? autoformats to
Subroutines and VBE Immediates Window functions via Other Methods
On rare occasion, when the situation is just right, you may take input from some of the more trivial inputs available to VBA such as the font size adjuster, font selector, and zoom. (Eg. Emulating the Word Font Size Selector)