If statement inside Varibale's - Default value

Is it possible to create an if statement and do check on something before writing it?

I have a varibale of fileName… while i create the file name I want to be sure about one thing as i do not want to hardcord value…

varFileName = Now.Date.ToString(“ddMMyy”)+“OfficeNumber”+in_OfficeNumber

Let see I want to check if user is specifik and add user name into the fileName and if user is not same then i do not want to add any name.

Can i do like this as writen down? it gives error :frowning:
varFileName = Now.Date.ToString(“ddMMyy”)+“OfficeNumber”+in_OfficeNumber+if(in_UserName=“Adam” And in_OfficeNumber=“03”) Then("-Adam") Else("")

Sure. You could use “if” operator


i am using if operator

“if” operator has no “then” nor “else”. Check the correct syntax.


Now.ToString(“ddMMyy”)+“OfficeNumber”+in_OfficeNumber+if(in_UserName=“Adam” And in_OfficeNumber=“03”,"-Adam","")

This is your correct syntax (note that it’s Now.ToString not Now.Date.ToString). The If operator takes 3 arguments. Argument 1 is the statement to evaluate, argument 2 is what happens if argument 1 evaluates to True, and argument 3 is what happens if argument 1 evaluates to false.


Thanks @postwick
Problem was that I thought this comma will not help. but it actually did…
thanks for bigg help.


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.