Results 1 to 7 of 7

Thread: Adding Up Numbs

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    17

    Adding Up Numbs

    Im developing a Text based Rpg on VB and Im fair new at it but I need help with a code i need and I dont know how to code it.
    Race Selector
    Code:
        Private Sub Button5_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            HealthStat.Text = 15
        End Sub
    Easily to see this code will add the number 15 in my Health Starter Stat but I need help with the second button which its my Class selector
    Class Selector
    Code:
        Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
            HealthStat.Text = 
        End Sub
    At HealthStat.Text = I need a code that will add like a number to the current 15 in my Health Starter Stat textbox. so can anyone help me? This might be a easy code for anyone out there but i couldnt think on 1

  2. #2

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    17

    Re: Adding Up Numbs

    Alright ty

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding Up Numbs

    First up, as your health value is an integer, I would suggest that you declare a member variable of type Integer for it:
    vb.net Code:
    1. Private health As Integer
    Whenever you want to change the health value, you use that Integer:
    vb.net Code:
    1. 'Set the health to 15.
    2. Me.health = 15
    3.  
    4. 'Add 10 to the current health.
    5. Me.health = Me.health + 10
    6.  
    7. 'Add another 10 to the current health.
    8. Me.health += 10
    Whenever you want to display the current health, you display the value of that variable, converting it to a String first:
    vb.net Code:
    1. HealthStat.Text = Me.health.ToString()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    17

    Re: Adding Up Numbs

    Alright, ty but I am confused on were to put the codes in and at?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding Up Numbs

    You put the code wherever you need to execute it. The code doesn't dictate where it goes. The required functionality does. I've shown you how to set the health. Where do you need to set the health? That's where you put that code. I've shown you how to add to the health. Where do you need to add to the health? That's where you put that code. I've shown you how to display the health. Where do you need to display the health? That's where you put that code. Obviously you'll need to display the health immediately after you change the health. As for the declaration of the member variable, there's only one place that that can go because there's only one place that you can declare members: inside the type definition but outside any member definition, which basically means inside the form but outside any methods.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2010
    Posts
    17

    Re: Adding Up Numbs

    Ok, ty I think I got It

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