Results 1 to 6 of 6

Thread: Learning & need help

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    4

    Question Learning & need help

    Hello everyone, I am new here and new in programming (coding) and could use some help. I am currently trying to configure a simple tool for a game I play.

    What I want the tool to do is to tell me an exact distance (which is a number) after choosing a few options (that will change the distance in their way)

    Example, I have 45 yards to chip, but I choose a rain option that reduces my ball by 0.12% so i'd like that initial 45 yards to be calculated into the real distance.

    Can anyone help me with the coding, I literally don't know much but I am trying to learn. Here's what I am trying to do.


    Weather Option:

    Cloud Option reduces 8% the distance traveled.
    Rain Option reduces 12% the distance traveled.
    Sun Option reduces 0% the distance traveled.

    Ground Option:

    Fairway Option reduces 0% the distance traveled.
    Bunker (sand) Option reduces 28% the distance traveled.
    Rough (grass) Option reduces 12% the distance traveled.

    Here is a screenshot of the UserForm to help you guys.

    Name:  Program.png
Views: 155
Size:  8.3 KB
    Last edited by Tonybboi; Aug 26th, 2016 at 05:06 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    4

    Re: Learning & need help

    Here's is what I tried so far.. (Keep in mind that this is first code I have ever programmed and that I am very new to this)

    Private Sub CalculateButton_Click()
    'Calculating the distance
    Me.CorrectBox = Me.DistanceValue

    If ClouOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1.08
    If RainOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1.12
    If SunOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1#
    Else
    If FairwayOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1#
    If BunkerOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1.28
    If RoughOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1.12


    End Sub
    Help please, anything would help at this stage....
    Last edited by Tonybboi; Aug 26th, 2016 at 01:49 PM.

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

    Re: Learning & need help

    so is the value actually 0.12% or is it 12%

    Your code is using 12% so if you really mean 0.12% you need some 0s in there
    Code:
    If RainOption.Value = True Then CorrectBox.Value = DistanceValue.Value * 1.0012
    Last edited by DataMiser; Aug 26th, 2016 at 03:50 PM.

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

    Re: Learning & need help

    That said you need to do this a bit differently as is you would only be applying part of the modification when more than one are needed.

    Would be best to create another variable lets call it modifier.
    In each if statement add to that modifier as needed then after all the if statements you have your total modifier value you can add to the distance to get your adjusted distance.
    Code:
    If ClouOption.Value = True Then Modifier=Modifier + (DistanceValue.Value * .0008)
    If RainOption.Value = True Then Modifier=Modifier + (DistanceValue.Value * .0012)
    ... and so on
    CorrectBox.Value = DistanceValue.Value +Modifier
    Note that else line should not be there at all.
    You also do not need to do anything for the fairway or sunny since those do not change the distance.

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Posts
    4

    Re: Learning & need help

    Great, thank you DataMiser for the help, it really mean alot to me! So Modifier changes the value only when it is True, but what if the 2 options have to modify the values ?

    Ex: Rain + Bunker

    * I am sorry, here are the %'s;

    Rain affects the distance by 12%
    Clouds affect the distance by 8%

    Rough shot affects distance by 12%
    Bunker shot affects distance by 28%

    Quote Originally Posted by DataMiser View Post
    That said you need to do this a bit differently as is you would only be applying part of the modification when more than one are needed.

    Would be best to create another variable lets call it modifier.
    In each if statement add to that modifier as needed then after all the if statements you have your total modifier value you can add to the distance to get your adjusted distance.
    Code:
    If ClouOption.Value = True Then Modifier=Modifier + (DistanceValue.Value * .0008)
    If RainOption.Value = True Then Modifier=Modifier + (DistanceValue.Value * .0012)
    ... and so on
    CorrectBox.Value = DistanceValue.Value +Modifier
    Note that else line should not be there at all.
    You also do not need to do anything for the fairway or sunny since those do not change the distance.
    Last edited by Tonybboi; Aug 26th, 2016 at 05:01 PM.

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

    Re: Learning & need help

    As you can see modifier is being added to there so if it were raining it would get the % for rain and if they were also in the rough that % would be added to modifier then modifier is added to distance for the correct end result

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