Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 4th, 2006, 7:48 PM   #1
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
Question Visual Basic Converter Problem

Hi, I'm trying to make a program to convert us to metric, where miles go to kilometers, yards to meters, and feet to centimeters. I just can't understand the y to m, and f to cm, since i need to do it in a specific way for my class. Here's the code w/ explanations at end.


Dim Miles, Yards, Feet, Inches, totalInches, totalMeters As Double
        Dim km, m, cm As Double
        'assign values from txt boxes
        Miles = txtMiles.Text
        Yards = txtYards.Text
        Feet = txtFeet.Text
        Inches = txtInches.Text

        'convert to inches
        totalInches = (63360 * Miles) + (36 * Yards) + (12 * Feet) + Inches
        Miles = 63360 * Miles
        Yards = 36 * Yards
        Feet = 12 * Feet

        'convert to meters
        totalMeters = totalInches / 39.37
        Miles = Miles / 39.37
        Yards = Yards / 39.37
        Feet = Feet / 39.37

        km = Miles
        m = Yards
        cm = Feet



        km = Int(Miles / 1000)
        m = Int((totalMeters - Miles) / 1000)
        cm = Math.Round(totalMeters - (km + m), 1)

        'display
        cm = Math.Round(cm, 2)
        With lstOutput.Items
            .Add("The metric length is")
            .Add(km & " kilometers")
            .Add(m & " meters")
            .Add(cm & " centimeters")
            .Add(totalInches)
            .Add(totalMeters)
        End With



I was trying to convert, w/ these formulas, and tested it w/ these input numbers:
formula1, totalInches = 63360 * miles + 36 * yards + 12 * feet + inches
#2 totalMeters = totalInches / 39.37
Note: I have no idea why i need the total inches or meters.
kilometers = Int(meters/1000), i use miles instead of meters and it works.
input #'s
Miles = 5
Yards = 20 to 8 only this one works for me
Feet = 2 to 65
Inches = 4 to 73.5

please help, thanks, i just need even at least tips on what to do, even just explanations, thanks.

Last edited by dwizzle13; Oct 4th, 2006 at 8:18 PM. Reason: had too much code/ need code tags
dwizzle13 is offline   Reply With Quote
Old Oct 4th, 2006, 7:51 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
As a new member, you should read the forum's Rules/FAQ, specifically, in this case, in regard to code tags. Anything less is rude to those from whom you seek help.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 4th, 2006, 7:54 PM   #3
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
sorry, didn't notice tht, thanks. BTW, the error was that i got riddiculios numbers on the meters and centimeters when i displayed them.

Last edited by dwizzle13; Oct 4th, 2006 at 7:56 PM. Reason: more info
dwizzle13 is offline   Reply With Quote
Old Oct 4th, 2006, 8:06 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Your code is illogical and your naming conventions are confusing. Miles is not equal to 63360 * Miles. That gives you inchesPerMile. Still, a name is just a name if you don't get confused. The problem is that you are multiplying Miles by 63360 at the beginning of your code, and again in line 4. That gives you 63360*63360*Miles, which is a somewhat larger number than you want. Similarly, elsewhere.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 4th, 2006, 8:12 PM   #5
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
i fixed the miles, but the miles = 63360 * Miles the first time is because i had to change 5 miles into its inch equivilent, and the same w/ the others, but i don't know why, it was just the way the problem goes. So what else is wrong? I'll update the above code.
dwizzle13 is offline   Reply With Quote
Old Oct 4th, 2006, 8:15 PM   #6
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 710
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
I don't really get what your doing with your code. It should be simple. Perhaps your over thinking it.
Feet = CM * 30.48
Metres = Yards * 0.9144

How hard is that to throw into the equation?

I'm not amzing at math, and never realyl had to bother with conversions, but if you get your math right, consider posting all of your code. Also, as you said, you have to do it a paticular way for your class, so it may not be as easy as just that. The class is to teach you programming, not math. If you have problems with the math, simply google the equations. the google calculator always helps me. I have noticed that you haven't declared any of the variables. Some might tell you that vb is sloppy and will do it for you. In some cases that is true, but I have experiences that say otherwise.
Booooze is offline   Reply With Quote
Old Oct 4th, 2006, 8:18 PM   #7
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
ok, i don't think it'll work, i'm trying to convert us to metric. I'll post the full code above.
dwizzle13 is offline   Reply With Quote
Old Oct 4th, 2006, 8:19 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You can't multiply them twice. The yards and feet things have the same problem. You are going to have to choose one or the other. You can say,
Miles = 63360 * Miles
Yards = 36 * Yards
Feet = 12 * Feet
totalInches = Miles + Yards + Feet
or, you can say,
totalInches = (Miles * 63360) + (Yards * 36) + (Feet * 12)
You can't do both. If you correct that and have additional problems, post back with the fresh (corrected) code. It would also help if you post enough for us to see the source of the values you are manipulating and explain precisely what you are supposed arrive at with those values. Information is key here; my crystal is in the shop for 'ball' joints.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 4th, 2006, 8:25 PM   #9
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
Ok, here's the fresh code, my only problem is the answers(output) of meters and cm are 0 meters, and 8057.6 cm. I needed to get an answer of 65 meters and 73.5 centimeters.



Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        Dim Miles, Yards, Feet, Inches, totalInches, totalMeters As Double
        Dim km, m, cm As Double
        'assign values from txt boxes
        Miles = txtMiles.Text
        Yards = txtYards.Text
        Feet = txtFeet.Text
        Inches = txtInches.Text

        'convert to inches
        Miles = 63360 * Miles
        Yards = 36 * Yards
        Feet = 12 * Feet
        totalInches = Miles + Yards + Feet

        'convert to meters
        totalMeters = totalInches / 39.37
        Miles = Miles / 39.37
        Yards = Yards / 39.37
        Feet = Feet / 39.37

        km = Miles
        m = Yards
        cm = Feet



        km = Int(Miles / 1000)
        m = Int((totalMeters - Miles) / 1000)
        cm = Math.Round(totalMeters - (km + m), 1)

        'display
        cm = Math.Round(cm, 2)
        With lstOutput.Items
            .Add("The metric length is")
            .Add(km & " kilometers")
            .Add(m & " meters")
            .Add(cm & " centimeters")
            .Add(totalInches)
            .Add(totalMeters)
        End With

    End Sub
dwizzle13 is offline   Reply With Quote
Old Oct 4th, 2006, 8:36 PM   #10
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
srry about missing tags, etc... it's hard to do this prog, and i need help since i have no idea about it, especially this part:

km = Int(Miles / 1000)
        m = Int((totalMeters - Miles) / 100)
        cm = Math.Round(totalMeters - (km + m), 1)
dwizzle13 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic 2005 Express Edition For Dummies ReubenK Book Reviews 3 Jul 31st, 2007 8:47 AM
Compiling Maverik 6.2 (from C) megamind5005 C 16 May 3rd, 2006 5:41 PM
visual basic pixel image comparison youngnoviceinneedofhelp Visual Basic 3 Mar 19th, 2006 1:57 PM
Enquiry About Visual Basic Project kbkhoo5053 Visual Basic 13 Feb 15th, 2005 2:20 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC