1

Ok... I guess my brain has finally gone on vacation without me today. I have extracted 2 fields from a website and I get this string

vData = "Amount Owed [EXTRACT]$125.00[EXTRACT]

vData was declared as an array (string).

I split vData on [EXTRACT] and I end up with 2 string variables like this:

varA = "Amount Owed"
varB = "$125.00"

To parse varB, I use

Dim varC as Currency
varC = val(varB)

I want to use varC in an If statement:

If Val(VarC) <> 0 Then

I was expecting varC to be 125 but when I look at varC is 0. I can't figure out why varC = 0 and not 125.

cxw
  • 16,685
  • 2
  • 45
  • 81
Shaves
  • 884
  • 5
  • 16
  • 46

1 Answers1

1

Use CCur(varB) instead of Val(varB). CCur converts to a Currency type, so knows about $ and other things.

Explanation from the MS docs:

... when you use CCur, different decimal separators, different thousand separators, and various currency options are properly recognized depending on the locale setting of your computer.

Val is only looking for straight numbers:

The Val function stops reading the string at the first character it can't recognize as part of a number. Symbols and characters that are often considered parts of numeric values, such as dollar signs and commas, are not recognized.

cxw
  • 16,685
  • 2
  • 45
  • 81
  • @cxw..............Thanks for the information and suggestion. I think I had used "val" in the past (without the $ sign) so it probably gave me the number I was looking for. – Shaves Jun 28 '16 at 19:35