Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27350

VS 2010 [RESOLVED] Button properties

$
0
0
Hey all.

I have a function that is used to change the properties of some buttons. This funtion is called within a loop and each button is assign a number. when it calls the function an id is used. Hope the code below helps! but is there an easier way to do the following.
I ask as in total there is 15 button to change. As you can see the "id" number is the same as the Btn_Add number.

Code:

Sub RenderPageBtn(ByVal id As Integer, ByVal text As String, ByVal price As String, ByVal stock As String)
        ' Button 1
        If id = 1 Then
            If text = "product" Then
                With MainScreen
                    .Btn_Add1.Visible = False
                    .Price1.Visible = False
                    .Stock1.Visible = False
                    .Quantity1.Visible = False
                    .Cost1.Visible = False
                End With
            Else
                With MainScreen
                    .Btn_Add1.Text = text
                    .Price1.Text = "£" & price
                    .Stock1.Text = stock
                End With
            End If
        End If

        ' Button 2
        If id = 2 Then
            If text = "product" Then
                With MainScreen
                    .Btn_Add2.Visible = False
                    .Price2.Visible = False
                    .Stock2.Visible = False
                    .Quantity2.Visible = False
                    .Cost2.Visible = False
                End With
            Else
                With MainScreen
                    .Btn_Add2.Text = text
                    .Price2.Text = "£" & price
                    .Stock2.Text = stock
                End With
            End If
        End If

        ' Button 3
        If id = 3 Then
            If text = "product" Then
                With MainScreen
                    .Btn_Add3.Visible = False
                    .Price3.Visible = False
                    .Stock3.Visible = False
                    .Quantity3.Visible = False
                    .Cost3.Visible = False
                End With
            Else
                With MainScreen
                    .Btn_Add3.Text = text
                    .Price3.Text = "£" & price
                    .Stock3.Text = stock
                End With
            End If
        End If

        ' Button 4
        If id = 4 Then
            If text = "product" Then
                With MainScreen
                    .Btn_Add4.Visible = False
                    .Price4.Visible = False
                    .Stock4.Visible = False
                    .Quantity4.Visible = False
                    .Cost4.Visible = False
                End With
            Else
                With MainScreen
                    .Btn_Add4.Text = text
                    .Price4.Text = "£" & price
                    .Stock4.Text = stock
                End With
            End If

            //........ 15 buttons later! .......//

        End If
    End Sub


Viewing all articles
Browse latest Browse all 27350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>