locked
cnvert c# to vb RRS feed

  • Question

  • User1717218719 posted
    <%@ Page Language="vb" AutoEventWireup="true"  %>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>My Profile Page</title>
        <style type="text/css">
            .auto-style1 {
                width: 187px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h1>
                Profile Settings for: <asp:LoginName ID="LoginName1" runat="server" />
            </h1>
            
            <table border="1">
                <tr>
                    <td>Country:</td>
                    <td class="auto-style1"><asp:Label ID="Country" runat="server" Text="Label"></asp:Label></td>
                </tr>
                
                <tr>
                    <td>Gender:</td>
                    <td class="auto-style1"><asp:Label ID="Gender" runat="server" Text="Label"></asp:Label></td>
                </tr>
            
                <tr>
                    <td>Age:</td>
                    <td class="auto-style1"><asp:Label ID="Age" runat="server" Text="Label"></asp:Label></td>
                </tr>        
            
                 <tr>
                    <td style="align-self:start">Roles:</td>
                    <td class="auto-style1"><asp:ListBox ID="RoleList" runat="server" Width="181px" /></td>
                </tr>       
            
            </table>
            
        </div>
            <p>
                &nbsp;</p>
        </form>
    </body>
    </html>
    
    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Public Class MyProfile
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Country.Text = Profile.Country
            Gender.Text = Profile.Gender
            Age.Text = Profile.Age.ToString
            RoleList.DataSource = Roles.GetRolesForUser(User.Identity.Name)
            RoleList.DataBind
        End Sub
    End Class
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class MyProfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) {
    
            Country.Text = Profile.Country;
            Gender.Text = Profile.Gender;
            Age.Text = Profile.Age.ToString();
    
            RoleList.DataSource = Roles.GetRolesForUser(User.Identity.Name);
            RoleList.DataBind();
        }
    }




    Hi All,

    I am lookingto do a profile page using vb.

    I found the following example but its in c#...I have tried to convert it but with my limited knowledge on c# I am struggling a bit. below Is what I have tried which gives me errors. if anyone could help conver this code that would be great. Thanks

    Friday, September 13, 2019 8:22 AM

All replies

  • User-719153870 posted

    Hi E.RU,

    Here's a website you can use to convert c# to Vb or Vb to c#: Code Converter.

    And the result seems should be :

    Imports System
    Imports System.Data
    Imports System.Configuration
    Imports System.Collections
    Imports System.Web
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.WebControls.WebParts
    Imports System.Web.UI.HtmlControls
    
    Public Partial Class MyProfile
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Country.Text = Profile.Country
            Gender.Text = Profile.Gender
            Age.Text = Profile.Age.ToString()
            RoleList.DataSource = Roles.GetRolesForUser(User.Identity.Name)
            RoleList.DataBind()
        End Sub
    End Class

    You are missing the double brackets for methods.

    Hope this can help.

    Best Regard,

    Yang Shen

    Friday, September 13, 2019 9:08 AM
  • User1717218719 posted

    thank you yang

    however i still get errors on lines:

    Country.Text = Profile.Country

    Gender.Text = Profile.Gender

    Age.Text = Profile.Age.ToString()

    RoleList.DataSource = Roles.GetRolesForUser(User.Identity.Name)

    RoleList.DataBind()

    Friday, September 13, 2019 9:11 AM
  • User753101303 posted

    Hi,

    Strictly speaking it's unrelated to a language issue. RoleList is a control. VS should generate a MyPage.Designer.vb file with the proper control declarations.

    Not sure about Profile. You had https://docs.microsoft.com/en-us/previous-versions/aspnet/2y3fs9xs(v=vs.100) but it's quite old now... The original C# sample doesn't give any explanation about that Profile ?

    Edit: the modern approach would be rather to use https://docs.microsoft.com/en-us/aspnet/identity/overview/getting-started/introduction-to-aspnet-identity 

    Friday, September 13, 2019 9:24 AM