FUNCTION PBMAIN() AS LONG
  LOCAL v AS VARIANT
  LOCAL d AS DOUBLE
  LOCAL r AS LONG
  
  r = 0
  
  ' Uninitialized variant should report VT_EMPTY (0)
  IF VARIANTVT(v) <> 0 THEN r = 1
  
  ' Assign a double via VARIANT#()
  VARIANT#(v) = 3.125
  IF VARIANTVT(v) <> 5 THEN r = 2
  
  d = VARIANT#(v)
  IF d < 3.124 OR d > 3.126 THEN r = 3
  
  ' Assign an integer
  v = 42
  IF VARIANTVT(v) <> 20 THEN r = 6
  IF VARIANT%(v) <> 42 THEN r = 7

  ' Assign a boolean
  v = TRUE
  IF VARIANTVT(v) <> 11 THEN r = 8

  ' Assign a currency
  LOCAL c AS CURRENCY
  c = 12.34
  v = c
  IF VARIANTVT(v) <> 6 THEN r = 9

  ' Assign a string
  v = "hello variant"
  IF VARIANTVT(v) <> 8 THEN r = 4
  IF VARIANT$(v) <> "hello variant" THEN r = 5

  ' Direct VARIANT comparison
  LOCAL v1 AS VARIANT
  LOCAL v2 AS VARIANT
  v1 = 42
  v2 = 42
  IF NOT (v1 = v2) THEN r = 10
  v2 = 43
  IF v1 = v2 THEN r = 11
  v1 = "abc"
  v2 = "abc"
  IF NOT (v1 = v2) THEN r = 12
  v1 = 3.125
  v2 = 3.125
  IF NOT (v1 = v2) THEN r = 13
  
  IF r = 0 THEN FUNCTION = 1 ELSE FUNCTION = r + 1
END FUNCTION
