Results 1 to 5 of 5

Thread: text box values

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    13

    text box values

    I have a text box which is binded to my data base. Im trying to take that value and multiply it to a value from another text box not binded to my data base.

  2. #2
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: text box values

    Do you have a question? Or just wanting someone to write the code for you?

    Here's a few pointers, at any rate..

    Textboxes hold strings, so you will need to properly cast it first
    Have you tried Google?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    13

    Re: text box values

    Dim partamt As Integer, quantity As Integer, totalpart As Integer
    partamt = (Int(TextBoxPrice1.Text))
    quantity = (Int(TextBox1.Text))
    totalpart = partamt * quantity
    TextBox9.Text = Str(totalpart)

    this the code im using.

  4. #4
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: text box values

    Code:
    Dim partamt As Integer, quantity As Integer, totalpart As Integer
    partamt = (Int(TextBoxPrice1.Text))
    quantity = (Int(TextBox1.Text))
    totalpart = partamt * quantity
    TextBox9.Text = Str(totalpart)
    You code looks like its half vb.net and half c#, in vb.net you use
    Cint(string) to convert a string to int, in c# its int(string)
    I'm pretty sure the C stands for "cast".


    Also you can just call .tostring on your int variables
    dim mystring as string
    dim myint as Integer = 1000
    mystring = myint.tostring
    Have you tried Google?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: text box values

    It doesn't look half VB.NET and half C#. It looks half VB.NET and half VB6. In C#, a cast as type 'int' looks like this:
    csharp Code:
    1. var i = (int) o;
    That Int function is a holdover from VB6 that is intended to take a number and round it down to a whole number. The thing is, it doesn't return an Integer value anyway, so it's of no value in this case.

    There are various ways to convert a String to an Integer but, generally speaking, the most correct way is to use Integer.TryParse. That will validate the text for you as well as convert it if its valid. If you're allowed (e.g. by the requirements of an assignment) to assume that input is always valid then you can use CInt, Integer.Parse or Convert.ToInt32.

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