Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Help with VB Express Edition

Hi. I am very new to Visual Basic. I am trying to do the following:

I have created a form on which I have a button for each letter of the alphabet. So one button for A, one button for B etc.

I have a textbox at the top of the form. What I want to be able to do is, click on button A and the letter A appears in the textbox.

Any idea of how this can be done?

Thanks
[400 byte] By [MonaVohra] at [2007-11-11 10:20:26]
# 1 Re: Help with VB Express Edition
are your command buttons in an control array? if they are, just create a loop to grab the index and use it in a Select to tell it what letter you want to add to the text box.

if the buttons are not part of an array, you'll need to do something like this for each one of them:

Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & "A"
End Sub

That will add "A" to whatever is already in the textbox everytime the button with the name "Command1" is clicked.
doofusboy at 2007-11-11 20:48:09 >
# 2 Re: Help with VB Express Edition
they are not in a control array...iv tried the 2nd part of the code u gave. its worked thanks :)

would u be able to recommend any books on visual basic express ed? im a very new learner and need to get my application completed asap so need to learn vb asap too.

thanks for ur help :)
MonaVohra at 2007-11-11 20:49:16 >
# 3 Re: Help with VB Express Edition
doofusboy: Your answer is correct for VB6 and prior versions. Unfortunately, Mona posted his/her message to the wrong forum; as the subject states, s/he is using VB Express Edition, which is based on .NET and does not support control arrays.

Mona, assuming that your textbox is named txtBox and your buttons are named btnA, btnB, etc. and their text properties are set to "A", "B", "C", etc. you can do this:

Private Sub Button_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnA.Click, btnB.Click, btnC.Click ' , etc.

' Convert sender parameter (the control that
' triggered the event) to Button
Dim btn As Button = DirectCast(sender, Button)
' Add button text to end of textbox
txtBox.AppendText(btn.Text)

End Sub
Phil Weber at 2007-11-11 20:50:10 >
# 4 Re: Help with VB Express Edition
Phil,

Thanks for ur comment. I have tried both ways and they both work :)
MonaVohra at 2007-11-11 20:51:10 >
# 5 Re: Help with VB Express Edition
have done very little so far in .Net

could you elaborate on:
based on .NET and does not support control arrays.

how are control arrays addressed in .Net?
doofusboy at 2007-11-11 20:52:15 >
# 6 Re: Help with VB Express Edition
http://www.google.com/search?q=vb.net+control+arrays
Phil Weber at 2007-11-11 20:53:20 >