473,466 Members | 1,334 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1531
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.