7 Replies - 17033 Views - Last Post: 19 May 2010 - 10:57 AM Rate Topic: -----

#1 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

How to change button text

Posted 19 May 2010 - 06:13 AM

Hello,

I try to make a program function. Its hard to explain it, but I'll try.

Here is code :

If Form1.Button18.Text = "B18" Then
            Form1.Button18.Show()
            Form1.Button18.Text = "TextToSpeech"
        ElseIf Form1.Button19.Text = "B19" Then
            Form1.Button19.Show()
            Form1.Button19.Text = "TextToSpeech"
        ElseIf Form1.Button20.Text = "B20" Then
            Form1.Button20.Show()
            Form1.Button20.Text = "TextToSpeech"
        ElseIf Form1.Button21.Text = "B21" Then
            Form1.Button21.Show()
            Form1.Button21.Text = "TextToSpeech"
        ElseIf Form1.Button22.Text = "B22" Then
            Form1.Button22.Show()
            Form1.Button22.Text = "TextToSpeech"
        ElseIf Form1.Button23.Text = "B23" Then
            Form1.Button23.Show()
            Form1.Button23.Text = "TextToSpeech"
        ElseIf Form1.Button24.Text = "B24" Then
            Form1.Button24.Show()
            Form1.Button24.Text = "TextToSpeech"
        ElseIf Form1.Button25.Text = "B25" Then
            Form1.Button25.Show()
            Form1.Button25.Text = "TextToSpeech"
        ElseIf Form1.Button26.Text = "B26" Then
            Form1.Button26.Show()
            Form1.Button26.Text = "TextToSpeech"
        ElseIf Form1.Button27.Text = "B27" Then
            Form1.Button27.Show()
            Form1.Button27.Text = "TextToSpeech"
        ElseIf Form1.Button28.Text = "B28" Then
            Form1.Button28.Show()
            Form1.Button28.Text = "TextToSpeech"
        ElseIf Form1.Button29.Text = "B29" Then
            Form1.Button29.Show()
            Form1.Button29.Text = "TextToSpeech"
        End If


Its works , but if some buttons already have TexToSpeech text then it make one button more with same text. I want to do that if one button already have this TextToSpeech text then dont come more buttons and this only one stay what is already. Mabye someone know a way how to do that.
I hope that you understand what i mean.

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: How to change button text

#2 camckee316  Icon User is offline

  • D.I.C Regular

Reputation: 15
  • View blog
  • Posts: 283
  • Joined: 29-August 08

Re: How to change button text

Posted 19 May 2010 - 06:48 AM

Why so many buttons with the same text?

You can the text of the button in the propery's section in design view. See attached.
Was This Post Helpful? 0
  • +
  • -

#3 mr.coder  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 41
  • Joined: 31-January 10

Re: How to change button text

Posted 19 May 2010 - 07:00 AM

Dear qtex,

As far as your problem is concerned, you may first check if any Button has the text "TextToSpeech". If No, change the text of a Button and show it.

Let me know about it!
Was This Post Helpful? 0
  • +
  • -

#4 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to change button text

Posted 19 May 2010 - 07:05 AM

View Postcamckee316, on 19 May 2010 - 05:48 AM, said:

Why so many buttons with the same text?

You can the text of the button in the propery's section in design view. See attached.


You didnt understand this problem right

View Postmr.coder, on 19 May 2010 - 06:00 AM, said:

Dear qtex,

As far as your problem is concerned, you may first check if any Button has the text "TextToSpeech". If No, change the text of a Button and show it.

Let me know about it!


Can you give me a code snippet ?
Was This Post Helpful? 0
  • +
  • -

#5 mr.coder  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 41
  • Joined: 31-January 10

Re: How to change button text

Posted 19 May 2010 - 07:29 AM

View Postqtex, on 19 May 2010 - 06:35 PM, said:

Can you give me a code snippet ?


Hear is a Code Snippet:

        For i As Integer = 18 To 29
            If Me.Controls.Item("Button" & i).Text = "TextToSpeech" Then
                'Button with Text as "TextToSpeech" Exists, Break Loop
            End If
        Next




The loop is used to check every button for its text as "TextToSpeech".

Hope it helps!
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to change button text

Posted 19 May 2010 - 07:37 AM

I have the same question as camckee316, why so many button that seem to do the same thing. If this is homework it does not matter. For a real application I am having a hard time understanding why you would need this many. Could you elaborate?
Was This Post Helpful? 0
  • +
  • -

#7 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to change button text

Posted 19 May 2010 - 08:02 AM

View Postmr.coder, on 19 May 2010 - 06:29 AM, said:

View Postqtex, on 19 May 2010 - 06:35 PM, said:

Can you give me a code snippet ?


Hear is a Code Snippet:

        For i As Integer = 18 To 29
            If Me.Controls.Item("Button" & i).Text = "TextToSpeech" Then
                'Button with Text as "TextToSpeech" Exists, Break Loop
            End If
        Next




The loop is used to check every button for its text as "TextToSpeech".

Hope it helps!


Thanks , but i got error.
The error is: Object reference not set to an instance of an object.

Error is shown when i click Button31

These are my codes :

Private Sub Button31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button31.Click
        Form2.Show() < it shows error
    End Sub


 Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Form1.Button32.Hide()
        For i As Integer = 18 To 29
            If Form1.Controls.Item("Button" & i).Text = "To Do List" Then
                'Button with Text as "ToDoList" Exists, Break Loop
            ElseIf Form1.Button18.Text = "B18" Then
        Form1.Button18.Show()
        Form1.Button18.Text = "To Do List"
            ElseIf Form1.Button19.Text = "B19" Then
        Form1.Button19.Show()
        Form1.Button19.Text = "To Do List"
            ElseIf Form1.Button20.Text = "B20" Then
        Form1.Button20.Show()
        Form1.Button20.Text = "To Do List"
            ElseIf Form1.Button21.Text = "B21" Then
        Form1.Button21.Show()
        Form1.Button21.Text = "To Do List"
            ElseIf Form1.Button22.Text = "B22" Then
        Form1.Button22.Show()
        Form1.Button22.Text = "To Do List"
            ElseIf Form1.Button23.Text = "B23" Then
        Form1.Button23.Show()
        Form1.Button23.Text = "To Do List"
            ElseIf Form1.Button24.Text = "B24" Then
        Form1.Button24.Show()
        Form1.Button24.Text = "To Do List"
            ElseIf Form1.Button25.Text = "B25" Then
        Form1.Button25.Show()
        Form1.Button25.Text = "To Do List"
            ElseIf Form1.Button26.Text = "B26" Then
        Form1.Button26.Show()
        Form1.Button26.Text = "To Do List"
            ElseIf Form1.Button27.Text = "B27" Then
        Form1.Button27.Show()
        Form1.Button27.Text = "To Do List"
            ElseIf Form1.Button28.Text = "B28" Then
        Form1.Button28.Show()
        Form1.Button28.Text = "To Do List"
            ElseIf Form1.Button29.Text = "B29" Then
        Form1.Button29.Show()
        Form1.Button29.Text = "To Do List"
            End If
        Next
    End Sub

This post has been edited by qtex: 19 May 2010 - 08:03 AM

Was This Post Helpful? 0
  • +
  • -

#8 qtex  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to change button text

Posted 19 May 2010 - 10:57 AM

View Posthawkvalley1, on 19 May 2010 - 06:37 AM, said:

I have the same question as camckee316, why so many button that seem to do the same thing. If this is homework it does not matter. For a real application I am having a hard time understanding why you would need this many. Could you elaborate?


Posted Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1