Solved

Bind controls to a class's property in VB6

Posted on 1998-11-04
9
457 Views
Last Modified: 2013-11-25
Hello I have a class that is bound to a recordset.  I also have a form with several controls on it.  These controls are currently bound to the recordset.  But what I want them to be bound to is the class's property, so that it calls the property Get and Let procedure when it needs or saves data.

The reason for this is that the database has some user-unfriendly values such as Y or N for True and False so I want to put a checkbox on the form and have the value property of the checkbox bound to the class's property get and let procedure so that I can return True or False and not Y or N.

I will be greatly appreciative of any responses.
0
Comment
Question by:Jagar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:tcurtin
ID: 1443070
use the property get to return 0 or -1 as boolean for false or true respectively.
0
 
LVL 2

Author Comment

by:Jagar
ID: 1443071
It never calls the property get it goes directly to the database.  That's why I need to know how to set up the class as a data source correctly because obviously I'm doing something wrong.
0
 
LVL 3

Expert Comment

by:tcurtin
ID: 1443072
Use a property in the class to connect to the recordset. Open a connection in the class's initialize event:
  in the client:
dim x as Class1
Private sub command1_click()
   set x = new class1
   x.customername = txtCustomername.text
   'repeat property setting for all fields
end sub
 Property Let CustomerName(strCustomer as string)
       con.execute("insert into " _                            &        "customers('Customer_name') " _
       & "values (" & strcustomer & ")"
end property

I hope this is closer. I'm using ADO. A super book is by Sams. Visual Basic 6. Database How to. It focuses on ADO and Crystal reports..... Written by The Waite's Group.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Jagar
ID: 1443073
There is some way to automatically bind the controls to the class.  So that you do not have to explicitely set the class's propertys to the text values of the controls.
0
 
LVL 3

Expert Comment

by:tcurtin
ID: 1443074
Use VB6's data environment to establish a connection to the data source. The Data Member can be a command(stored Procedure,SQL string). Then map the 'DataMember' property to the data environment(command), then the data field property to the database field.
0
 
LVL 2

Author Comment

by:Jagar
ID: 1443075
Please provide an example of what you are doing I half understand it, because I have half of it setup, but I don't know what I'm missing.
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 150 total points
ID: 1443076
In VB6 this is easy. The following text is directly from the VB help. You can find it yourself. In VB 5 it is not possible.

Creating the MyDataSource Class


In the previous topic, we created a class that implements an OLE DB Simple Provider. In this step we'll create another class that will provide data from the MyOSPObject class to other objects.

Note   This topic is part of a series that walks you through creating sample data source components. It begins with the topic Creating Data Sources.

To create the MyDataSource class

Select the MyDataComponent project in the Project Explorer.


Select Add Class Module from the Project menu, then choose Class Module from the Add Class Module dialog box.


Select the Properties window and set the following properties for the new class module:Property Setting
(Name) MyDataSource
DataSourceBehavior 2-vbOLEDBProvider


In the Object box, select Class. In the Procedure box, select the GetDataMember event. Add the following code to the Class_GetDataMember event procedure:
Private Sub Class_GetDataMember(DataMember As String, Data As Object)
   ' Declare an instance of the MyOSPObject class
   Dim MyOSP As New MyOSPObject

   ' Make sure the DataMember is valid
   If DataMember = "" Then
       Err.Raise (E_FAIL)
   End If

   ' Set the FilePath property
   MyOSP.FilePath = DataMember

   ' Call the LoadData method to populate the class
   MyOSP.LoadData

   ' Set MyDataSource's data to MyOSPObject's data
   Set Data = MyOSP
End Sub

Choose Save Project Group from the File menu to save your changes. When prompted for a file name for the Class module, choose the default (MyDataSource.cls).
As you may have noticed, this class is much simpler than the MyOSPObject class. In fact, if you go back and compare it with the GetDataMember event, you'll see that it's doing essentially the same thing. The main difference here is that we're using a class that we created rather than the pre-existing ADODB class.

In the next step, we'll convert the form that we created earlier to use our new data source object, and we'll test it to see the results.

Step by Step
This topic is part of a series that walks you through creating sample ActiveX data sources.

To See
Go to the next step Testing the MyData Component
Start from the beginning Creating Data Sources

0
 
LVL 2

Author Comment

by:Jagar
ID: 1443077
That looks like what I could be looking for, but could you tell me where in the Help files you found this, so that I can review the whole thing (about the previous chapter and all)  I some how missed this when I was looking through the help files.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1443078
Just press F1 in VB6. Search for "Creating the MyDataSource Class"
and you will find this topic.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question