Results 1 to 12 of 12

Thread: quick translation needed ( c# to vb )

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    Arrow quick translation needed ( c# to vb )

    hi,

    it would be very kind if someone helps me out here, i need this code translated to vb.net.

    i understand most of it, like one thing i cant figure out is the " continue" method? whats the equilivent of that in vb.net?!!!

    Code:
    foreach(XmlNode xnode in section.ChildNodes)
    			{	
    				if(!(xnode.NodeType == XmlNodeType.Element && xnode.Attributes != null)) continue ; 
    
    				if(xnode.Attributes["domainlocal"] != null && Convert.ToBoolean(xnode.Attributes["domainlocal"].Value) == false)
    				{
    					//host list needs to be mentioned, if domainlocal is false
    					if(xnode.Attributes["host"] == null)	throw new ApplicationException("Configuration Error : For Single Signon Targets that are not local to the domain, a host list must be provided");
    					_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["host"].Value));
    				}
    				else
    				{
    					if(xnode.Attributes["name"] == null)  throw new ApplicationException(" Configuration Error : For Single Signon Targets that are local to the domain, a cookie name must be provided");
    					if(xnode.Attributes["path"] == null)  throw new ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided");
    					if(xnode.Attributes["persistent"] == null)  throw new ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided");
    					_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["name"].Value,xnode.Attributes["path"].Value,Convert.ToBoolean(xnode.Attributes["persistent"].Value)));
    				}
    			}
    Last edited by persianboy; Nov 11th, 2003 at 11:48 AM.

  2. #2
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108
    Umm, ok so far so good. But when you call 'continue', what do you expect it to do? cuz my program can't determine what Continue does. does it continue with the sub. if it does, are there any other tasks used with continue before heading on to the next line of code?
    Last edited by Danny J; Nov 11th, 2003 at 12:20 PM.
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    continue is not a method, as stated in MSDN lib:
    The continue statement passes control to the next iteration of the enclosing iteration statement in which it appears.
    which means that if you are in a loop or something like that it stops the execution flow there and continues in the next FOR
    \m/\m/

  4. #4
    Lively Member
    Join Date
    Aug 2003
    Location
    When?!?!
    Posts
    108
    If the code below doesn't function the way it did in CS, please contact me immediatly, and tell me what is going wrong so I can tweak my application.

    VB Code:
    1. Public Sub TranslatedOutput()
    2.  
    3.         'Code translated with Danny J's .NET Code Converter ALPHA created by Danny Joumaa
    4.  
    5.         Dim xnode As Xml.XmlNode
    6.  
    7.         For Each xnode In xnode.ChildNodes
    8.             'TODO: Method 'continue' could not be recodnized. User suggested new code.
    9.             If Not (xnode.NodeType = Xml.XmlNodeType.Element And xnode.Attributes Is Nothing) Then Exit Sub
    10.             If (xnode.Attributes("domainlocal") Is Nothing & Convert.ToBoolean(xnode.Attributes("domainlocal").Value)) = False Then
    11.  
    12.                 'host list needs to be mentioned, if domainlocal is false
    13.                 If (xnode.Attributes("host") Is Nothing) Then Throw New ApplicationException(" Configuration Error : For Single Signon Targets that that are local to the domain, a cookie name must be provided")
    14.                 If (xnode.Attributes("path") Is Nothing) Then Throw New ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided")
    15.                 If (xnode.Attributes("persistent") Is Nothing) Then Throw New ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided")
    16.                 'TODO: The code below could not be translated. Please translate this code manually.
    17.                 '_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["name"].Value,xnode.Attributes["path"].Value,Convert.ToBoolean(xnode.Attributes["persistent"].Value)));
    18.             End If
    19.  
    20.         Next
    21.     End Sub

    Cheers!
    DannyJoumaa
    Advanced VB6 Programmer
    Intermediate-Advanced VB .NET Programmer
    Intermediate C# Programmer
    Intermediate Win32 Developer
    Beginner Mac OS X Developer
    Contact: [email protected]

    Favorite Sayings:
    "Every time you open your mouth, you prove your an idiot."
    "God is a programmer. Satan is a bug. Life is debugging."

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    i dont have vs around to test it, but it seems its not correct

    Code:
    Public Sub TranslatedOutput()
    
          
            Dim xnode As Xml.XmlNode
    
            For Each xnode In xnode.ChildNodes
          
    ' i dont think what the continue does is to exit the for, i think it should move on to the next xnode without processing the code under it , tell me if i'm wrong?? ( and you missed a not too )
    
                If Not (xnode.NodeType = Xml.XmlNodeType.Element And Not xnode.Attributes Is Nothing) Then Exit Sub
                If (xnode.Attributes("domainlocal") Is Nothing & Convert.ToBoolean(xnode.Attributes("domainlocal").Value)) = False Then
    
                    'host list needs to be mentioned, if domainlocal is false
                    If (xnode.Attributes("host") Is Nothing) Then Throw New ApplicationException(" Configuration Error : For Single Signon Targets that that are local to the domain, a cookie name must be provided")
                    If (xnode.Attributes("path") Is Nothing) Then Throw New ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided")
                    If (xnode.Attributes("persistent") Is Nothing) Then Throw New ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided")
                    'TODO: The code below could not be translated. Please translate this code manually.
                    '_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["name"].Value,xnode.Attributes["path"].Value,Convert.ToBoolean(xnode.Attributes["persistent"].Value)));
                End If
    
            Next
        End Sub
    ]

    so the main thing here is the continue, how to translate that?

  6. #6
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    of course it can't be correct, he did put "exit sub" in the place of a "continue" that are completly different things
    \m/\m/

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Originally posted by PT Exorcist
    of course it can't be correct, he did put "exit sub" in the place of a "continue" that are completly different things
    LMAO, Ah the perils of using an automated C# translator

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    Code:
       Dim xnode As XmlNode
                For Each xnode In section.ChildNodes
                    If xnode.NodeType = XmlNodeType.Element And Not xnode.Attributes Is Nothing Then
                        If Not xnode.Attributes("domainlocal") Is Nothing And Convert.ToBoolean(xnode.Attributes("domainlocal").Value) = False Then
                            If xnode.Attributes("host") Is Nothing Then Throw New ApplicationException("Authentication Configuratio Error : For SignOn Targets that are not local to the domain , a host list must be porvided")
                            _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("host").Value))
                        Else
                            If xnode.Attributes("name") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are not local to the domain, a host list must be provided")
                            If xnode.Attributes("path") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided")
                            If xnode.Attributes("persistent") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided")
                            _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("name").Value, xnode.Attributes("path").Value, Convert.ToBoolean(xnode.Attributes("persistent").Value)))
                        End If
                    End If
                Next
    is this how it should look like in vb.net?!!!!!!!
    ( cant test it in code, since i havent finished translating othere related parts )

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    well, its 100% syntax-correct. Compiler doesn't complain.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    this continue is whats got me confused a little , maybe this exp will help me figure it out



    for a=1 to 3
    if a=2 then continue
    str &=a
    next
    lbltext.text=str


    so finally is the labels text 13 or 1??


    p.s i dont if this is how the syntax of for...next is in C#, anyways thats not the idea of the question

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    According to the original code posted, I'm guessing it should not process the rest of the for loop if the node is an element. I only say that because, it appears they are trying to catch exceptions, and if its the smallest child node, it would not contain any other nodes:
    VB Code:
    1. Dim xnode As XmlNode
    2.             For Each xnode In section.ChildNodes
    3.                 If xnode.NodeType = XmlNodeType.Element And Not xnode.Attributes Is Nothing Then [b]Continue[/b]
    4.                     If Not xnode.Attributes("domainlocal") Is Nothing And Convert.ToBoolean(xnode.Attributes("domainlocal").Value) = False Then
    5.                         If xnode.Attributes("host") Is Nothing Then Throw New ApplicationException("Authentication Configuratio Error : For SignOn Targets that are not local to the domain , a host list must be porvided")
    6.                         _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("host").Value))
    7.                     Else
    8.                         If xnode.Attributes("name") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are not local to the domain, a host list must be provided")
    9.                         If xnode.Attributes("path") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided")
    10.                         If xnode.Attributes("persistent") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided")
    11.                         _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("name").Value, xnode.Attributes("path").Value, Convert.ToBoolean(xnode.Attributes("persistent").Value)))
    12.                     End If
    13.                 End If
    14.             Next

    Persian, as far as your example:
    VB Code:
    1. for a=1 to 3
    2. if a=2 then continue
    3. str &=a
    4. next
    5. lbltext.text=str

    If a=2, then it skips str&=a.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    so finally this code in c#

    Code:
    foreach(XmlNode xnode in section.ChildNodes)
    			{	
    				if(!(xnode.NodeType == XmlNodeType.Element && xnode.Attributes != null)) continue ; 
    
    				if(xnode.Attributes["domainlocal"] != null && Convert.ToBoolean(xnode.Attributes["domainlocal"].Value) == false)
    				{
    					//host list needs to be mentioned, if domainlocal is false
    					if(xnode.Attributes["host"] == null)	throw new ApplicationException("Configuration Error : For Single Signon Targets that are not local to the domain, a host list must be provided");
    					_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["host"].Value));
    				}
    				else
    				{
    					if(xnode.Attributes["name"] == null)  throw new ApplicationException(" Configuration Error : For Single Signon Targets that are local to the domain, a cookie name must be provided");
    					if(xnode.Attributes["path"] == null)  throw new ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided");
    					if(xnode.Attributes["persistent"] == null)  throw new ApplicationException("Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided");
    					_SingleSignonTargetList.Add(new SampleAuthenticationSingleSignonTarget(xnode.Attributes["name"].Value,xnode.Attributes["path"].Value,Convert.ToBoolean(xnode.Attributes["persistent"].Value)));
    				}
    			}
    is equil to the code beneath in vb.net


    Code:
     Dim xnode As XmlNode
                For Each xnode In section.ChildNodes
                    If xnode.NodeType = XmlNodeType.Element And Not xnode.Attributes Is Nothing Then
                        If Not xnode.Attributes("domainlocal") Is Nothing And Convert.ToBoolean(xnode.Attributes("domainlocal").Value) = False Then
                            If xnode.Attributes("host") Is Nothing Then Throw New ApplicationException("Authentication Configuratio Error : For SignOn Targets that are not local to the domain , a host list must be porvided")
                            _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("host").Value))
                        Else
                            If xnode.Attributes("name") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are not local to the domain, a host list must be provided")
                            If xnode.Attributes("path") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie path must be provided")
                            If xnode.Attributes("persistent") Is Nothing Then Throw New ApplicationException("Authentication Configuration Error : For Single Signon Targets that are local to the domain, a cookie persistence indicator must be provided")
                            _SingleSignOnTargetList.Add(New Authentication.AuthenticationSingleSignOnTarget(xnode.Attributes("name").Value, xnode.Attributes("path").Value, Convert.ToBoolean(xnode.Attributes("persistent").Value)))
                        End If
                    End If
                Next


    thanks to all

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width