Results 1 to 6 of 6

Thread: TextBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Wink 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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    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

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I guess you have to convert the string to a number, something like:
    VB Code:
    1. 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:
    1. For Each c As Control In Controls
    2.             If c.ContainsFocus Then
    3.                 MessageBox.Show(c.ToString)
    4.             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.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    But how to focus on the specific textbox and then i click on the remove button to remove the value??

    viv

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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:
    1. Dim ctr As Control
    2.         For Each ctr In Controls
    3.             If ctr.Name = strTemp Then
    4.                 ctr.Text = ""
    5.             End If
    6.         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.

  6. #6
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    VB Code:
    1. Dim t As TextBox
    2.    Private Sub t_enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter, TextBox5.Enter
    3.       t = CType(sender, TextBox)
    4.    End Sub
    5.  
    6.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.       t.Clear()
    8.    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
  •  



Click Here to Expand Forum to Full Width