Solved

Bind controls to a class's property in VB6

Posted on 1998-11-04
9
427 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

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

Author Comment

by:Jagar
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

by:Jagar
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:tcurtin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Just press F1 in VB6. Search for "Creating the MyDataSource Class"
and you will find this topic.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now