VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,765 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
If I create my own API that can be used like method().method() ... like below, please let me know how to code using class and namespace.
Excel.Worksheets(sheetName).range("$A$27:$G100").Value
Namespace Excel
Class Worksheets
????
Class Range
????
End Class
End Class
End Namespace
Hello @Soyoung Lee
Looks like you can use the builder pattern which is a creational design pattern and can be used to create complex objects step by step as seen in the following Microsoft TechNet article code sample which has several more examples to get ideas from.
Public Class Burger
Public ReadOnly Property Size() As Integer
Public ReadOnly Property Cheese() As Boolean
Public ReadOnly Property Pepperoni() As Boolean
Public ReadOnly Property Lettuce() As Boolean
Public ReadOnly Property Tomato() As Boolean
Public Sub New(builder As Classes.BurgerBuilder)
Size = builder.Size
Cheese = builder.Cheese
Pepperoni = builder.Pepperoni
Lettuce = builder.Lettuce
Tomato = builder.Tomato
End Sub
End Class
Public Class BurgerBuilder
Public ReadOnly Property Size() As Integer
Private mCheese As Boolean
Public Property Cheese() As Boolean
Get
Return mCheese
End Get
Private Set(ByVal value As Boolean)
mCheese = value
End Set
End Property
Private mPepperoni As Boolean
Public Property Pepperoni() As Boolean
Get
Return mPepperoni
End Get
Private Set(ByVal value As Boolean)
mPepperoni = value
End Set
End Property
Private mLettuce As Boolean
Public Property Lettuce() As Boolean
Get
Return mLettuce
End Get
Private Set(ByVal value As Boolean)
mLettuce = value
End Set
End Property
Private mTomato As Boolean
Public Property Tomato() As Boolean
Get
Return mTomato
End Get
Private Set(ByVal value As Boolean)
mTomato = value
End Set
End Property
Public Sub New(ByVal size As Integer)
Me.Size = size
End Sub
Public Function AddPepperoni() As BurgerBuilder
Pepperoni = True
Return Me
End Function
Public Function AddLettuce() As BurgerBuilder
Lettuce = True
Return Me
End Function
Public Function AddCheese() As BurgerBuilder
Cheese = True
Return Me
End Function
Public Function AddTomato() As BurgerBuilder
Tomato = True
Return Me
End Function
Public Function Build() As Burger
Return New Burger(Me)
End Function
End Class
Dim burger = New Classes.BurgerBuilder(14).
AddPepperoni().
AddLettuce().
AddTomato().
Build()
In the above we can also specify the type
Dim burger As Burger = New Classes.BurgerBuilder(14).
AddPepperoni().
AddLettuce().
AddTomato().
Build()
Try something like this:
Module Excel
Public ReadOnly Worksheets As New AllWorksheets
Class AllWorksheets
Default Public ReadOnly Property Item(name As String) As Worksheet
Get
Return New Worksheet
End Get
End Property
End Class
Class Worksheet
Public ReadOnly Property Range(address As String) As Range
Get
Return New Range
End Get
End Property
End Class
Class Range
Public Property Value As String ' or 'As Object'
Get
Return "some text"
End Get
Set(value As String)
End Set
End Property
End Class
End Module