-
Mar 16th, 2011, 05:01 PM
#1
Thread Starter
New Member
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.
-
Mar 16th, 2011, 05:42 PM
#2
Addicted Member
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
-
Mar 16th, 2011, 07:24 PM
#3
Thread Starter
New Member
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.
-
Mar 16th, 2011, 08:00 PM
#4
Addicted Member
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
-
Mar 16th, 2011, 08:27 PM
#5
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: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|