Results 1 to 11 of 11

Thread: [RESOLVED] [Excel] Output issues

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Resolved [RESOLVED] [Excel] Output issues

    For my Computational Techniques Class, we have to write a program that inputs temperature and wind speed, and computes the wind chill factor. The program also has to output what type of coat the person should wear.

    Additionally, wind chill is not defined when t > 50 or when wind < 3 mph, so the program must define this. If a wind chill factor is not obtainable, the program must still output the temperature and give a coat rec.

    I don't see where my issue is, I run the program, and it doesn't output much correctly. Some values are missing when i run the program and it ends before the calculation, and when it runs all the way through, no values are returned at all.

    Help would be appreciated. Thanks in advance!


    Code:
    'in this program, a user will input wind speed and temperture to find the wind chill.'
    'this is the declaration statement'
    Option Explicit
    
    Dim wc As Double
    Dim t As Double
    Dim mph As Double
    
    Sub windchill()
    'this part will input the data'
    
    
    t = InputBox("What is the temperture?", , 50)
    mph = InputBox("What is the wind speed?")
    If t > 50 Then
    MsgBox ("It must be colder than 50 degrees Farenheit for wind chill to be a factor.")
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Type of coat?"
    Cells(2, 2) = "No coat necessary!"
    End If
    
    If Cells(2, 1) > 50 Then End
    
    If mph < 3 Then
    MsgBox ("The wind must be blowing harder than 3 mph for windchill to be a factor.")
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Wind speed in MPH"
    Cells(2, 2) = mph
    Cells(1, 3) = "Coat Recommendations"
    End If
    If 50 > t > 40 Then
    Cells(2, 3) = "No coat necessary.!"
    ElseIf 40 >= t >= 15 Then
    Cells(2, 3) = "Wear a light coat, as it may get a bit nippy!"
    ElseIf 15 > t Then
    Cells(2, 3) = "Bring out the parka. Eskimos only may proceed."
    End If
    
    If Cells(2, 2) < 3 Then End
    
    
    
    If t > 50 And mph > 3 Then
    wc = (0.0817 * (3.71 * Sqr(mph) + 5.81 - 0.25 * mph) * (t - 91.4) + 91.4)
    End If
    
    If 50 > wc > 40 Then
    MsgBox ("The weather is fine, no coat is needed!")
    ElseIf 40 >= wc >= 15 Then
    MsgBox ("A light coat is reccomended!")
    ElseIf 15 > wc Then
    MsgBox ("Bring out the parka. Eskimos only.")
    End If
    
    Cells(1, 1) = "Temperature in F"
    Cells(1, 2) = "Wind speed in MPH"
    Cells(1, 3) = "Wind chill in F"
    Cells(2, 1) = t
    Cells(2, 2) = mph
    Cells(3, 2) = wc

  2. #2
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: [Excel] Output issues

    Code:
    If 50 > wc > 40 Then
    I don't think this line does what you think it does. Remember operator precedence and execution order. In this case I think 50 > wc would evaluate to true or false and then do true/false > 40 which would never be true. It's confusing syntax at any rate don't use it. Use an and or something.
    Last edited by dmaruca; Feb 15th, 2012 at 09:38 PM.

  3. #3
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: [Excel] Output issues

    Use a select case if you want it to follow english more...

    Code:
    Select case wc
        Case 40 to 50
            'code
    End Select

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2012
    Posts
    4

    Re: [Excel] Output issues

    Quote Originally Posted by dmaruca View Post
    Code:
    If 50 > wc > 40 Then
    I don't think this line does what you think it does. Remember operator precedence and execution order. In this case I think 50 > wc would evaluate to true or false and then do true/false > 40 which would never be true. It's confusing syntax at any rate don't use it. Use an and or something.
    Yeah, I figured that out after some tinkering. I eventually changed to a combination of case and if statements, but it still won't output some of the time. It refuses to output for the cases where the temperatures/ wind speed are outside of the accepted parameters for the wind chill formula, and I'm, again, stumped. It appears to output correctly for other cases, however.


    Code:
    'in this program, a user will input wind speed and temperture to find the wind chill.'
    Option Explicit
    
    Dim wc As Double
    Dim t As Double
    Dim mph As Double
    
    Sub windchill()
    'this part will input the data'
    
    
    t = InputBox("What is the temperture?", , 50)
    mph = InputBox("What is the wind speed?")
    
    Select Case t And mph
    Case t > 50
    MsgBox ("It must be colder than 50 degrees Farenheit for wind chill to be a factor.")
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Coat?"
    Cells(2, 2) = "Only if you're a wimp."
    End
    
    Case mph < 3
    MsgBox ("The wind must be blowing harder than 3 mph for windchill to be a factor.")
    If t > 40 And t < 50 Then
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Wind speed in MPH"
    Cells(2, 2) = mph
    Cells(1, 3) = "Coat Recommendations"
    Cells(2, 3) = "Only if you're a wimp."
    ElseIf t <= 40 And t > 15 Then
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Wind speed in MPH"
    Cells(2, 2) = mph
    Cells(1, 3) = "Coat Recommendations"
    Cells(2, 3) = "A small one is acceptable, I suppose...."
    
    ElseIf t <= 15 Then
    Cells(1, 1) = "Temperature in F"
    Cells(2, 1) = t
    Cells(1, 2) = "Wind speed in MPH"
    Cells(2, 2) = mph
    Cells(1, 3) = "Coat Recommendations"
    Cells(2, 3) = "Bring out the parka."
    End
    End If
    
    Case Else
    wc = (0.0817 * (3.71 * Sqr(mph) + 5.81 - 0.25 * mph) * (t - 91.4) + 91.4)
    
    If 50 > wc And wc > 40 Then
    MsgBox ("The weather is fine, no coat is needed!")
    Cells(1, 1) = "Temperature in F"
    Cells(1, 2) = "Wind speed in MPH"
    Cells(1, 3) = "Wind chill in F"
    Cells(2, 1) = t
    Cells(2, 2) = mph
    Cells(3, 2) = wc
    Cells(1, 4) = "Coat Reccomendation"
    Cells(2, 4) = "Grow a pair or move to San Diego."
    
    ElseIf 40 >= wc And wc >= 15 Then
    MsgBox ("A light coat is reccomended!")
    Cells(1, 1) = "Temperature in F"
    Cells(1, 2) = "Wind speed in MPH"
    Cells(1, 3) = "Wind chill in F"
    Cells(2, 1) = t
    Cells(2, 2) = mph
    Cells(3, 2) = wc
    Cells(1, 4) = "Coat Reccomendation"
    Cells(2, 4) = "Should probably dust off a decent jacket."
    
    ElseIf 15 > wc Then
    MsgBox ("Bring out the parka. Eskimos only.")
    Cells(1, 1) = "Temperature in F"
    Cells(1, 2) = "Wind speed in MPH"
    Cells(1, 3) = "Wind chill in F"
    Cells(2, 1) = t
    Cells(2, 2) = mph
    Cells(3, 2) = wc
    Cells(1, 4) = "Coat Reccomendation"
    Cells(2, 4) = "Go Eskimo, bro."
    End If
    
    End Select
    
    End Sub

  5. #5
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [Excel] Output issues

    if i was your "Computational Techniques Class" teacher i would be ashamed at how bad my teaching obviously is..

    nothing in your attempt to solve this problem, indicates that you have been taught anything about problem solving.

    and a class that teaches computaional techniques should have covered enough for you to make reasoned choices, using appropriate structures and commands, before they set you problems!

    It is good practice to know the students can solve a problem before setting them as this will result in a learning and retention process which after all is the whole purpose of such classes!

    i am dissapointed in your teacher...

    AND BEFORE ANYONE GETS ON MY BACK ABOUT THIS ( I TEACH ) AND I HAVE NEVER HAD A STUDENT FAIL (EVER!) NOT EVEN THOSE WHO OTHERS THOUGHT WHERE A WASTE OF SPACE!!!

    there is always a way to get information into a student and always a way to express every and any thing!

    If a student dies at the back of the class, then i will accept there may be a problem educating them!

    here to help

    We can work through the process for you like a lesson if you really need this! - but i will not give you the answers!

  6. #6
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: [Excel] Output issues

    I would love to hear some tips from you, incidentals. I have recently started giving a class to workmates and I find it hard to go back and see things from their perspective. I started off by explaining some basics and giving some examples on the screen. Then I gave them a slightly modified example to do themselves and they were able to mostly pull it off. Repeat the next class and the same technique failed. Teaching a class of people is not easy.

  7. #7
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: [Excel] Output issues

    Code:
    Select Case t And mph
    Juicy, I think this is your sticking point right now. You're trying to code in English, but that's not how the computer thinks. "AND" is an operator to the computer. Read this wikipedia article to see what is happening under the hood. In your case "t And mph" combine together to make one number. You should only use a select case on one variable except in rare cases.

  8. #8
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [Excel] Output issues

    there is the problem at the end of your paragraph...

    teaching a class of people is not easy.

    i was going to give you a nice quote, but then i lost the will to live...

    WE DO NOT TEACH PEOPLES OR CLASSES OR YEAR GROUPS OR ANY COLLECTIVE THING!

    we endeavour to teach the individual to achieve to the best of their abilities and to reach the goals they aspire to.

    We do however have to teach a collected body of knowledge to them all!

    NEVER EXPECT WHAT WORKED YESTERDAY TO WORK TOMMORROW WITHOUT REVIEWING HOW IT WORKED TODAY IF INDEED IT DID WORKED AT ALL!

    I teach concepts not actions, my students learn to cope and often thrive in an ever changing world of technological "advancement" i quote the word advisadly...

    here to help

    if you have the time i would suggest you start at the very start of this question, at the design stage.

    are you up for it?

  9. #9
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: [Excel] Output issues

    Quote Originally Posted by incidentals View Post
    i was going to give you a nice quote, but then i lost the will to live...
    I hope I never end up in one of your classes.

  10. #10
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [Excel] Output issues

    @dmaruca
    you have a problem with me less a third of the way through a communication and then i get a little down on the whole thing... but then get up and do a whole lot more!

    how many of your teachers gave up on you?

    did you always have enough to interest you ?

    was the class arranged around some other fictitious persons abilities ?

    did you fit that norm?

    most intellegent people get bored and are not catered for in the "normal classroom", its not just the under achievers or the hyperactive or the baddly behaved or the challenged who have a problem...

    what was yours?

    if the answer was there was not one , you are either "normal" and recieved the normal "limited" education, or you are lying to your self and just caosted along - missing the oportunities that could have been made available to you be a teacher whoes mission was to educate!

    here to help

  11. #11
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [Excel] Output issues

    i have not tested, but it may be the case that a select case setup! to reference an expression will work as the OP has used it.

    it may equate to

    select case true
    case test
    case tes1
    end select

    such select structures are able to test a variety of things unlike

    select case x
    case 2
    case 4
    end select

    that responds to x and nothing else

    just tested the hypothosis and using expressions does case the select statement to switch to true false versions!

    @dmaruca - did you know this, or even suspect it, have you ever used "select case true/false"? its an educational thing!

    here to help
    Last edited by incidentals; Feb 18th, 2012 at 09:30 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width