Programming with classes

L

leaderionel

Hi,
I'd like to program with classes in Access.

1) I have a front-end (mdb), with a form which has a button and a text
box
2) Here I have a reference to a library (mda) with a class (Class1)
and a module (Module1) with a function.

The Class1 class is:

Option Compare Database
Option Explicit

Private mAstring As String

Public Property Get Astring() As String
Astring = mAstring
End Property
Public Property Let Astring(value As String)
mAstring = UCase(mAstring)
End Property


The function is:

Public Function NewClass() As Class1
Set NewClass = New Class1
End Function

3) Now, let's go back to the front-end, and let's write something with
lower cases.
4) Click-ing the button, I'd like to use the class to have back the
string in uppercase.

How to do that?

Thank you,
Ionel
 
T

Tom van Stiphout

On Mon, 9 Jun 2008 21:05:44 -0700 (PDT), (e-mail address removed) wrote:

It's probably a contrived example because you could simply write:
Msgbox UCase$(myTextbox)
but that aside.

Write in the click event of that button:
dim x as Class1
set x=new Class1
x.Astring myTextbox
MsgBox x.Astring

But note, your class has an important error. Make this change:
Public Property Let Astring(value As String)
mAstring = UCase(value)
End Property

-Tom.
 
L

leaderionel

On Mon, 9 Jun 2008 21:05:44 -0700 (PDT), (e-mail address removed) wrote:

It's probably a contrived example because you could simply write:
Msgbox UCase$(myTextbox)
but that aside.

Write in the click event of that button:
dim x as Class1
set x=new Class1
x.Astring myTextbox
MsgBox x.Astring

But note, your class has an important error. Make this change:
Public Property Let Astring(value As String)
    mAstring = UCase(value)
End Property

-Tom.














- Show quoted text -

Hi Tom,
You are right:
1) I can use Msgbox UCase$(myTextbox)
2) with mAstring = UCase(value)

Your example code works well when the form and the class are in the
same database.
Me, i'd like to keep the class in a class library.
This library (mda) keeps the class, and also a function:

I need to use somehow this function (or maybe another technique)

Generally speaking, how to program VBA, keeping the classes in a class
library (mda) and the forms in a mdb?

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top