Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help wih code

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am trying the take the following code and change it to VB. Can someone tell me what the equivelent to this., is for VB?

public class DynamicallyAddingControls : System.Web.UI.Page
{
// a Property that manages a counter stored in ViewState
protected int NumberOfControls
{
get{return (int)ViewState["NumControls"];}
set{ViewState["NumControls"] = value;}
}

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
//Initiate the counter of dynamically added controls
this.NumberOfControls = 0;
else
//Controls must be repeatedly be created on postback
this.createControls();
}

// This routine creates the controls and assigns a generic ID
private void createControls()
{
int count = this.NumberOfControls;

for(int i = 0; i < count; i++)
{
TextBox tx = new TextBox();
tx.ID = &quot;ControlID_&quot; + i.ToString();
//Add the Controls to the container of your choice
Page.Controls.Add(tx);
}
}

// example of dynamic addition of controls
// note the use of the ViewState variable
private void addSomeControl()
{
TextBox tx = new TextBox();
tx.ID = &quot;ControlID_&quot; + NumberOfControls.ToString();

Page.Controls.Add(tx);
this.NumberOfControls++;
}

}
 
Here is an example of how a VB.NET class is formatted:
Code:
Public Class clsEmployees
    Private m_intEmployeeID As Int32
    Private m_strFirstName As String
    Private m_strLastName As String
    Private m_strNetworkUserID As String
    Private m_intServiceAreaID As Int32
    Private m_strServiceAreaDescription As String
    Private m_blnRosterAdministrator As Boolean

    Public Sub New()

    End Sub

    Public Sub New(ByVal intEmployeeID As Int32, _
                   ByVal strFirstName As String, _
                   ByVal strLastName As String)
        m_intEmployeeID = intEmployeeID
        m_strFirstName = strFirstName
        m_strLastName = strLastName
    End Sub

    Property EmployeeID() As Int32
        Get
            Return m_intEmployeeID
        End Get
        Set(ByVal Value As Int32)
            m_intEmployeeID = Value
        End Set
    End Property

    Property FirstName() As String
        Get
            Return m_strFirstName
        End Get
        Set(ByVal Value As String)
            m_strFirstName = Value
        End Set
    End Property

    Property LastName() As String
        Get
            Return m_strLastName
        End Get
        Set(ByVal Value As String)
            m_strLastName = Value
        End Set
    End Property

    Property NetworkUserID() As String
        Get
            Return m_strNetworkUserID
        End Get
        Set(ByVal Value As String)
            m_strNetworkUserID = Value
        End Set
    End Property

    Property ServiceAreaID() As Int32
        Get
            Return m_intServiceAreaID
        End Get
        Set(ByVal Value As Int32)
            m_intServiceAreaID = Value
        End Set
    End Property

    Property ServiceAreaDescription() As String
        Get
            Return m_strServiceAreaDescription
        End Get
        Set(ByVal Value As String)
            m_strServiceAreaDescription = Value
        End Set
    End Property

    Property RosterAdministrator() As Boolean
        Get
            Return m_blnRosterAdministrator
        End Get
        Set(ByVal Value As Boolean)
            m_blnRosterAdministrator = Value
        End Set
    End Property

    Public Overrides Function ToString() As String
        Return m_strLastName & &quot;, &quot; & m_strFirstName
    End Function
End Class

Hope this helps.

Rich
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top