Solved

Changing the text on a button after its been selected.

Posted on 2008-10-11
4
168 Views
Last Modified: 2012-05-05
I'm creating a Jeopardy style game. I've created an array of buttons so when the form is loaded, each buttons text is set to its dollar value. How do I change the text on a button after it's been selected?
Private Sub frmBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim oBoard As New ClsBoard
        Dim dtCategories As New DataTable
 
        'hook up array
        arrCol1(0) = btn1200
        arrCol1(1) = btn1400
        arrCol1(2) = btn1600
        arrCol1(3) = btn1800
        arrCol1(4) = btn11000
 
        arrCol2(0) = btn2200
        arrCol2(1) = btn2400
        arrCol2(2) = btn2600
        arrCol2(3) = btn2800
        arrCol2(4) = btn21000
 
        arrCol3(0) = btn3200
        arrCol3(1) = btn3400
        arrCol3(2) = btn3600
        arrCol3(3) = btn3800
        arrCol3(4) = btn31000
 
        arrCol4(0) = btn4200
        arrCol4(1) = btn4400
        arrCol4(2) = btn4600
        arrCol4(3) = btn4800
        arrCol4(4) = btn41000
 
        arrCol5(0) = btn5200
        arrCol5(1) = btn5400
        arrCol5(2) = btn5600
        arrCol5(3) = btn5800
        arrCol5(4) = btn51000
 
        arrCol6(0) = btn6200
        arrCol6(1) = btn6400
        arrCol6(2) = btn6600
        arrCol6(3) = btn6800
        arrCol6(4) = btn61000
 
        dtCategories = oBoard.GetCategories
        txtCat1.Text = dtCategories.Rows(0).Item(1)
        txtCat2.Text = dtCategories.Rows(1).Item(1)
        txtCat3.Text = dtCategories.Rows(2).Item(1)
        txtCat4.Text = dtCategories.Rows(3).Item(1)
        txtCat5.Text = dtCategories.Rows(4).Item(1)
        txtCat6.Text = dtCategories.Rows(5).Item(1)
        For x = 0 To 4
            arrCol1(x).Text = ("$" & (x + 1) * 200)
            arrCol2(x).Text = ("$" & (x + 1) * 200)
            arrCol3(x).Text = ("$" & (x + 1) * 200)
            arrCol4(x).Text = ("$" & (x + 1) * 200)
            arrCol5(x).Text = ("$" & (x + 1) * 200)
            arrCol6(x).Text = ("$" & (x + 1) * 200)
 
        Next
        m_Categories = dtCategories
        Me.Show()
    End Sub
 
    Private Sub btnCol1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1200.Click, btn1400.Click, btn1600.Click, btn1800.Click, btn11000.Click
 
        'btnCol1_click.text = "Used"
 
        m_sender = Strings.Right(sender.tag, 1)
        icolumn = Strings.Left(sender.tag, 1) - 1
        irow = Strings.Right(sender.tag, 1) - 1
        'hook up array
        Dim frmQ As New frmQuestion
        vwQuestion.RowFilter = "CategoryID = '" & CStr(m_Categories.Rows(icolumn).Item("CategoryID")).Replace("'", "\'") & "'"
        frmQ.Question = vwQuestion.ToTable.Rows(irow).Item(2)
        frmQ.Answer1 = vwQuestion.ToTable.Rows(irow).Item(3)
        frmQ.Answer2 = vwQuestion.ToTable.Rows(irow).Item(4)
        frmQ.Answer3 = vwQuestion.ToTable.Rows(irow).Item(5)
        frmQ.Answer4 = vwQuestion.ToTable.Rows(irow).Item(6)
        frmQ.CorrectAnswer = vwQuestion.ToTable.Rows(irow).Item(7)
        frmQ.ShowDialog()
 
    End Sub

Open in new window

0
Comment
Question by:98fatboyrider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Expert Comment

by:leegclystvale
ID: 22695547
Try
yourbuttonname.caption = "new text value".
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 22695767
Try this way:
        Dim btn As Button = DirectCast(sender, Button)
        btn.Text = "New text"

Open in new window

0
 

Author Closing Comment

by:98fatboyrider
ID: 31505340
Thanks again!
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 22696722
Glad I could help!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to make search between pages 17 59
Excel Web Add-in Where is Visual Basic used 9 79
How do I "share" on social sites? 2 38
vb.net code 9 28
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question