Some programming help

Discussion in 'School Work Help' started by iris, Sep 6, 2009.

  1. iris

    iris Well-Known Member

    296
    53
    0
    Hello, I'm re-reading my notes from my programming class last week and I need help coming up with a line. We're using Visual Basic in class and we were just messing around with some stuff.

    The task i'm trying to do is figure out how to calculate the area of a room but I can't figure out what how to write that code. I know it's length * width :p

    I have it set up to where you write the input into the length and width box, then you press the button to calculate the output into a separate text box. Any suggestions? thanks in advance
     
  2. iris

    iris Well-Known Member

    296
    53
    0
    oh hehe I got it

    Dim area As Double
    Dim length As Double
    Dim width As Double
    length = CDbl(txtLength.Text)
    width = CDbl(txtWidth.Text)
    area = length * width
    txtArea.Text = CStr(area)

    A mod can delete the thread haha
     
  3. spider-man

    spider-man Well-Known Member

    466
    55
    1
    OMG, this is easy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    iris is right but I would change the last line to this:

    txtArea.Text =math.round( CStr(area)*100) *100

    it rounds to 2 decimal places.
     
  4. wufei

    wufei New Member

    4
    226
    0
    mmm... i think that jonathan is wrong... cause if u just want to round it to 2 decimal... just

    Try

    TxtArea.Text= CStr(Round(area , 2));

    that would be enough to do the trick :p
     
  5. spider-man

    spider-man Well-Known Member

    466
    55
    1

    I made a mistake. It's suppose to be:

    txtArea.Text =math.round( CStr(area)*100) /100

    How come you need to convert it to String. Area is a double, not a word. (Just wondering)
    TxtArea.Text= CStr(Round(area , 2))

    :)
     
  6. wufei

    wufei New Member

    4
    226
    0
    very simple... it just that "txtArea.test" method can accept string only... :p
     
  7. Paramonos

    Paramonos New Member

    1
    26
    0
    Well, the above is true if you compile with option explicit. If not, the textbox.text will convert the values to String.