|
-
Jul 29th, 2004, 03:52 PM
#1
Thread Starter
Junior Member
TextBox
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!!
viv
-
Jul 29th, 2004, 04:03 PM
#2
I smell school project
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
-
Jul 29th, 2004, 04:10 PM
#3
Frenzied Member
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.
-
Jul 29th, 2004, 04:36 PM
#4
Thread Starter
Junior Member
But how to focus on the specific textbox and then i click on the remove button to remove the value??
viv
-
Jul 29th, 2004, 05:57 PM
#5
PowerPoster
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
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.
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
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 29th, 2004, 09:21 PM
#6
Fanatic Member
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
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
|