Skip to content
+1-888-319-3663

COMMUNITY FORUM

Nested If, Then Statement

John asked 2 years ago
Hi:
Please explain why the following nested if, then syntax doesn’t work and how to fix it:
If _COUNTRYCODE = “USA” Then return “US”
if _COUNTRYCODE = “AUS” Then return “AU”
if _COUNTRYCODE = “BLZ” Then return “BZ”
if _COUNTRYCODE = “CUB” Then return “CU”
if _COUNTRYCODE = “MEX” Then return “MX”
if _COUNTRYCODE = “NIG” Then return “NG”
if _COUNTRYCODE = “STM” Then return “SX”
if _COUNTRYCODE = “SAA” Then return “GY”
else return _COUNTRYCODE
end if
Thanks!
John
Answers
Patrick Roth Staff answered 2 years ago
John,
The nice thing about SC is that you are writing standard .NET code – vb in your case – and so we can pull examples from the internet on how to do things.
So in your case, what you really are looking for is various “if/elseif” statements (you are missing elseif)
https://www.dotnetperls.com/if-vbnet
Instead of using if/elseif though, I’d consider switching to a select/case statement
https://www.tutorialspoint.com/vb.net/vb.net_select_case_statements.htm
as it is easier to read (to me) and add lines without using multiple if/then/else branches.
patrick

If you would like to submit an answer or comment, please sign in to the eOne portal.