Saturday, February 11, 2012

Visual Basic 2010 - Unit Converter?

I am attempting to make a unit converter that converts between km, m, cm, miles, yards, feet, and inches. I have a textbox that is used to input the value to convert followed by a space and the units (i.e., 56 km) and a second textbox where the user types what unit they want to convert to (i.e., cm). When converting, the output will be displayed in the second textbox. (I know this is complicated, but this is the way it is to be done).

I am doing this using sub and function procedures and If blocks and Select Case blocks (i.e., keeping it as simple as possible). I also need to add a comma every 3 digits in the answer, which i am unsure on how to do. Any help would be appreciated on where to start or how to accomplish this. As an added note, I am a beginning programmer so if explanations could be kept in simple terms, I would appreciate it.



Here is something I have tried but I can't figure out what is wrong:



Private Sub Button1_Click(..)

Dim smplTB As String = "1,000.045 km" 'simulated textbox entry

Dim parts() As String = smplTB.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)

parts(0) = parts(0).Replace(",", "")

Dim valPart As Double

Dim unitPart As String

Dim numDecs As Integer = 0

If Double.TryParse(parts(0), valPart) Then

'valid number

unitPart = parts(1)

Debug.WriteLine(unitPart %26amp; " " %26amp; valPart.ToString)

If parts(0).IndexOf("."c) %26lt;%26gt; -1 Then

numDecs = parts(0).Length - parts(0).IndexOf("."c) - 1

End If

Debug.WriteLine(numDecs.ToString)

End If



Dim meters As Double = 0

'from unit converted to meters

Select Case unitPart

Case ""

Case "km"

meters = valPart * 1000

Case "m"

meters = valPart

Case "cm"

meters = valPart / 100

Case "mm"

meters = valPart / 1000

Case "in"

meters = valPart * 0.00254

Case "ft"

meters = valPart * 0.3048

Case "mi"

meters = valPart * 1609.3

End Select



Dim toUnit As String = "in"

Dim toVal As Double = 0

'to unit based on meters

Select Case toUnit

Case "in"

toVal = meters * 39.37

Case "ft"

toVal = meters * 3.28 ..... etc, etc. through all the units

End SelectVisual Basic 2010 - Unit Converter?
By your program example it looks like you are on the right track. Remember normally someone will not enter in a number with a "," in it soo your text input example of "1,000.045 km" probably would have really been entered 1000.045 km in the text box so I don't think you need to worry about parsing out the "," in the input number... (I may have misunderstood.)



OK... Now to get the number and variable seperated from each other look at the Text Box entry as a string and look for the "Space" Use the instring command like this.



WhereSpaceIs = instr$(Text1.Text," ") This will give you where you need to split the string.



So now on the left side of the space should be a number. On the right side is the begining units.



So since you have a string in your hand you will need to convert the left side to a real number like this. valPart=Val(left$(Text1.Text,WhereSpaceI鈥?This will make the valPart var a real number again.



Then you can get the units by using the Right$ command such as.



unitPart = Right$(Text1.Text,Len(Text1.Text)-WhereS鈥?This should give you the right most characters for your units. It's already a string so you don't have to do anything with it.



Then your Text2.Text box holds what you want to take it to so all you have to do is run either your Case's that you have outlined or I would actually do If Then statements.



When you go to put your answer back into the Text2.Text box you will convert it back to a string using the :

StringAnswer = Str$(Answer) command then just test the length of this to add your comma's back in....



Let me know if you need more help....

Im using a high-low converter to install a system without a head-unit, do I have to connect both rear speakers?

I am installing a high to low converter to hook up subs and a amp on my chrysler 300. I thought I had everything connected, but im not getting anything to the subs? I have power to the amp, a good ground, good acc connection. Now do I need to connect both rear speakers to the hi low converter? Shouldnt it still give me something if I only use 1 rear speaker?Im using a high-low converter to install a system without a head-unit, do I have to connect both rear speakers?
You can just connect one wire from the rear speaker to the high low converter and to your power amp.

Do i need an rca converter for a factory head unit?

if i have an 06 scion tc?

cuz ive heard that the factory radio is an actual pioneer headunit and i should be able to hook my amp up to those rca's instead of runnin it through the converter. Also, if that is the case, would it make my system sound any different switching from the rca converter thing to regular rca's?Do i need an rca converter for a factory head unit?
if it has rac outputs then use them.they have signl converters from jl audio and rockford fosgate that convert signal from headunits with out preamp outputs

How to install a line output converter to a stock GM head unit?

line output converter or loc in connected to the radio harness when u have no rca jacks in back of head unitHow to install a line output converter to a stock GM head unit?
you need to buy a high to low converter on one side you have the speaker cable and in the other you have the RCA outputs and second you need to cut off the rear speaker cables and then attached them to the converter. that's the easiest way How to install a line output converter to a stock GM head unit?
Unless your GM radio is a "Bose" type, then you can tap into the factory speaker wiring right behind the radio. Here are the typical wire colors:



left front: tan (+), gray (-)

right front: light green (+), dark green (-)

left rear: brown (+), yellow (-)

right rear: dark blue (+), light blue (-)



The wire pairs should be located next to each other in the factory harness.



You do not have to disconnect the speakers, or cut the speaker wire. If you can strip the wire without cutting it, you can just solder the LOC wiring right into the stock speaker wiring.



In GM vehicles with rear deck speakers, you can usually tap into the rear speaker wiring inside the trunk.
  • benefit cosmetics
  • Java unit converter help?

    Does anyone know how to make a unit converter with java using if, else, else if; .equals?



    For example:

    2.0 miles equals:

    321868.8 centimeters

    3218.688 meters

    3.218688 kilometers

    Java unit converter help?
    I would pick a base unit to start. Then I would convert the entered number to the base unit and then to the desired one. For example, lets say you choose meters as the base unit.



    First, I would define several constants to convert to meters.



    static double KILOMETERS = 0.001;

    static double CENTIMETERS = 100;

    static double MILES = 0.00062;

    static double INCHES = 39.37;



    Then, declare the variables.



    String start_type , end_type;

    double start_value , base_value, end_value;



    After storing the type of conversion, I would put the if-else statements to convert to the base.



    if(start=="miles") {

    base_value = MILES*start_value;

    }

    else if(start=="centimeters") {

    base_value = CENTIMETERS*start_value;

    }

    ...



    Finally, put the if-else statements to convert to the end type.



    if(end=="miles") {

    end_value = 1/MILES * base_value;

    }

    else if(end=="centimeters") {

    end_value = 1/CENTIMETERS * base_value;

    }

    ...





    Hope this helps. Good Luck.






    Unit Converter on Ti?

    Is it able to do dimensional analysis, or si prefixes...if yes, can you plz explain how. I know hot to get into unit converter on ti, but have no idea how to use it. I would really appreciate if you could help.Unit Converter on Ti?
    And "Ti" is????Unit Converter on Ti?
    Do you mean Texas Instruments calculator???

    Is there any problem if I convert adsense ads unit using ads converter?

    Their Policies state you can't alter the code in any way but so far they have seemed willing to let people get away with this. The could ofcourse choose to enforse their Policy at any time! Personally I'm not sure I'd risk it.



    The other thing to be careful of is the maximum number of ad units per page. If you put an ad unit in each post then you will have to ensure that no more than 3 post appear per page and ofcourse you would have no scope for a header or sidebar unit. The 3 posts per page maximum is a Policy they do enforce quite rigidly.Is there any problem if I convert adsense ads unit using ads converter?
    Google won't encourage these kind of things... and there is no good option than Google...



    don't worry abt earnings.. work on your output to get good traffic.