No idea what i should use

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 918 Views - Last Post: 12 January 2010 - 11:51 PM Rate Topic: -----

#1 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

No idea what i should use

Posted 08 January 2010 - 11:02 PM

Hi, sorry if my english isn't proper, i am originaly french. I do my best to avoid bad spelling.

Well, lets go to my problem.

I really have time to loose but i want to make it.

The programme is for calculating an amount of fruit.

I have a label saying the name of the fruit, a textbox to enter a value of 0-99
and another textbox with ReadOnly wich will show the price.

A little picture here:
http://img94.imagesh...anstitre1rs.jpg

Ok, as you can see, the Fruit1 Etc... Is only the fruit name.
The Text box wich indicate 1-99 means the number of fruit.
The Textbox with Cash on it, means the total price.
The Calaculate button, when i will puch it, all the total price from all the fruit will be added together to form a total price wich will be indicated in the total price textbox under the Calculate button.

When i will enter the number of fruit, if i enter 99, it give me a price.
When i will enter 60, i want that the 60 are multiplyed by (let say) 0,10$
I just like to know how i can do this... Its really bothering e and i don;t want to calculate all the things and make 99 line for 1 fruit cause it will be long.

I don't know if you understand what am saying.

The code i was using was:


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

If TextBox1.Text = "99" Then
	   TextBox2.text = "10.00$"

Elseif TextBox1.Text = "98" Then
		TextBox2.Text = "9,90$"

EndIf
	End Sub




Until the the number of the fruit in the code reach 0.
So its very very very long.
Its why i'd like to know if theres a code that can do it simply.

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: No idea what i should use

#2 cabbae  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 11-December 09

Re: No idea what i should use

Posted 08 January 2010 - 11:29 PM

How much does each fruit cost? Instead of doing it manually you just multiply the amount of fruit on hand by the cost per fruit and that's it.

This post has been edited by cabbae: 08 January 2010 - 11:30 PM

Was This Post Helpful? 0
  • +
  • -

#3 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 09 January 2010 - 03:32 AM

No no no, it could be much simpler than that!
Just multiply the amount of fruit by the price, for example
TextBox2.Text = Convert.ToString(Val(TextBox1.Text) * 0.10)

'Val gets the value of the textbox and turns it into an integer
'This is then multiplied by the price (0.10 = 10cents, 1.00 = 1 dollar etc)
'All that is then converted to a string so it can be set as the value of TextBox2


Just do that for every textbox and its cash textbox. Also, this is just from a programmer's point of view, give your textboxes descriptive names, for example AppleAmount could be the textbox for the fruit Apple and its cash textbox could be named ApplePrice so the code for that would look like
ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.10)


If you need more help, just post. I don't know if this is correct french, mais j'espère j'ai aidé!

This post has been edited by remorseless: 09 January 2010 - 03:33 AM

Was This Post Helpful? 1
  • +
  • -

#4 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 09 January 2010 - 06:15 AM

Thanks alot am gonna go test it out!

EDIT: Ok, but if i want the fruit to have multiple price?

Exemple:

If you buy 1-26 fruit, it will be 0,10$ Each
If you buy 27-46 fruitm it will be 0,16 Each
Etc...

And yes it really helped me:P I will be able to use it for another things :)

This post has been edited by jamsters: 09 January 2010 - 06:22 AM

Was This Post Helpful? 0
  • +
  • -

#5 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 09 January 2010 - 06:37 AM

I think i found it!

If AppleAmount.Text < 99 And AppleAmount.Text > 86 Then
   ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.10)

ElseIf AppleAmount.Text < 85 And AppleAmount.Text > 75 Then
   ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.05)


EndIf



Etc...

Is it good?

EDIT: Well... the price of 99 and 86 will not be shown. Same for 85 and 75.

This post has been edited by jamsters: 09 January 2010 - 07:01 AM

Was This Post Helpful? 0
  • +
  • -

#6 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 09 January 2010 - 07:11 PM

View Postjamsters, on 9 Jan, 2010 - 10:37 PM, said:

I think i found it!

If AppleAmount.Text < 99 And AppleAmount.Text > 86 Then
   ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.10)

ElseIf AppleAmount.Text < 85 And AppleAmount.Text > 75 Then
   ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.05)


EndIf



Etc...

Is it good?

EDIT: Well... the price of 99 and 86 will not be shown. Same for 85 and 75.


Yep, that should be about right. But, Make sure you use Val, because if you use AppleAmount.Text < 99 You're comparing a string to an integer. Instead use
If Val(AppleAmount.Text) >= 1 And Val(AppleAmount.Text) <= 26 Then
ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.10) '10 cents each fruit if you buy 1-26
Else If Val(AppleAmount.Text) >= 27 And Val(AppleAmount.Text) <= 46 Then
ApplePrice.Text = Convert.ToString(Val(AppleAmount.Text) * 0.16) '16 cents each fruit if you buy 27-46
'Repeat for however much you want
End If



