-
Dec 4th, 2022, 12:24 AM
#1
Thread Starter
Lively Member
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!!!
-
Dec 4th, 2022, 12:52 AM
#2
Thread Starter
Lively Member
Re: Why doesn't this work for buttons like it does for labels ***Resolved***
 Originally Posted by vbcub
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!!!
-
Dec 4th, 2022, 03:21 AM
#3
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.
-
Dec 4th, 2022, 03:29 AM
#4
Re: Why doesn't this work for buttons like it does for labels ***Resolved***
 Originally Posted by vbcub
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 =
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|