locked
Is Already Declared As 'Protected.. RRS feed

  • Question

  • User1810613429 posted

    Hello, I've got to program something in C# and VB.net and I've gotten the C# but VB is giving me more diffuculties. I keep getting this:

    Button_Click is already declared as 'Protected...

     

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    <script runat="server">
    	
        Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim names(5) As String
            Dim number As Integer = 0
            Dim check As Integer = 0
            If number < names.Length Then
                For count As Integer = 0 To number
                    If String.Compare(names(number), names(count)) Then
                        check = 0
                        Label1.Text = "You have to enter a different name!"
                        Exit For
                    Else : check = 1
                        
                    End If
                Next
    				
                If check = 1 Then
                    names(number) = txtBoxNames.Text
                    Label1.Text = "Enter another student's name"
                    number = number + 1
                End If
    		
            Else : Label1.Text = "You've Entered to many names!"
            End If
        End Sub
    
    
    
    Sub btnDisplay_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim namelist As String
            For count As Integer = 0 To number
            
                namelist &= "<br />" + names(number)
            Next
    	
            lblTextResults.Text &= "Students Entered: " + "<br />" + namelist
            number = 0
        End Sub
            
    </script>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Matthew Carnali Lab 1</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
    
        <asp:Label
            id="Label1"
            Text="Enter A Student's Name: "
            AssociatedControlID="txtBoxNames"
            Runat="server" 
            />
    <br />  
    <br />  
    
    <asp:TextBox
    id="txtBoxNames"
    Runat="server" />
    
    <asp:RegularExpressionValidator
         id="reqPersonName"
         ControlToValidate="txtBoxNames"
         Text="(No Numbers)"
         ValidationExpression="^[a-zA-Z''-'\s]{1,40}$"
         Runat="server" />  
    <br />  
    <br />
    <asp:RangeValidator
        id="reqLength"
        ControlToValidate="txtBoxNames"
        Text="(Too Short!)"
        MinimumValue="2"
        MaximumValue="100"
        Type="String"
        Runat="server" />
    
        <asp:Button
            id="Button_Click"
            Text="Enter"
            CommandName="Add_Name"
            OnClick="btnEnter_Click"
            Runat="server" />
    
          
       
            
            <br />
            <br />
    
            <asp:Button
            id="btnDisplay_Click"
            Text="Display All Names and Exit"
            OnClick="btnDisplay_Click"
            Runat="server" />
        
        <br /><br />
        
    <asp:Label
    id="lblTextResults"
    Runat="server"/>
    <br /><br />
        
        </div>
        </form>
    </body>
    </html>
    

    Monday, September 10, 2012 2:52 PM

Answers

  • User1810613429 posted

    I solved my issue but one last issue remains, , for some reason the array will not populate than display with the second button. Not sure if its the comparison of strings that might be causing this issue:

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    <script runat="server">
        Public names(6) As String
        Public number As Integer = 1
        Public check As Integer = 0
        Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
            
            If number < names.Length Then
                For count As Integer = 0 To number
                    If String.Compare(names(number), names(count)) Then
                        check = 0
                        Label1.Text = "You have to enter a different name!"
                        Exit For
                    Else : check = 1
                        
                    End If
                Next
    				
                If check = 1 Then
                    names(number) = txtBoxNames.Text
                    Label1.Text = "Enter another student's name"
                    number = number + 1
                End If
    		
            Else : Label1.Text = "You've Entered to many names!"
            End If
        End Sub
    
    
        Dim namelist As String
    Sub btnDisplay_Click(ByVal sender As Object, ByVal e As EventArgs)
            
            For count As Integer = 0 To number
            
                namelist &= "<br />" + names(count)
            Next
    	
            lblTextResults.Text &= "Students Entered: " + "<br />" + namelist
            number = 1
        End Sub
            
    </script>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Matthew Carnali Lab 1</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
    
        <asp:Label
            id="Label1"
            Text="Enter A Student's Name: "
            AssociatedControlID="txtBoxNames"
            Runat="server" 
            />
    <br />  
    <br />  
    
    <asp:TextBox
    id="txtBoxNames"
    Runat="server" />
    
    <asp:RegularExpressionValidator
         id="reqPersonName"
         ControlToValidate="txtBoxNames"
         Text="(No Numbers)"
         ValidationExpression="^[a-zA-Z''-'\s]{1,40}$"
         Runat="server" />  
    <br />  
    <br />
    
    
        <asp:Button
            id="Button"
            Text="Enter"
            CommandName="Add_Name"
            OnClick="Button_Click"
            Runat="server" />
    
          
       
            
            <br />
            <br />
    
            <asp:Button
            id="btnDisplay"
            Text="Display All Names and Exit"
            OnClick="btnDisplay_Click"
            Runat="server" />
        
        <br /><br />
        
    <asp:Label
    id="lblTextResults"
    Runat="server"/>
    <br /><br />
        
        </div>
        </form>
    </body>
    </html>

     

     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2012 4:56 PM

All replies

  • User1810613429 posted

    I solved my issue but one last issue remains, , for some reason the array will not populate than display with the second button. Not sure if its the comparison of strings that might be causing this issue:

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    <script runat="server">
        Public names(6) As String
        Public number As Integer = 1
        Public check As Integer = 0
        Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
            
            If number < names.Length Then
                For count As Integer = 0 To number
                    If String.Compare(names(number), names(count)) Then
                        check = 0
                        Label1.Text = "You have to enter a different name!"
                        Exit For
                    Else : check = 1
                        
                    End If
                Next
    				
                If check = 1 Then
                    names(number) = txtBoxNames.Text
                    Label1.Text = "Enter another student's name"
                    number = number + 1
                End If
    		
            Else : Label1.Text = "You've Entered to many names!"
            End If
        End Sub
    
    
        Dim namelist As String
    Sub btnDisplay_Click(ByVal sender As Object, ByVal e As EventArgs)
            
            For count As Integer = 0 To number
            
                namelist &= "<br />" + names(count)
            Next
    	
            lblTextResults.Text &= "Students Entered: " + "<br />" + namelist
            number = 1
        End Sub
            
    </script>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Matthew Carnali Lab 1</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
    
        <asp:Label
            id="Label1"
            Text="Enter A Student's Name: "
            AssociatedControlID="txtBoxNames"
            Runat="server" 
            />
    <br />  
    <br />  
    
    <asp:TextBox
    id="txtBoxNames"
    Runat="server" />
    
    <asp:RegularExpressionValidator
         id="reqPersonName"
         ControlToValidate="txtBoxNames"
         Text="(No Numbers)"
         ValidationExpression="^[a-zA-Z''-'\s]{1,40}$"
         Runat="server" />  
    <br />  
    <br />
    
    
        <asp:Button
            id="Button"
            Text="Enter"
            CommandName="Add_Name"
            OnClick="Button_Click"
            Runat="server" />
    
          
       
            
            <br />
            <br />
    
            <asp:Button
            id="btnDisplay"
            Text="Display All Names and Exit"
            OnClick="btnDisplay_Click"
            Runat="server" />
        
        <br /><br />
        
    <asp:Label
    id="lblTextResults"
    Runat="server"/>
    <br /><br />
        
        </div>
        </form>
    </body>
    </html>

     

     


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2012 4:56 PM
  • User397347636 posted

    String.Compare returns an integer - please don't rely on VB's conversion of the integer result to a boolean condition.  VB allows you to write crap and it will try to interpret the crap, but you have to be strong and resist that urge.

    Monday, September 10, 2012 9:09 PM