Hope I helped! :D
Was This Post Helpful? 0
  • +
  • -

#7 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 10 January 2010 - 10:05 AM

Yes thanks. But when i click on my button to calculate, it doesn;t show as decimal... How can i do it to show in decimal?
Was This Post Helpful? 0
  • +
  • -

#8 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 10 January 2010 - 03:58 PM

If ur on, could you add my msn?

Volonter@live.ca

I really need help fast :(
Was This Post Helpful? 0
  • +
  • -

#9 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 11 January 2010 - 05:23 AM

View Postjamsters, on 11 Jan, 2010 - 02:05 AM, said:

Yes thanks. But when i click on my button to calculate, it doesn;t show as decimal... How can i do it to show in decimal?


Oh sorry, that was my fault. To show it as decimal, in the price textbox, instead of Val, use Convert.ToDouble.
So your code will look like:
If Val(AppleAmount.Text) >= 1 And Val(AppleAmount.Text) <= 26 Then
ApplePrice.Text = Convert.ToString(Convert.ToDouble(AppleAmount.Text) * 0.10) '10 cents each fruit if you buy 1-26
Else If Val(AppleAmount.Text) >= 27 And Val(AppleAmount.Text) <= 46 Then
ApplePrice.Text = Convert.ToString(Convert.ToDouble(AppleAmount.Text) * 0.16)) '16 cents each fruit if you buy 27-46
'Repeat for however much you want
End If



I don't really use MSN :P You can still message me by hotmail if you like.

This post has been edited by remorseless: 11 January 2010 - 05:27 AM

Was This Post Helpful? 1
  • +
  • -

#10 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 11 January 2010 - 06:00 AM

And is i want to calculate all the price? I have a button called calculate... I push it but i get only 1 number... If ihave 2 number with 0,50, the number will show 0...

I was using this:

Totalprice.text = Val(ApplePrice.text) + Val(OrangePrice.text)
etc...

Gotta go school cya

This post has been edited by jamsters: 11 January 2010 - 06:33 AM

Was This Post Helpful? 0
  • +
  • -

#11 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 11 January 2010 - 07:36 PM

View Postjamsters, on 11 Jan, 2010 - 10:00 PM, said:

And is i want to calculate all the price? I have a button called calculate... I push it but i get only 1 number... If ihave 2 number with 0,50, the number will show 0...

I was using this:

Totalprice.text = Val(ApplePrice.text) + Val(OrangePrice.text)
etc...

Gotta go school cya


Yea this is because Val returns an integer, a whole number with no decimal. Use Convert.ToDouble() instead. Also, A good idea is to store that number in a double and when you set it as text, use .ToString(). For example:

Dim price As Double = Convert.ToDouble(ApplePrice.Text) + Convert.ToDouble(OrangePrice.Text)
Totalprice.text = price.ToString()



Hope I helped! :D
Was This Post Helpful? 1
  • +
  • -

#12 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 11 January 2010 - 07:56 PM

Thanks, but if theres a price that have a 0.00 (If anyone won;t take of a fruit, he put 0, and the price qwill be 0.00)

Then i get an error like this:

The format of the input string is incorrect.

How do i fix that?

If every case is filled, no problem... As soon as i have a 0.00, its show me this error... please help
Was This Post Helpful? 0
  • +
  • -

#13 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 11 January 2010 - 10:42 PM

Hang on, so if you have 0.00 in the amount box you get "The format of the input string is incorrect."?
Was This Post Helpful? 1
  • +
  • -

#14 jamsters  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 08-January 10

Re: No idea what i should use

Posted 12 January 2010 - 12:13 AM

yes...
Was This Post Helpful? 0
  • +
  • -

#15 remorseless  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 129
  • Joined: 08-August 09

Re: No idea what i should use

Posted 12 January 2010 - 03:17 PM

I see your problem. What is happening is we were not checking if the user did not want any.

If Val(AppleAmount.Text) = 0 Then ApplePrice.Text = "0" 'If the user did not want any.
Else If Val(AppleAmount.Text) >= 1 And Val(AppleAmount.Text) <= 26 Then
ApplePrice.Text = Convert.ToString(Convert.ToDouble(AppleAmount.Text) * 0.10) '10 cents each fruit if you buy 1-26
Else If Val(AppleAmount.Text) >= 27 And Val(AppleAmount.Text) <= 46 Then
ApplePrice.Text = Convert.ToString(Convert.ToDouble(AppleAmount.Text) * 0.16)) '16 cents each fruit if you buy 27-46
'Repeat for however much you want
End If



Hope I helped! :D

This post has been edited by remorseless: 12 January 2010 - 03:24 PM

Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2