Program Help

michaeldalton7

New member
Joined
Sep 28, 2006
Messages
1
Location
SW New Mexico
Programming Experience
Beginner
I have had a the same lousy teacher my first and now second year of Visual Basic. His lectures consists of the book's companion site slide show, which is not detailed enough to help beginners. Some of my buddies actually are going to a math teacher who has visual basic experience for study sessions, and he at times doesn't understand what we are doing.

Anyways to whom ever can give me help because I've looked for every resources on the internet and this is my last resort:

Problem: BANK ACCOUNT- Wite a program that simulates a bank account. A text box allows deposits (a positive number) to be made into the account and whithdrawals (a negative number) to be made. The state of the account is continually displayed and, if the account goes into the red (negative balance), a suitable message is displayed.Create a class named ACCOUNT to represent bank accounts. It has methods DEPOSIT and WITHDRAW, and property CURRENT BALANCE.

In this chapter we barely go introduced to private properties and methods. I've spent 7 hours straight on trying to create this program. It's so frustrating because I love programming, but my instructor has made this so hard on us to be successful.

I'm really green to this, so please be very explicit and if possible a lot of comments so I can see what's going on in each step.

Thank you
 
well creating classes is rather simple to explain:
all you need is to declare a class as a class:
VB.NET:
Class MyClass

End Class
it's like making a sub or function really, you can specify a scope: Private Protected, Friend, Public most classes i make have a scope of Friend:
VB.NET:
Friend Class MyClass

End Class
now all you need to do is add methods (subs and functions) which you should already be familiar with:
VB.NET:
Friend Class MyClass

  Friend Sub DoSomething
    'Code that does something
  End Sub

End Class
that's where your Withdrawls and Deposits come in, they'd be subs

now all you need to know is properties, which are simple, but can seem kind of complex:

for a class to have a property you'll need a variable to store the information and a way to access it, the reason we use properties (the method of retrieving and storing the value to the variable) is so we can valid date the data before storing the value to the variable here's a property's outline:
VB.NET:
Property MyProperty As String
  Get

  End Get
  Set (Value As String)

  End Set
End Property
the property can have a specified scope as well (just like classes, subs, functions and variables), the Get branch is for retreiving the value, the Set branch is for validating and setting the var of the property. also the example above is for string, but change the word "As String" to "As Integer" or "As Decimal" or "As Boolean" or to whatever type of variable needed

so here's an example of a simple assignment:
VB.NET:
Private _MyProperty As String

Friend Property MyProperty As String
  Get
    Return _MyProperty
  End Get
  Set (value As String)
    _MyProperty = value
  End Set
End Property
so as a whole you've got:
VB.NET:
Friend Class MyClass
  Private _MyProperty As String

  Friend Property MyProperty As String
    Get
      Return _MyProperty
    End Property
    Set (value As String)
      _MyProperty = value
    End Set
  End Property

  Friend Sub DoSomething()
    'Do something, you can pass args to the sub too and you can also interact with the _MyProperty variable here too, you will have to with the Deposits and Withdrawls
  End Sub
End Class

i hope all that helps a little bit, i could get into more detail, but my fingers got tired and there are numerous examples of this via a simple google search
 
Back
Top