Console.Readline help

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Console.Readline help

 
0
  #1
Sep 12th, 2008
Hey,
Can anyone help me solve this, i am trying to read the value of Console.Readline into a varible declared as Double using vb 2008. As shown below:
  1. Private Sub ReadQuantity()
  2. ' Read ask customer to input many liters
  3. Private quantity As Double
  4. Console.Write("How many liters (only whole liters please ") "? ")
  5. Console.ReadLine()
  6.  
  7. quantity = Double.Parse(Console.ReadLine())
  8. quantity = Convert.ToDouble(Console.ReadLine())
I tried both coversion function above but got FormatException errors. Is there a way around this or can i use a different approach.
Last edited by cscgal; Sep 13th, 2008 at 12:39 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: Dnx is an unknown quantity at this point 
Solved Threads: 2
Dnx Dnx is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #2
Sep 12th, 2008
Originally Posted by 3Dees View Post
Hey,
Can anyone help me solve this, i am trying to read the value of Console.Readline into a varible declared as Double using vb 2008. As shown below:

Private Sub ReadQuantity()
' Read ask customer to input many liters
Private quantity As Double
Console.Write("How many liters (only whole liters please ") "? ")
Console.ReadLine()

quantity = Double.Parse(Console.ReadLine())
quantity = Convert.ToDouble(Console.ReadLine())

I tried both coversion function above but got FormatException errors. Is there a way around this or can i use a different approach.
Hi!

Guess this is a conversion from string to double... so can you check "." or ","

Regards
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #3
Sep 12th, 2008
Thanks Dix,
But i'm not understanding what i should try,
and yes i am trying to do a conversion. Could you expand on your response please thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: Dnx is an unknown quantity at this point 
Solved Threads: 2
Dnx Dnx is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #4
Sep 12th, 2008
Originally Posted by 3Dees View Post
Thanks Dix,
But i'm not understanding what i should try,
and yes i am trying to do a conversion. Could you expand on your response please thanks.

Can you tell me what is your input?
eg :

dim input as string = console.readline()

if input has a "." and throw formatException then replace the "." by a ","
and if input has "," and throw formatException then replace "," by a "."

Let me know if it works.

Regards
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Console.Readline help

 
1
  #5
Sep 12th, 2008
  1. Dim temp, quantity As Double
  2. Console.Write("How many liters (only whole liters please ) ? ")
  3. temp = Console.ReadLine()
  4. quantity = Double.Parse(temp)
Last edited by Jx_Man; Sep 12th, 2008 at 8:10 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: Dnx is an unknown quantity at this point 
Solved Threads: 2
Dnx Dnx is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #6
Sep 12th, 2008
can you show me what is the content of "TEMP"?
just put a breakpoint after

temp = console.readline()

and paste the content of temp here.

Regards
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: Dnx is an unknown quantity at this point 
Solved Threads: 2
Dnx Dnx is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #7
Sep 12th, 2008
also Temp has to be be DECLARED AS STRING

regards
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #8
Sep 12th, 2008
My input is coming from:
Console.Write("How many liters (only whole liters please ") "? ")

I did not declare a string variable to store the input because i need it to be store as a Double for use in a calculation method. if that answer your ?
Do you know of a way i can Read an input line and some how change the returned value data type from String?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: Dnx is an unknown quantity at this point 
Solved Threads: 2
Dnx Dnx is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #9
Sep 12th, 2008
No...

what i meant is to retrieve your KEYBOARD INPUT

When you ask user to input how many liters

Just store the "CONSOLE.READLINE" in a STRING VARIABLE to check his content.

and then we can see why you have a formatexception when you did a convert.todouble.

Regards
Last edited by Dnx; Sep 12th, 2008 at 8:26 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: Console.Readline help

 
0
  #10
Sep 12th, 2008
Could the ToString method be use to slove this in anyway? I am not that experience in VB.Net
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC