Results 1 to 3 of 3

Thread: A simple one (I Hope)

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    11

    Angry

    I am trying to add the number i have got in a textbox to a number in my database. Somone gave me this code but it does not seem to work

    Dim mynewnumber As Integer
    mynewnumber = myoldnumber + Text1.Text



    Private Sub Command1_Click()
    Data1.Recordset.Edit
    Data1.recordest.score = myoldnumber
    Text1.Text = mynewnumber
    Data1.Recordset.score.myoldnumber = mynewnumber
    Data1.recordest.Update


    End Sub

    Please can u help.
    later mike

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Holden Beach NC
    Posts
    85
    Originally posted by baynham
    I am trying to add the number i have got in a textbox to a number in my database. Somone gave me this code but it does not seem to work

    Dim mynewnumber As Integer
    mynewnumber = myoldnumber + Text1.Text



    Private Sub Command1_Click()
    Data1.Recordset.Edit
    Data1.recordest.score = myoldnumber
    Text1.Text = mynewnumber
    Data1.Recordset.score.myoldnumber = mynewnumber
    Data1.recordest.Update


    End Sub

    Please can u help.
    later mike
    You are trying to force types, sometimes it works, sometimes it doesn't to be sure that it works use the formal syntax:

    Dim mynewnumber As Integer
    Dim myoldnumber as Integer

    mynewnumber = myoldnumber + Val(Trim(Text1.Text))


    The Val function should trim the text string of leading blanks, but it doesn't take much effort to trim it.

    Hunter



  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you are performing math on textbox data, you have to remember that anything in a textbox is automatically a string.
    You cannot do calculations on strings. You can use the Val function as stated above, also, you should check out the cInt, cDbl, cLng functions as well.

    These functions convert a string to an integer, double, or long
    Ie.

    mynewnumber = myoldnumber + cInt(Text1.Text) 'integer
    mynewnumber = myoldnumber + cDbl(Text1.Text) 'doubles
    mynewnumber = myoldnumber + cLng(Text1.Text) 'long


    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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