What language is InfoPath set to use? If VBScript, that's why it doesn't understand 'var'. If you are using Managed Code through Visual Studio, then you would be using VB.NET or C# -- neither of which understand 'var'.
Look under Tools | Options to find out what language your form is set to be using.