hi,
1. how to add up the values in the textbox ??
example:
textbox1
textbox2
textbox3
textbox4
Total: ???
2. how to remove the data in the selected textbox by clicking the remove button??
Pls help!!:confused:
viv
Printable View
hi,
1. how to add up the values in the textbox ??
example:
textbox1
textbox2
textbox3
textbox4
Total: ???
2. how to remove the data in the selected textbox by clicking the remove button??
Pls help!!:confused:
viv
I smell school project :D
when you say add up values, i assume you mean that all the textboxes will have numbers in them (which that in itself you may want to error check in your code)
but basically if you had a variable of type Integer (if these are whole numbers) or maybe single if it could have decimal places.
Dim intTotal as Integer
intTotal = cint(textbox1.Text) + cint(textbox2.text) etc....
clearing the textbox is simple, as in .net you can do
textbox1.clear
I guess you have to convert the string to a number, something like:
VB Code:
MessageBox.Show(CType(TextBox1.Text, Integer) + CType(TextBox2.Text, Integer))
Not really sure if that's the most effecient way or not. As for the second question, umm, not sure either. You can check which control has the focus by something like:
VB Code:
For Each c As Control In Controls If c.ContainsFocus Then MessageBox.Show(c.ToString) End If
But if that code executes when you click a button, it's the button that currently has the focus. Not sure if you might need a lastFocused variable that you could set in the GotFocus event.
But how to focus on the specific textbox and then i click on the remove button to remove the value??
viv
Not as easy as the other part of your question. You will first have to remember which textBox had the focus immediately before the Remove button is clicked. I think the best way is to examine the stack, but someone else will have to comment on that.Quote:
Originally posted by vivsm
But how to focus on the specific textbox and then i click on the remove button to remove the value??
viv
I would have to use a long way round like:
Dim strTemp As String (Form scope)
Then in each of the textbox getfocus events put
strTemp=TextBox1 (the name of the textbox)
then in the remove button click event put
VB Code:
Dim ctr As Control For Each ctr In Controls If ctr.Name = strTemp Then ctr.Text = "" End If Next
VB Code:
Dim t As TextBox Private Sub t_enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter, TextBox5.Enter t = CType(sender, TextBox) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click t.Clear() End Sub