Join 117,523 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 2,052 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
Ok, so I have an assignment in my programming class and it is our first one that we need to do where we supply the entire code. I was given a couple formulas, and told to create a conversion caluator. The input are four numericUpDown controls, for miles, yards, feet, and inches, and when you hit compute, it will convert them to kilometers, meters and centimeters. The example given is (entered by the user) 2 miles 5 yards 2 feet and 7 inches, which should translate to 3 kilometers, 224 meters, 5.384810769 centimeters. With the code I've written, I can get this to work with this example, however, it doesnt seem that (nearly) any other values and I'm stumped.
We are given these formulas
Total Inches = 63360 x miles + 36 x yards + 12 x feet + inches and Total Meters = Total Inches / 39.37
Any clue where I went wrong?
CODE
Option Strict ON Const INCHESPERMILE As Integer = 63360 Const INCHESPERYARD As Integer = 36 Const INCHESPERFOOT As Integer = 12 Const CONVERTER As Double = 39.37
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click Dim dblMiles As Double Dim dblYards As Double Dim dblFeet As Double Dim dblInches As Double Dim dblKilometers As Double Dim dblMeters As Double Dim dblTotalInches As Double Dim dblRemainingMeters As Double Dim dblTotalMeters As Double
' Done to convert all nud values To Double dblMiles = Convert.ToDouble(nudMiles.Value) dblYards = Convert.ToDouble(nudYards.Value) dblFeet = Convert.ToDouble(nudFeet.Value) dblInches = Convert.ToDouble(nudInches.Value)
Ok, so I have an assignment in my programming class and it is our first one that we need to do where we supply the entire code. I was given a couple formulas, and told to create a conversion caluator. The input are four numericUpDown controls, for miles, yards, feet, and inches, and when you hit compute, it will convert them to kilometers, meters and centimeters. The example given is (entered by the user) 2 miles 5 yards 2 feet and 7 inches, which should translate to 3 kilometers, 224 meters, 5.384810769 centimeters. With the code I've written, I can get this to work with this example, however, it doesnt seem that (nearly) any other values and I'm stumped.
We are given these formulas
Total Inches = 63360 x miles + 36 x yards + 12 x feet + inches and Total Meters = Total Inches / 39.37
Any clue where I went wrong?
CODE
Option Strict ON Const INCHESPERMILE As Integer = 63360 Const INCHESPERYARD As Integer = 36 Const INCHESPERFOOT As Integer = 12 Const CONVERTER As Double = 39.37
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click Dim dblMiles As Double Dim dblYards As Double Dim dblFeet As Double Dim dblInches As Double Dim dblKilometers As Double Dim dblMeters As Double Dim dblTotalInches As Double Dim dblRemainingMeters As Double Dim dblTotalMeters As Double
' Done to convert all nud values To Double dblMiles = Convert.ToDouble(nudMiles.Value) dblYards = Convert.ToDouble(nudYards.Value) dblFeet = Convert.ToDouble(nudFeet.Value) dblInches = Convert.ToDouble(nudInches.Value)
Forgive my noobness, but it looks like you (in second from the last line) are converting "dblRemainingMeters" and converting and subtracting "dblRemainingMeters" to Int32...I thought you had to do conversions on the same variable on separate lines...Please someone correct me
Forgive my noobness, but it looks like you (in second from the last line) are converting "dblRemainingMeters" and converting and subtracting "dblRemainingMeters" to Int32...I thought you had to do conversions on the same variable on separate lines...Please someone correct me
Correct on the Int32. All variables involved should be double, or be cast double when preforming mathmatical operations. Otherwise, the behavior is to cast the result down to what the smallest can handle.
Well, I tried that, and it didnt change anything as far as the formula not creating the proper conversion. Also, I reread the instructions and it says that the first three constants have to be integers, and the last one needs to be as double. So I cant really change that. I think the problem may not be with my variables, but with the formula itself. Any ideas?
It may help to post the entire assignment for this problem so we can get a better perspective of what exactly the problem is. On another note, if the variables absolutely have to be determined this way, you might second guess the quality of the book. I took 1 VB class at ITT and I remember where one assignment that simply could not be completed the way the book way wanting. You might ask the instructor if this problem has ever been completed before also. Just a thought.
Do you have to have the Option Strict On for this assignment?
If you do, delete the following from all of your code: Convert.ToString
This post has been edited by Recoil: 4 Jul, 2008 - 06:05 AM
Well, actually, Ive been talking to a friend of mine, who is a programmer (who is in school with me also, just not the programming class) and I had him look at it, and he said the only way to make meters and centimeters read 0 instead of a negative number, is an if then statement. Either way, I'll turn it in and see what happens...I appreciate all the help tho guys