Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Hi,
 
Any one please convert this code in C# Code

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Text
 

Namespace LNTSystems.CommonControls
    Partial Class MsgBox
        Inherits System.Web.UI.UserControl
 
#Region " Web Form Designer Generated Code "
 
        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
        End Sub
 

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub
 
#End Region
        Private content As String
        Public Sub alert(ByVal msg As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<script language="'javascript'">")
            sb.Append("alert( """ + sMsg + """ );")
            sb.Append("</script>")
            content = sb.ToString
        End Sub
        Public Sub alert(ByVal msg As String, ByVal Redirect As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<script language="'javascript'">")
            sb.Append("alert( """ + sMsg + """ );")
            sb.Append("window.navigate( """ + Redirect + """ );")
            sb.Append("</script>")
            content = sb.ToString
        End Sub
 
        Public Sub confirm(ByVal msg As String, ByVal hiddenfield_name As String)
            Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
            sMsg = msg.Replace("""", "'")
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("<INPUT type=hidden value='0' name='" + hiddenfield_name + "'>")
            sb.Append("<script language="'javascript'">")
            sb.Append(" if(confirm( """ + sMsg + """ ))")
            sb.Append(" { ")
            sb.Append("document.forms[0]." + hiddenfield_name + ".value='1';" + "document.forms[0].submit(); }")
            sb.Append(" else { ")
            sb.Append("document.forms[0]." + hiddenfield_name + ".value='0'; }")
            sb.Append("</script>")
            content = sb.ToString
        End Sub
 
        Protected Overloads Overrides Sub Render(ByVal output As HtmlTextWriter)
            output.Write(Me.content)
        End Sub
 
    End Class
 
End Namespace
 
 
i'm following this link . but in above code hwenever "Chr" is there in that it show some error doesn't contain a definition for Chr.
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]
Posted 29-Nov-12 1:54am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here is a tool: http://www.tangiblesoftwaresolutions.com/[^]Since conversion tool sometimes have wrong code, so I am not sure it must be all right after converting, you can try. Good luck!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Code translators aren't 100% in converting from VB.NET to C#, you will need to manually change some code like you have found the Microsoft.VisualBasic.Chr(10) as one of them
 
these links show you how to do the same in C#
 
What is the C# equivalent of the chr() function?[^]
 
C# equivilent for Asc and Chr[^]
 
but here is a simple example conversion
 
  Dim sMsg As String = msg.Replace("" & Microsoft.VisualBasic.Chr(10) & "", "\n")
 
To
 
  Char newLine = (char)10;
  string sMsg = msg.Replace(newLine, @"\n");
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 404
1 Richard MacCutchan 240
2 OriginalGriff 230
3 Jared Sanow 145
4 Vinay Mistry 143
0 Sergey Alexandrovich Kryukov 5,955
1 OriginalGriff 4,805
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100