Roberto Flores
Roberto Flores

Reputation: 789

Translate C# into VB

Problem:

I currently have the following line of code in C#:

if ((oAEAuthInfo.GetInfo("LetterTo_name") == (oAEAuthInfo.GetInfo("firstname") + " " + oAEAuthInfo.GetInfo("lastname"))) && (oAEAuthInfo.GetInfo("Name")).Contains("OMEGA") || (oAEAuthInfo.GetInfo("Name")).Contains("Alpha"))

and it displays what I want correctly.

However, when I try to do the same thing but in VB:

IF ((oAEAuthInfo.GetInfo("LetterTo_name") = (oAEAuthInfo.GetInfo("firstname") + " " + oAEAuthInfo.GetInfo("lastname"))) And ((oAEAuthInfo.GetInfo("Name")).Contains("Omega") Or (oAEAuthInfo.GetInfo("Name")).Contains("Alpha"))) THEN

It displays no results. Meaning when I run my C# version of the code, it displays an image but for the VB version, nothing occurs.

What am I doing wrong?

UPDATE

Hello Everyone. I would like to thank you all for your help and helping me get a better understanding with VB. However, it is still not displaying any images and I am not sure why.

The following is what I am doing. For some reason, when I try to assigned variables, it did not display any results as well. Any help would be appreciated.

<table width="100%" CELLSPACING="0" CELLPADDING="0">
<tr>
	<td align="center">
	<%
	IF ((oAEAuthInfo.GetInfo("LetterTo_name") = (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname"))) AndAlso ((oAEAuthInfo.GetInfo("Name")).Contains("OMEGA") OrElse (oAEAuthInfo.GetInfo("Name")).Contains("ALPHA"))) THEN
		select (oAEAuthInfo.GetInfo("Site")) 
			case "R107":
			case "R0712":
			case "R108":
			case "R10812":
			case "R113":
			case "R11312":
			case "R115":
			case "R11512":
			case "R10702":
			case "R10802":
			case "R11302":
			case "R11502":
			case "RG112":
				Response.Write("<img src='/images/logos/COLA-m.jpg'>")
			case "RG109":
			case "RG10912":
			case "RG110":
			case "RG11012":
			case "RG10902":
			case "RG11002":
				Response.Write("<img src='/images/logos/regalcodow-m.jpg'>")
      End select
ELSEIF (oAEAuthInfo.GetInfo("Name") = (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname"))) THEN
			case "RG112":
			case "RG11212":
			case "RG11202":
				Response.Write("<img src='/images/logos/RegalBG-m.jpg'>")				
			case "RMG117":
			case "RMG11712":
			case "RMG11702":
				Response.Write("<img src='/images/logos/RegalGle-m.jpg'>")				
			case "MG101":
			case "MG10112":
			case "MG102":
			case "G10212":
			case "G116":
			case "G11612":
			case "118":
			case "11812":
			case "10102":
			case "G10202":
			case "G11602":
			case "G11802":
				Response.Write("<img src='/images/logos/RegalSFV-m.jpg'>")
     End select
Else
		IF((oAEAuthInfo.GetInfo("Facility") <> (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname"))) OrElse (oAEAuthInfo.GetInfo("_ReferredTo") <> (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname"))) OrElse (oAEAuthInfo.GetInfo("ReferredFrom") <> (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname"))) OrElse (oAEAuthInfo.GetInfo("pcpname") <> (oAEAuthInfo.GetInfo("firstname") & " " & oAEAuthInfo.GetInfo("lastname")))) THEN
select (oAEAuthInfo.GetInfo("PatientSite")) 
				case "MG112":
				case "MG11212":
				case "MG11202":
					Response.Write("<img src='/images/logos/RegalBG.bmp'>")				
				case "MG117":
				case "MG11712":
				case "MG11702":
					Response.Write("<img src='/images/logos/RegalGle.bmp'>")					
				case "MG101":
				case "MG10112":
				case "MG102":
				case "MG10212":
				case "RG116":
				case "MG11612":
				case "MG118":
				case "MG11812":
				case "MG10102":
				case "MG10202":
				case "MG11602":
				case "MG11802":
					Response.Write("<img src='/images/logos/RegalSFV.bmp'>")
     End select
  End If
End If
	%>
	</td>
</tr>
</table>

Upvotes: 3

Views: 131

Answers (1)

The Vermilion Wizard
The Vermilion Wizard

Reputation: 5395

A good debugging strategy in a situation like this is to take your evaluations outside your if statement and use the debugger to step through and make sure the values are getting calculated correctly.

C#

var letterToName = oAEAuthInfo.GetInfo("LetterTo_name");
var fullName = oAEAuthInfo.GetInfo("firstname") + " " + oAEAuthInfo.GetInfo("lastname");
var containsOmega = oAEAuthInfo.GetInfo("Name").Contains("OMEGA");
var containsAlpha = oAEAuthInfo.GetInfo("Name").Contains("Alpha");

if ((letterToName == fullName) && containsOmega || containsAlpha)

VB

dim letterToName = oAEAuthInfo.GetInfo("LetterTo_name")
dim fullName = oAEAuthInfo.GetInfo("firstname") + " " + oAEAuthInfo.GetInfo("lastname")
dim containsOmega = oAEAuthInfo.GetInfo("Name").Contains("Omega")
dim containsAlpha = oAEAuthInfo.GetInfo("Name").Contains("Alpha")

IF ((letterToName = fullName) And (containsOmega Or containsAlpha)) THEN

And it becomes clear what your problem is: you have an extra set of parenthesis in the VB code that are missing from the C# code. Order of operations dictate that and operators take precedence over or operators, so in the C# code if containsAlpha is true the condition always passes, whereas in the VB code that will only happen if letterToName = fullName is also true.

Also, case sensitivity of "Omega" may be the problem.

As Visual Vincent pointed out, the And and Or operators do not actually correspond to the behavior of C#'s && and || operators - instead VB's operators that are equivalent would be AndAlso and OrElse. That is unlikely to be the source of the problem in this situation unless GetInfo or Contains have some side-effects.

Upvotes: 7

Related Questions