DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 28 May 2007 12:56:03 -0700,    posted on: microsoft.public.dotnet.framework.aspnet.buildingcontrols        back       

Thread Index
  1    jonefer
          2    unknown


Lost in Translation   
Please help, I'm using a converter to translate some C# code.

The following code written in C# does not translate well to Visual Basic
(If I paste it in a C# page, however it has no problems compiling)

//C# Code.....

private string GridViewSortDirection
    {
        get { return ViewState["SortDirection"] as string ?? "ASC"; }
        set { ViewState["SortDirection"] = value; }
    }

 
    private string GridViewSortExpression
    {
        get { return ViewState["SortExpression"] as string ?? string.Empty; }
        set { ViewState["SortExpression"] = value; }
     }

' Here is the VB equivalent

Private Property GridViewSortDirection() As String
	Get 
        	 Return ViewState("SortDirection") as String ?? "ASC"
	End Get
	Set (ByVal Value As String) 
        	 ViewState("SortDirection") = value
	End Set
End Property
 
 
 
    Private Property GridViewSortExpression() As String
    	Get 
        	 Return ViewState("SortExpression") as String ?? String.Empty
    	End Get
    	Set (ByVal Value As String) 
        	 ViewState("SortExpression") = value
    	End Set
    End Property

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net) 
'----------------------------------------------------------------
Date:Mon, 28 May 2007 12:56:03 -0700   Author:  

Re: Lost in Translation   
Vb.Net 2.0 or earlier does not have the coalesce operator (double
question mark).
So you'll need to write it out like so:

Get
  Dim o As Object = ViewState("SortExpression")
  If o Is Nothing Then
    Return String.Empty
  Else
    Return CStr(o)
  End If
End Get

On May 28, 8:56 pm, jonefer  wrote:

> Please help, I'm using a converter to translate some C# code.
>
> The following code written in C# does not translate well to Visual Basic
> (If I paste it in a C# page, however it has no problems compiling)
>
> //C# Code.....
>
> private string GridViewSortDirection
>     {
>         get { return ViewState["SortDirection"] as string ?? "ASC"; }
>         set { ViewState["SortDirection"] = value; }
>     }
>
>     private string GridViewSortExpression
>     {
>         get { return ViewState["SortExpression"] as string ?? string.Empty; }
>         set { ViewState["SortExpression"] = value; }
>      }
>
> ' Here is the VB equivalent
>
> Private Property GridViewSortDirection() As String
>         Get
>                  Return ViewState("SortDirection") as String ?? "ASC"
>         End Get
>         Set (ByVal Value As String)
>                  ViewState("SortDirection") = value
>         End Set
> End Property
>
>     Private Property GridViewSortExpression() As String
>         Get
>                  Return ViewState("SortExpression") as String ?? String.Empty
>         End Get
>         Set (ByVal Value As String)
>                  ViewState("SortExpression") = value
>         End Set
>     End Property
>
> '----------------------------------------------------------------
> ' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
> ' Developed by: Kamal Patel (http://www.KamalPatel.net)
> '----------------------------------------------------------------
Date:29 May 2007 05:51:32 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us