Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,569 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




classes and modules

 
Reply to this topicStart new topic

classes and modules, to many arguments?

penguindesktop
16 May, 2008 - 05:09 AM
Post #1

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 13


My Contributions
Greetings, I have a simple question/request for clarification on classes and modules. My very simple grass roots understanding is that classes do stuff and modules call classes and pass things to classes. In this exercise I have been tasked with creating an Account class that holds and balance, which comes from a module that inputs the initial balance into the account. I have finally gotten all the error's to go away except one. When I try to pass an initial balance from the module I get an error that states "Too many arguments to 'Public Sub New()'" Can anyone shed some light on what I am doing wrong. I think everything is in order, but obviously I'm missing something. Thanks.


CODE

Module AccountTest

   Sub Main()


      Dim Account1 As New Account(10) 'this should give Account1 a balance of 10??
      Dim account2 As New Account(20) 'this should give Account2 a balance of 20??

      Console.WriteLine("Account1 balance = " & Account1.Balance)
      Console.WriteLine("Account2 balacne = " & account2.Balance)


   End Sub

End Module


My Account class

CODE


Public Class Account

   ' make a private variable to hold the value of the balance
   Private Balancevalue As Integer

   Public Sub New_Account(ByVal initialbalance As Integer) 'this value will be given when this class is called

      'i.e. "Dim Account As New Account(50) 50 would be the initialbalance variable

      If initialbalance > 0 Then 'if the ammount is greater than 0

         Balance = initialbalance

      End If

   End Sub

   Public Sub debit(ByVal subtract As Integer)

      If subtract <= Balance Then ' if the debit is less than the balance

         Balance = Balance - subtract 'the debit amount

      End If
   End Sub

   Public Sub credit(ByVal add As Integer)

      Balancevalue = Balance + add 'add this amount to the existing balance

   End Sub

   Public Property Balance() As Integer
      Get 'returns the account balance

         Return Balancevalue

      End Get

      Set(ByVal value As Integer) 'sets the balance

         Balancevalue = value

      End Set

   End Property

End Class

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:56PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month