449,284 Members | 1,246 Online Need help? Post your question and get tips & solutions from a community of 449,284 IT Pros & Developers. It's quick & easy.

# How to write this simple program? converting to numbers???

 P: n/a I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox txtradius that I enter a radius into. I then have a lable that I want the surface area to be displayed in called lblsurface here is my logic. lblsurface.text = (4 * 3.14 * txtradius * txtradius) I am getting a conversion error. I dim txtradius as double dim lblsurface as double Thanks for any help Jan 17 '07 #1
10 Replies

 P: n/a "Ron" I then have a lable that I want the surface area to be displayed in called lblsurface here is my logic. lblsurface.text = (4 * 3.14 * txtradius * txtradius) I am getting a conversion error. I dim txtradius as double dim lblsurface as double txtRadius is a textbox right? In that case you should be doing: Dim _Radius as Double = Ctype(txtRadiu.text, Double) Jan 17 '07 #2

 P: n/a Ron wrote: I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. lblsurface.text = (4 * 3.14 * txtradius * txtradius) You could boil all this down into a single statement, but here's the long-hand way, so you can see all the conversions going on ... Dim nRadius as Double = CDbl( txtRadius.Text ) Dim nArea as Double _ = 4 * Math.PI * Math.Pow( nRadius, 2 ) lblSurface.Text = nArea.ToString( "0.000" ) HTH, Phill W. Jan 17 '07 #3

 P: n/a In the second line you put CDbl(lblsurface.Text, double) it should be CDbl(lblsurface.Text) or CType(lblsurface.Text, double) "Ron" Ron wrote: I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. lblsurface.text = (4 * 3.14 * txtradius * txtradius) You could boil all this down into a single statement, but here's thelong-hand way, so you can see all the conversions going on ...Dim nRadius as Double = CDbl( txtRadius.Text )Dim nArea as Double _ = 4 * Math.PI * Math.Pow( nRadius, 2 )lblSurface.Text = nArea.ToString( "0.000" )HTH, Phill W. Jan 17 '07 #5

 P: n/a AMDRIT wrote: First, I would use doubles, I would use decimals. .. . . const decPi as decimal = 3.14d Why use Decimals when all the Math methods return Doubles? Why avoid using the Math library? The last time I looked, PI <3.14! Regards, Phill W. Jan 18 '07 #7

 P: n/a Because Dim dNumber1 As Decimal = Math.PI Dim dNumber2 As Decimal = Math.PI ^ 2 Dim dNumber3 As Decimal = dNumber2 - dNumber1 + 5& lblsurface.Text = dNumber3 is not the same as Dim dNumber1 As Double = Math.PI Dim dNumber2 As Double = Math.PI ^ 2 Dim dNumber3 As Double = dNumber2 - dNumber1 lblsurface.Text = dNumber3 and if you plan on reusing any of the numbers where they mean anything, then I recommend decimals. "Phill W." First, I would use doubles, I would use decimals. . . . >const decPi as decimal = 3.14d Why use Decimals when all the Math methods return Doubles? Why avoid using the Math library? The last time I looked, PI <3.14! Regards, Phill W. Jan 18 '07 #8

 P: n/a My apologies, that second dNumber3 should have read Dim dNumber3 As Double = dNumber2 - dNumber1 + 5& "AMDRIT" Because Dim dNumber1 As Decimal = Math.PI Dim dNumber2 As Decimal = Math.PI ^ 2 Dim dNumber3 As Decimal = dNumber2 - dNumber1 + 5& lblsurface.Text = dNumber3 is not the same as Dim dNumber1 As Double = Math.PI Dim dNumber2 As Double = Math.PI ^ 2 Dim dNumber3 As Double = dNumber2 - dNumber1 lblsurface.Text = dNumber3 and if you plan on reusing any of the numbers where they mean anything, then I recommend decimals. "Phill W." AMDRIT wrote: >>First, I would use doubles, I would use decimals. . . . >>const decPi as decimal = 3.14d Why use Decimals when all the Math methods return Doubles?Why avoid using the Math library? The last time I looked, PI <3.14!Regards, Phill W. Jan 18 '07 #9

 P: n/a AMDRIT wrote: Because Dim dNumber1 As Decimal = Math.PI Dim dNumber2 As Decimal = Math.PI ^ 2 Dim dNumber3 As Decimal = dNumber2 - dNumber1 + 5& lblsurface.Text = dNumber3 is not the same as Dim dNumber1 As Double = Math.PI Dim dNumber2 As Double = Math.PI ^ 2 Dim dNumber3 As Double = dNumber2 - dNumber1 lblsurface.Text = dNumber3 and if you plan on reusing any of the numbers where they mean anything, then I recommend decimals. Strange, then, that Our Friends in Redmond seem satified with mere Doubles for the Math methods... :-) Regards, Phill W. Jan 18 '07 #10
{"ft_lang_label":"__label__en","ft_lang_prob":0.8244725,"math_prob":0.8017369,"size":3452,"snap":"2020-10-2020-16","text_gpt3_token_len":941,"char_repetition_ratio":0.19431554,"word_repetition_ratio":0.13644524,"special_character_ratio":0.28592122,"punctuation_ratio":0.17963225,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9978061,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-08T03:19:04Z\",\"WARC-Record-ID\":\"<urn:uuid:5f3f87e8-45c2-46dc-8830-4c6ba48e08b6>\",\"Content-Length\":\"52885\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b9e84b71-e1a4-499d-b5ab-c4ed6746a83c>\",\"WARC-Concurrent-To\":\"<urn:uuid:7cd811ed-66a2-4965-9805-772edd2917ce>\",\"WARC-IP-Address\":\"104.197.32.212\",\"WARC-Target-URI\":\"https://bytes.com/topic/visual-basic-net/answers/589436-how-write-simple-program-converting-numbers\",\"WARC-Payload-Digest\":\"sha1:TIPB2L7QZBUV6EJWHMU743BBVTFU5TTL\",\"WARC-Block-Digest\":\"sha1:7R5M54REY6NV2AYT6UTTZHZZIEGGOMQG\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585371807538.83_warc_CC-MAIN-20200408010207-20200408040707-00048.warc.gz\"}"}