473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

beginner question

I'm playing with MS Visual Studio C#

I have a Combo box that drops down to let me pick a quantity value. called
milkQnty

However, my understanding is that C# treats this as an object.
I want to use this value to multiply with the price to get the total.

double milkPrice, milkTotal;
milkPrice = 1.99f;
milkTotal = milkPrice * milkQnty;

When I compile, I get a message that says I cannot apply operands of type
System.Windos.Forms.ComboBox; and 'double'

How can I turn the value in object milkQnty into an integer I can do
arithmetic with ?

Trying to learn C# and this is all new to me.

Thanks in advance.

Nov 15 '05 #1
2 1528
milkQnty is the name of the ComboBox control which has the value in it.
To get the currently selected value, you will have to use the Text property
to get the text of the selected item. However, this will be a string value,
and you need a number. To convert it to a number, pass that value to the
static Parse method on the Int32 class (which is the same as int). Once you
have this, you can use it, like so:

// Set the milkPrice.
milkPrice = 1.99f;

// Get the quantity.
int pintMilkQnty = Int32.Parse(milkQnty.Text);

// Get the total.
milkTotal = milkPrice * pintMilkQnty;

Now, if you were using data binding, you could get a value directly, but
I am pretty sure you are not using that. If you are, then I would recommend
using the SelectedValue member of the milkQnty combobox in order to get the
value associated with the selection.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"News charter" <ra******@charter.net> wrote in message
news:vq************@corp.supernews.com...
I'm playing with MS Visual Studio C#

I have a Combo box that drops down to let me pick a quantity value. called
milkQnty

However, my understanding is that C# treats this as an object.
I want to use this value to multiply with the price to get the total.

double milkPrice, milkTotal;
milkPrice = 1.99f;
milkTotal = milkPrice * milkQnty;

When I compile, I get a message that says I cannot apply operands of type
System.Windos.Forms.ComboBox; and 'double'

How can I turn the value in object milkQnty into an integer I can do
arithmetic with ?

Trying to learn C# and this is all new to me.

Thanks in advance.

Nov 15 '05 #2
This worked great.

But I had problem parsing a field with decimal place with Int32.Parse method

The sale tax field is input 7.5
when I pass this field to Int32.Parse(salesTax.Text)

I get exception.

Is there another method I can use to parse field with decimal place ?
Thanks

Where can I find references to all these methods and what they are used for
?
I guess they are part of the .NET class library but there must be a quick
references that list all of the
widely used ones. Is there a book ? or do we learn to use them as we gain
experience ?

thanks



"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uD**************@tk2msftngp13.phx.gbl...
milkQnty is the name of the ComboBox control which has the value in it. To get the currently selected value, you will have to use the Text property to get the text of the selected item. However, this will be a string value, and you need a number. To convert it to a number, pass that value to the
static Parse method on the Int32 class (which is the same as int). Once you have this, you can use it, like so:

// Set the milkPrice.
milkPrice = 1.99f;

// Get the quantity.
int pintMilkQnty = Int32.Parse(milkQnty.Text);

// Get the total.
milkTotal = milkPrice * pintMilkQnty;

Now, if you were using data binding, you could get a value directly, but I am pretty sure you are not using that. If you are, then I would recommend using the SelectedValue member of the milkQnty combobox in order to get the value associated with the selection.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"News charter" <ra******@charter.net> wrote in message
news:vq************@corp.supernews.com...
I'm playing with MS Visual Studio C#

I have a Combo box that drops down to let me pick a quantity value. called milkQnty

However, my understanding is that C# treats this as an object.
I want to use this value to multiply with the price to get the total.

double milkPrice, milkTotal;
milkPrice = 1.99f;
milkTotal = milkPrice * milkQnty;

When I compile, I get a message that says I cannot apply operands of type System.Windos.Forms.ComboBox; and 'double'

How can I turn the value in object milkQnty into an integer I can do
arithmetic with ?

Trying to learn C# and this is all new to me.

Thanks in advance.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
4
by: a | last post by:
Dear all vb.net developer I want to know the time I need to master vb.net? I'm beginner
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
2
by: roanhn | last post by:
Hello. I've to to write a master's thesis. Currently I deal with php, mysql, ajax. Fate decreed that I've to choose one of this subjects: 1.gdi+ library in .net technology 2.ado.net technology...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.