![]() |
User Defined Type
It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. Yes, they are quite different. In VBA, a class module contains one and only one class, whose name is the name of the module. For your code, first create a new class module, F4 to bring up the Properties window, and give it a name of LedgerTransaction. In that module, put the following code: Public Items As Collection Public Index As Long Private Sub Class_Initialize() Set Items = New Collection End Sub Next, create a second class module, name it BankAccountLedger, and place the following code in that module: Public Name As String Public Transactions As Collection Public LedgerRange As Range Private Sub Class_Initialize() Set Transactions = New Collection End Sub Then, in your initialization code in a regular code module, instantiate the classes with code like Dim LT As LedgerTransaction Dim BAL As BankAccountLedger ' other code Set LT = New LedgerTransaction Set BAL = New BankAccountLedger -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... I dont have much programming experience, but the little that i do know is from visual basic.net. It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. So what i need to know is how to make a class or an object that i can manipulate in my code I wish to make a Class that Will Be Called LedgerTransaction this class will have two member variables 1) Items - which will have a collection of range objects that contain the range of the particular transaction item 2) Index - which will be the index of the transaction I will also need a class called BankAccountLedger Wich will have three Member Variables 1) Name 2) Transactions - Collection of Transactions 3) Range the range of the ledger now this is a very elementry process in vb.net and i am sure that it is in vba to. however i am missing something i tried a classs module and a user defined types and received several different error messages. If anyone could please help me understand this or send me to a good tutorial i would be very grateful WStoreyII |
User Defined Type
Chip,
Thanks for the quick and extremely helpful information. I had one problem though when i tried to use a sub from the class i got an error Dim ptyTransactions As Collection Dim ptyRange As Range Function GetRange(Sheet As String) As Range End Function Function Transaction(Index As Integer) End Function Public Sub Add(HasItems As Boolean, Count As Integer) MsgBox (Count) End Sub Private Sub Item(Count As Integer) End Sub when i tried to call the the Sub Add Button from this class like this Private Sub btnNewTransaction_Click() Dim I As Class1 Set I = New Class1 I.Add(True,10) End Sub i got the following error: "Compile Error: Syntax error" but i dont understand what is wrong with the syntax "Chip Pearson" wrote: It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. Yes, they are quite different. In VBA, a class module contains one and only one class, whose name is the name of the module. For your code, first create a new class module, F4 to bring up the Properties window, and give it a name of LedgerTransaction. In that module, put the following code: Public Items As Collection Public Index As Long Private Sub Class_Initialize() Set Items = New Collection End Sub Next, create a second class module, name it BankAccountLedger, and place the following code in that module: Public Name As String Public Transactions As Collection Public LedgerRange As Range Private Sub Class_Initialize() Set Transactions = New Collection End Sub Then, in your initialization code in a regular code module, instantiate the classes with code like Dim LT As LedgerTransaction Dim BAL As BankAccountLedger ' other code Set LT = New LedgerTransaction Set BAL = New BankAccountLedger -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... I dont have much programming experience, but the little that i do know is from visual basic.net. It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. So what i need to know is how to make a class or an object that i can manipulate in my code I wish to make a Class that Will Be Called LedgerTransaction this class will have two member variables 1) Items - which will have a collection of range objects that contain the range of the particular transaction item 2) Index - which will be the index of the transaction I will also need a class called BankAccountLedger Wich will have three Member Variables 1) Name 2) Transactions - Collection of Transactions 3) Range the range of the ledger now this is a very elementry process in vb.net and i am sure that it is in vba to. however i am missing something i tried a classs module and a user defined types and received several different error messages. If anyone could please help me understand this or send me to a good tutorial i would be very grateful WStoreyII |
User Defined Type
In VBA, you don't enclose argument to Sub procedures in
parentheses. Only arguments to Function procedures are enclosed in parens. Change I.Add(True,10) to I.Add True,10 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... Chip, Thanks for the quick and extremely helpful information. I had one problem though when i tried to use a sub from the class i got an error Dim ptyTransactions As Collection Dim ptyRange As Range Function GetRange(Sheet As String) As Range End Function Function Transaction(Index As Integer) End Function Public Sub Add(HasItems As Boolean, Count As Integer) MsgBox (Count) End Sub Private Sub Item(Count As Integer) End Sub when i tried to call the the Sub Add Button from this class like this Private Sub btnNewTransaction_Click() Dim I As Class1 Set I = New Class1 I.Add(True,10) End Sub i got the following error: "Compile Error: Syntax error" but i dont understand what is wrong with the syntax "Chip Pearson" wrote: It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. Yes, they are quite different. In VBA, a class module contains one and only one class, whose name is the name of the module. For your code, first create a new class module, F4 to bring up the Properties window, and give it a name of LedgerTransaction. In that module, put the following code: Public Items As Collection Public Index As Long Private Sub Class_Initialize() Set Items = New Collection End Sub Next, create a second class module, name it BankAccountLedger, and place the following code in that module: Public Name As String Public Transactions As Collection Public LedgerRange As Range Private Sub Class_Initialize() Set Transactions = New Collection End Sub Then, in your initialization code in a regular code module, instantiate the classes with code like Dim LT As LedgerTransaction Dim BAL As BankAccountLedger ' other code Set LT = New LedgerTransaction Set BAL = New BankAccountLedger -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... I dont have much programming experience, but the little that i do know is from visual basic.net. It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. So what i need to know is how to make a class or an object that i can manipulate in my code I wish to make a Class that Will Be Called LedgerTransaction this class will have two member variables 1) Items - which will have a collection of range objects that contain the range of the particular transaction item 2) Index - which will be the index of the transaction I will also need a class called BankAccountLedger Wich will have three Member Variables 1) Name 2) Transactions - Collection of Transactions 3) Range the range of the ledger now this is a very elementry process in vb.net and i am sure that it is in vba to. however i am missing something i tried a classs module and a user defined types and received several different error messages. If anyone could please help me understand this or send me to a good tutorial i would be very grateful WStoreyII |
User Defined Type
Chip,
Properties are really different to how do you use those? Just out of curiosity do Mvp's Get paid to answers Posts ? Becuase any newsgroup that i post a question in, i always get reply from mvps and really quick as if they were sitting there waiting for the question? WStoreyII Thanks Alot "Chip Pearson" wrote: In VBA, you don't enclose argument to Sub procedures in parentheses. Only arguments to Function procedures are enclosed in parens. Change I.Add(True,10) to I.Add True,10 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... Chip, Thanks for the quick and extremely helpful information. I had one problem though when i tried to use a sub from the class i got an error Dim ptyTransactions As Collection Dim ptyRange As Range Function GetRange(Sheet As String) As Range End Function Function Transaction(Index As Integer) End Function Public Sub Add(HasItems As Boolean, Count As Integer) MsgBox (Count) End Sub Private Sub Item(Count As Integer) End Sub when i tried to call the the Sub Add Button from this class like this Private Sub btnNewTransaction_Click() Dim I As Class1 Set I = New Class1 I.Add(True,10) End Sub i got the following error: "Compile Error: Syntax error" but i dont understand what is wrong with the syntax "Chip Pearson" wrote: It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. Yes, they are quite different. In VBA, a class module contains one and only one class, whose name is the name of the module. For your code, first create a new class module, F4 to bring up the Properties window, and give it a name of LedgerTransaction. In that module, put the following code: Public Items As Collection Public Index As Long Private Sub Class_Initialize() Set Items = New Collection End Sub Next, create a second class module, name it BankAccountLedger, and place the following code in that module: Public Name As String Public Transactions As Collection Public LedgerRange As Range Private Sub Class_Initialize() Set Transactions = New Collection End Sub Then, in your initialization code in a regular code module, instantiate the classes with code like Dim LT As LedgerTransaction Dim BAL As BankAccountLedger ' other code Set LT = New LedgerTransaction Set BAL = New BankAccountLedger -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... I dont have much programming experience, but the little that i do know is from visual basic.net. It appears though that programming with (vba) for excel 2000 and vb.net are two completely different worlds. So what i need to know is how to make a class or an object that i can manipulate in my code I wish to make a Class that Will Be Called LedgerTransaction this class will have two member variables 1) Items - which will have a collection of range objects that contain the range of the particular transaction item 2) Index - which will be the index of the transaction I will also need a class called BankAccountLedger Wich will have three Member Variables 1) Name 2) Transactions - Collection of Transactions 3) Range the range of the ledger now this is a very elementry process in vb.net and i am sure that it is in vba to. however i am missing something i tried a classs module and a user defined types and received several different error messages. If anyone could please help me understand this or send me to a good tutorial i would be very grateful WStoreyII |
User Defined Type
For properties, you use Property Get, Property Let, and Property
Set. E.g., Private pPropName As Long Public Property Get PropName() As Long PropName = pPropName End Property Public Property Let PropName(Value As Long) pPropName = Value End Property Property Set is used for object type properties. Just out of curiosity do Mvp's Get paid to answers Posts ? Nope, we're all volunteers, end users like yourself. We just like helping others by answering posts. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... Chip, Properties are really different to how do you use those? Just out of curiosity do Mvp's Get paid to answers Posts ? Becuase any newsgroup that i post a question in, i always get reply from mvps and really quick as if they were sitting there waiting for the question? WStoreyII Thanks Alot "Chip Pearson" wrote: In VBA, you don't enclose argument to Sub procedures in parentheses. Only arguments to Function procedures are enclosed in parens. Change I.Add(True,10) to I.Add True,10 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com |
User Defined Type
Chip,
You guys sure do a good job, quick and concise. I try to help where i can but most of the time i am still the one asking the questions. Keep Up The good work "Chip Pearson" wrote: For properties, you use Property Get, Property Let, and Property Set. E.g., Private pPropName As Long Public Property Get PropName() As Long PropName = pPropName End Property Public Property Let PropName(Value As Long) pPropName = Value End Property Property Set is used for object type properties. Just out of curiosity do Mvp's Get paid to answers Posts ? Nope, we're all volunteers, end users like yourself. We just like helping others by answering posts. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "WStoreyII" wrote in message ... Chip, Properties are really different to how do you use those? Just out of curiosity do Mvp's Get paid to answers Posts ? Becuase any newsgroup that i post a question in, i always get reply from mvps and really quick as if they were sitting there waiting for the question? WStoreyII Thanks Alot "Chip Pearson" wrote: In VBA, you don't enclose argument to Sub procedures in parentheses. Only arguments to Function procedures are enclosed in parens. Change I.Add(True,10) to I.Add True,10 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com |
All times are GMT +1. The time now is 07:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com