7

What does the following mean?

Class.Function(variable := 1 + 1)

What is this operator called, and what does it do?

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
Kevin
  • 13,044
  • 11
  • 55
  • 76

3 Answers3

11

It is used to assign optional variables, without assigning the previous ones.

sub test(optional a as string = "", optional b as string = "")
   msgbox(a & b)
end sub

you can now do

test(b:= "blaat")
'in stead of
test("", "blaat")
Ikke
  • 99,403
  • 23
  • 97
  • 120
  • 1
    I also use it sometimes for required variables. For example if I have a function that takes multiple boolean flags (the horrors!) then I can do something like `DoTheThing(doItFast := True, doItNow := True...)` so that it's clear what flags I'm setting (as opposed to `DoTheThing(True, True, False, True, False, False, False)` :P) – Jeff B Dec 07 '12 at 16:48
0

It assigns the optional parameter "variable" the value 2.

Nescio
  • 27,645
  • 10
  • 53
  • 72
0

VB.NET supports this syntax for named (optional) parameters in method calls. This particular syntax informs Class.Function that its parameter variable is to be set to 2 (1 + 1).

John Rudy
  • 37,282
  • 14
  • 64
  • 100