Results 1 to 4 of 4

Thread: Why doesn't this work for buttons like it does for labels

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2016
    Posts
    106

    Why doesn't this work for buttons like it does for labels

    I created 20 labels and populated each label with text from a sql database. When the text changes in the database, I can load the new text into the labels:
    Code:
    Public Sub Top11RowsCount()
            Dim BE As Integer = 0
            Dim Top11Cnt() As Label = {LBL2ndRowCnt01, LBL2ndRowCnt02, LBL2ndRowCnt03, LBL2ndRowCnt04, LBL2ndRowCnt05, LBL2ndRowCnt06, LBL2ndRowCnt07, LBL2ndRowCnt08, LBL2ndRowCnt09, LBL2ndRowCnt10, LBL2ndRowCnt11, LBL2ndRowCnt12, LBL2ndRowCnt13, LBL2ndRowCnt14, LBL2ndRowCnt15, LBL2ndRowCnt16, LBL2ndRowCnt17, LBL2ndRowCnt18, LBL2ndRowCnt19, LBL2ndRowCnt20}
            Sql.ExecQuery("Select SpotNbr,SpotCnt from JKP11Count order by SpotNbr")
            For Each r As DataRow In Sql.DBDT.Rows
                Top11Cnt(BE).Text = r("SpotNbr")
                Top11Cnt(BE).Text = r("SpotCnt")
                BE += 1
            Next
        End Sub
    I added 20 buttons to another panel and tried basically the same code except for buttons instead of labels:
    Code:
    Public Sub Top1stRow()
            Dim BB As Integer = 0
            Dim Top1BTN() As Button = {BTN1stRow01, BTN1stRow02, BTN1stRow03, BTN1stRow04, BTN1stRow05, BTN1stRow06, BTN1stRow07, BTN1stRow08, BTN1stRow09, BTN1stRow10, BTN1stRow11, BTN1stRow12, BTN1stRow13, BTN1stRow14, BTN1stRow15, BTN1stRow16, BTN1stRow17, BTN1stRow18, BTN1stRow19, BTN1stRow20}
            'This pulls the top 1 record from SP1stLastRow
            Sql.ExecQuery("Select KenSeqNbr,SpotNbr from JKP1stRow  order by Spotnbr ")
            For Each r As DataRow In Sql.DBDT.Rows
                LBLLastDraw.Text = r("KenSeqNbr")
                Top1BTN(BB).Text = r("Spotnbr")
                BB += 1
            Next
        End Sub
    With this code, I get the following error:
    BC30311.Value of type 'button' cannot be converted to 'VisualStyleElement.Toolbar.Button'

    I did google the error and couldn't find an answer that I could understand. (The answers didn't include exactly what I was doing.)
    My question is why does this work so well with labels and not buttons?
    I created the buttons using the button tool and the names of the buttons correlate with the dim statement.
    Thanks
    I don't program, I beat code into submission!!!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2016
    Posts
    106

    Re: Why doesn't this work for buttons like it does for labels ***Resolved***

    Quote Originally Posted by vbcub View Post
    I created 20 labels and populated each label with text from a sql database. When the text changes in the database, I can load the new text into the labels:
    Code:
    Public Sub Top11RowsCount()
            Dim BE As Integer = 0
            Dim Top11Cnt() As Label = {LBL2ndRowCnt01, LBL2ndRowCnt02, LBL2ndRowCnt03, LBL2ndRowCnt04, LBL2ndRowCnt05, LBL2ndRowCnt06, LBL2ndRowCnt07, LBL2ndRowCnt08, LBL2ndRowCnt09, LBL2ndRowCnt10, LBL2ndRowCnt11, LBL2ndRowCnt12, LBL2ndRowCnt13, LBL2ndRowCnt14, LBL2ndRowCnt15, LBL2ndRowCnt16, LBL2ndRowCnt17, LBL2ndRowCnt18, LBL2ndRowCnt19, LBL2ndRowCnt20}
            Sql.ExecQuery("Select SpotNbr,SpotCnt from JKP11Count order by SpotNbr")
            For Each r As DataRow In Sql.DBDT.Rows
                Top11Cnt(BE).Text = r("SpotNbr")
                Top11Cnt(BE).Text = r("SpotCnt")
                BE += 1
            Next
        End Sub
    I added 20 buttons to another panel and tried basically the same code except for buttons instead of labels:
    Code:
    Public Sub Top1stRow()
            Dim BB As Integer = 0
            Dim Top1BTN() As Button= {BTN1stRow01, BTN1stRow02, BTN1stRow03, BTN1stRow04, BTN1stRow05, BTN1stRow06, BTN1stRow07, BTN1stRow08, BTN1stRow09, BTN1stRow10, BTN1stRow11, BTN1stRow12, BTN1stRow13, BTN1stRow14, BTN1stRow15, BTN1stRow16, BTN1stRow17, BTN1stRow18, BTN1stRow19, BTN1stRow20}
            'This pulls the top 1 record from SP1stLastRow
            Sql.ExecQuery("Select KenSeqNbr,SpotNbr from JKP1stRow  order by Spotnbr ")
            For Each r As DataRow In Sql.DBDT.Rows
                LBLLastDraw.Text = r("KenSeqNbr")
                Top1BTN(BB).Text = r("Spotnbr")
                BB += 1
            Next
        End Sub
    With this code, I get the following error:
    BC30311.Value of type 'button' cannot be converted to 'VisualStyleElement.Toolbar.Button'

    I did google the error and couldn't find an answer that I could understand. (The answers didn't include exactly what I was doing.)
    My question is why does this work so well with labels and not buttons?
    I created the buttons using the button tool and the names of the buttons correlate with the dim statement.
    Thanks
    Resolution:
    Code:
     Dim Top1BTN() As Button=
    should be
    Code:
     Dim Top1BTN() As Windows.Forms.Button =
    Thanks for looking anyway!
    I don't program, I beat code into submission!!!

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109,268

    Re: Why doesn't this work for buttons like it does for labels

    Please use the Thread Tools menu to mark the thread Resolved, so we can see it without opening the thread.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,059

    Re: Why doesn't this work for buttons like it does for labels ***Resolved***

    Quote Originally Posted by vbcub View Post
    Resolution:
    Code:
     Dim Top1BTN() As Button=
    should be
    Code:
     Dim Top1BTN() As Windows.Forms.Button =
    Thanks for looking anyway!
    You can import System.Windows.Forms for your whole project, then you can just use...

    Code:
    Dim Top1BTN() As Button =

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width