Fixing logic
Fixing logic
Fixing logic
Fixing logic
Fixing logic
Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic
Fixing logic Fixing logic
Fixing logic
Go Back  Xtreme Visual Basic Talk > > > Fixing logic


Reply
 
Thread Tools Display Modes
  #1  
Old 04-10-2012, 10:29 AM
Warfarin Warfarin is offline
Newcomer
 
Join Date: Apr 2012
Location: Utah
Posts: 3
Unhappy Fixing logic


New to board and new to Visual Basic. Got assigned to teach this on High School level. Experience has been in C and C++

I have a student writing a game using VB2010 express. it is a football game, really simple. Problem is when the player goes over 10 yards it will say something like 3 down and -4 yards to go. Then on next play will reset to first and 10. here is the code he has. He has a picture of the quarterback that you click to start a passing play. We have not started on running plays etc until this problem is fixed. Thanks for any help you can offer. Remember this is a beginning HS programming class.
Code:
Public Class Form1 Dim yardstofirst As Integer = 10 Dim down As Integer = 1 Dim play As Integer Dim yardsgained As Integer Private Sub pboxpass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pboxpass.Click Randomize() play = Int(9 * Rnd()) + 1 'play lblplay.Text = play & " Yard Pass" yardsgained = yardsgained + play If yardstofirst <= 0 Then yardstofirst = 10 down = 1 End If If yardstofirst = yardstofirst - play Then down += 1 End If lbldown.Text = down & " and " & yardstofirst End Sub End Class

Last edited by Gruff; 04-10-2012 at 12:49 PM.
Reply With Quote
  #2  
Old 04-10-2012, 10:33 AM
Warfarin Warfarin is offline
Newcomer
 
Join Date: Apr 2012
Location: Utah
Posts: 3
Default

ok ingnore code in previous post he changed it and didn't tell me. Here is the code.

Code:
'Justin Dory '3/22/2012 Public Class Form1 Dim yardstofirst As Integer = 10 Dim down As Integer = 1 Dim play As Integer Dim yardsgained As Integer Private Sub pboxpass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pboxpass.Click Randomize() play = Int(9 * Rnd()) + 1 'play lblplay.Text = play & " Yard Pass" yardsgained = yardsgained + play If yardstofirst <= 0 Then yardstofirst = 10 down = 1 Else yardstofirst = yardstofirst - play down += 1 End If lbldown.Text = down & " and " & yardstofirst End Sub End Class

Last edited by Gruff; 04-10-2012 at 12:52 PM.
Reply With Quote
  #3  
Old 04-11-2012, 04:31 AM
DrPunk's Avatar
DrPunkFixing logic DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

It's the order that it's doing stuff that's the problem.

You want to take the play away from yards to first before checking it, not after.
Code:
        yardstofirst = yardstofirst - play

        If yardstofirst <= 0 Then
            yardstofirst = 10
            down = 1
        Else            
            down += 1
        End If
__________________
There are no computers in heaven!
Reply With Quote
  #4  
Old 04-11-2012, 09:00 AM
passel's Avatar
passelFixing logic passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

And that would be true regardless of the language, vb, C, C++, etc..
Logic is logic.
How much C, C++ experience to you have?
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 04-12-2012, 10:31 AM
Warfarin Warfarin is offline
Newcomer
 
Join Date: Apr 2012
Location: Utah
Posts: 3
Default

DUH thank you DrPunk. My experience is very limited in all programming aspects and sometimes I just miss little things like this. I have caught errors like this before but for some reason just couldn't see it here
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Fixing logic
Fixing logic
Fixing logic Fixing logic
Fixing logic
Fixing logic
Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic Fixing logic
Fixing logic
Fixing logic
 
Fixing logic
Fixing logic
 
-->