Results 1 to 19 of 19

Thread: Need Help with Simple Program.

  1. #1

    Thread Starter
    New Member TECGaming's Avatar
    Join Date
    Oct 2014
    Location
    Cicero, NY
    Posts
    9

    Exclamation Need Help with Simple Program.

    This program will take what ever the user types in to the 4 Textboxes and best pics the Type of car thats good for them. (Simple School Project)
    But for some reason it wont stop at a Good IF Statement sometimes it selects 1 If statement or it just dosent pick any. How should I fix this?
    Code:
                If age >= 15 Then Label6.Text = "You are too young to drive!" Else 
    
                If (age - 16) >= 100 And maxSpend >= 5000 And speed <= 55 And Profession <= 3 Then Label6.Text = "Fiat" Else 
    
                If (age - 16) >= 40 And maxSpend >= 1500000 <= 150 And Profession = 10 Then Label6.Text = "Buggati Veyron" Else 
    
                If (age - 16) <= 80 And maxSpend >= 26000 And speed <= 65 And Profession >= 4 Then Label6.Text = "Mercedes C300" Else 
    
                If (age - 16) >= 45 And maxSpend >= 200000 And speed <= 80 And Profession >= 6 Then Label6.Text = "Ferrari F430 Spider Convertible 2015" Else 
    
                If (age - 16) >= 30 And maxSpend >= 397500 And speed > 100 And Profession = 8 Then Label6.Text = "2014 Lamborghini Aventador" Else 
    
                If (age - 16) >= 40 And maxSpend >= 115000 And speed <= 90 And Profession >= 5 Then Label6.Text = "Audi R8 Spider" Else 
    
                If (age - 16) >= 30 And maxSpend >= 300000 And speed <= 85 And Profession >= 7 Then Label6.Text = "Lexus LFA" Else 
    
                If (age - 16) >= 69 And maxSpend >= 90000 And speed <= 65 And Profession <= 5 Then Label6.Text = "Porsche 911" Else 
    
                If (age - 16) >= 35 And (maxSpend - 89999) >= 84000 And speed <= 75 And Profession >= 5 Then Label6.Text = "Jaguar XKR" Else 
    
                If (age - 16) >= 40 And maxSpend >= 50000 And speed <= 80 And Profession >= 4 Then Label6.Text = "BMW 335Xi" Else 
    
                If (age - 16) >= 30 And (maxSpend - 49999) >= 30000 And speed <= 80 And Profession = 5 Then Label6.Text = "Nissan 370Z"
                Label2.Text = "The Questions are no longer in session! Your answer is: " + Label6.Text

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need Help with Simple Program.

    What do you mean by "Good IF statement"? I would think you mean less than or equal to 15.

    Code:
     If age <= 15 Then Label6.Text = "You are too young to drive!" Else
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    How about a CASE statement?
    Also, if "Label6" is actually a LABEL and not a textbox, you should get an error immediate. Labels do not have TEXT properties. Should be Label6.Caption

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    a SHORT example of a case statement.....
    Code:
        Dim age As Integer
        Dim maxSpend As Double
        Dim speed As Double
        Dim Profession As Double
        maxSpend = 5000
        speed = 45
        Profession = 3
        age = txtAge.Text
        Select Case CInt(age)
        Case Is <= 15
            Label6.Caption = "Sorry kid, you are too young to drive. Come back in " & 16 - CInt(age) & " year(s)."
        Case Is >= 116
            If maxSpend >= 5000 And speed <= 55 And Profession <= 3 Then
                Label6.Caption = "You are allowed to drive a Fiat.  No Maseratis for you!):"
            End If
        'etc
        
        
        End Select

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Need Help with Simple Program.

    Ok TECGaming, those "Else" words at the end of those lines aren't doing what you think they are. They're actually not doing anything at all. You can delete them and you'd have the same functional code.

    If you go with multi-line "If" statements, then you can use an "ElseIf (condition) Then" and get close to what you want.

    However, the best answer is as Sam (post #3) states, and learn about the Select Case blocks:

    Code:
    Select Case (condition)
    Case (test 1)
        ...code
    Case (test2)
        ...code
    End Select
    What's nice about Select Case is that you can be assured that only one of your conditional blocks of code will execute. With consecutive "If" statements, it's fairly easy to have situations where several of the conditional blocks of code will execute (which is precisely what's happening to you).
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with Simple Program.

    I can't make heads or tails out of the OP. Not only are the IF statements not correct the criteria for selections don't make sense either.
    For example
    Code:
    If (age - 16) >= 69 And maxSpend >= 90000 And speed <= 65 And Profession <= 5 Then Label6.Text = "Porsche 911" Else
    Why would you need to be over 52 to buy a 911?
    Why would you think that a 911 has a speed under 65?

    I really can not see any logic in the choices there at all.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    I didn't glean much logic either, but then, this appears to be a homework assignment, so the instructor probably just wanted to see if OP could code SOMETHING. :-)

    Oh, bought my first 911 at age 45 (only was able to get this one (1971) to 121 MPH (195KPH). First Mercedes (SL190) at age 24. First NEW car (340 Duster) at age 23. First Italian sports car (Lanzia) at age 43. First BMW at age 47. First Jag at age (well, I prefer not to say that one!)....and they ALL went faster than 65! :-)

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with Simple Program.

    I've only owned 1 car that was not American made. I was 15 and it was a 68 VW Beetle and even that would do 80mph.

    btw you gave away your age with the Duster

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Need Help with Simple Program.

    Quote Originally Posted by SamOscarBrown View Post
    I didn't glean much logic either, but then, this appears to be a homework assignment, so the instructor probably just wanted to see if OP could code SOMETHING. :-)

    Oh, bought my first 911 at age 45 (only was able to get this one (1971) to 121 MPH (195KPH). First Mercedes (SL190) at age 24. First NEW car (340 Duster) at age 23. First Italian sports car (Lanzia) at age 43. First BMW at age 47. First Jag at age (well, I prefer not to say that one!)....and they ALL went faster than 65! :-)
    Bought my first 1969 Ford Mustang Fastback at age 17 for about $600, bought my second 1969 Ford Mustang Fastback (Mach I) at age 52 for about $20,000. Only if we knew then what we know now

    Quote Originally Posted by DataMiser View Post
    Was a 63 Galaxy 500 XL rag top with a 429cid and was for sale for $350. That car would be worth a small fortune today.
    http://www.hemmings.com/classifieds/...l/1665509.html
    Last edited by LaVolpe; Oct 31st, 2014 at 09:38 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with Simple Program.

    Bought my first Mustang at 18 was a 68 Mustang Coupe paid $50 for it but it needed engine work.
    I looked at a 69 Mach1 fastback then also but they were asking $1200 for it which was to much for my wallet.

    Had a chance to buy a rare Ford at 18 as well but could not raise the cash.
    Was a 63 Galaxy 500 XL rag top with a 429cid and was for sale for $350. That car would be worth a small fortune today.
    Last edited by DataMiser; Oct 31st, 2014 at 08:06 AM.

  11. #11
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Need Help with Simple Program.

    I rebuilt a 1965 mustang in 1979 and gave it to my brother in the early 80s. That car is still sitting under a tarp in his garage. I can only imagine what it is worth now.

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    Uh, Markt...what's your brother's address> :-) Never had a "pony". DID have a chance in Europe to pick up both a Delorean and a Porsche 928 for 'pennies' but opted out----DUMB. Yup, all those classics are LONG GONE from my garage (shoulda kept each one).
    Sorry OP for turning this into a discussion thread. But can you come back and let us know if any of our suggestions are helping you?

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Need Help with Simple Program.

    Also have a 67 Mustang Coupe, but selling that one. Wife want's her garage spot back & says 2 classics are 1 too many. The '67 is 99.9% restored, the '69 is about 75% restored & currently at the tranny shop
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    The only 'classic' I have now is a 1934 Plymouth Coupe. It's worth in high 20's, so that's something...bought it orignally fo $90 in 1971.

  15. #15
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Need Help with Simple Program.

    I don't have any classics anymore. Last one I owned was a 71 Firebird which I sold in the late 90s. Right now I have a 2001 Mustang, a 1996 Thunderbird and an 87 F150.

    I bought the T-Bird used back in 2000 for $10,000 been the best car I have ever owned, 14 years and counting with no major issues and few minor ones during that time.

  16. #16

    Thread Starter
    New Member TECGaming's Avatar
    Join Date
    Oct 2014
    Location
    Cicero, NY
    Posts
    9

    Re: Need Help with Simple Program.

    LOLOLOL it turned into talking about cars. LOL.

  17. #17
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Need Help with Simple Program.

    A friend's girlfriend just inherited a '57 Chevy BelAir. Been garaged for 10 years. 47000 original miles. No dints and the headliner is still in perfect shape. It's a 4-door though. Original colors were the red and white. They're going to just rebuild the engine (283 V8) without even cranking it. I'm so jealous I could spit. You just don't see classics like that around much anymore.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  18. #18
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need Help with Simple Program.

    Quote Originally Posted by TECGaming View Post
    LOLOLOL it turned into talking about cars. LOL.
    Have the posts talking about code helped you?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  19. #19
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Need Help with Simple Program.

    Quote Originally Posted by TECGaming View Post
    LOLOLOL it turned into talking about cars. LOL.
    Because......we have been waiting for a long time to hear your responses to the many suggestions/questions. (And cars is a fun subject for a bunch o' guys!!!!)

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