Re: String vs. Collection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"boaz" <nospam@xxxxxxxxx> wrote in message
news:eShLbw5eGHA.5088@xxxxxxxxxxxxxxxxxxxxxxx
I see... so basically, what you are saying is that depending on what
database I am connecting, the program will "switch" Class to match the
database.



Yes. It is called polymorphism.

(Or at least classic VB's version of it.)

<g>



"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message
news:Ps6dnW6zHpwiofPZRVn-tw@xxxxxxxxxxxxxxx

"boaz" <nospam@xxxxxxxxx> wrote in message
news:uM49CC4eGHA.3336@xxxxxxxxxxxxxxxxxxxxxxx
I don't see how "Implements" can work...


"Ralph" <nt_consulting64@xxxxxxxxx> wrote in message
news:m6udnS4gadCOmfPZRVn-iA@xxxxxxxxxxxxxxx

"boaz" <nospam@xxxxxxxxx> wrote in message
news:eGEZfr2eGHA.1856@xxxxxxxxxxxxxxxxxxxxxxx
I can see why you might want to avoid classes, but I still
think leavine the data in the recordset may be a better
option for you.

Another problem of mine is that the same program needs to be run
against
different databases. Sometimes it is connected to Access.
Sometimes
it
is
connected to SQL Server. Sometimes it is connected to Oracle.
Sometimes
it
is DB2. and some others.

The data types in these database are all different from each other.
Sometimes they have something called a "Money" data type that
crashes
the
recordset.

So... no more recordset... use all string...



My I suggest, in the true tradition of the "Graduate", One Word -
"Implements". <g>

Checkout Facade, Bridge, and Adaptor patterns.

-ralph



Well for starters, from a 100k view...

' CProjConfig
' a class that just inits itself on startup, reading ini, reg,
' command line, etc with project specific information
' database location, security, etc.

' IDB
' a generic connection class
Public Function adoConn() As ADO.Connection
Public Sub Init(ByRef cls As CProjConfig)
'
' Class COracle
Implements IDB
Private Function IDB_adoConn As ADO.Connection ...
Private Sub IDB_Init(ByRef cls As CProjConfig)

' Class CMSAccess
Implements IDB
Private Function IDB_adoConn As ADO.Connection ...
Private Sub IDB_Init(ByRef cls As CProjConfig)

' Class CSQLSvr
Implements IDB
Private Function IDB_adoConn As ADO.Connection ...
Private Sub IDB_Init(ByRef cls As CProjConfig)

Dim gcConfig As CProjConfig
Dim gcDB As IDB
Sub Main()
Set gcConfig = New CProjConfig: ' gcConfig.Init()
Select Case gcConfig.Database
Case "Oracle"
Set gcDB = New COracle: gcDB.Init(gcConfig)
Case "Access"
Set gcDB = New CMSAccess : gcDB.Init(gcConfig)
Case "SQL"
Set gcDB = New CSQLSvr: gcDB.Init(gcConfig)
End Select

' for the rest of the project whenever an ADO Connection is
' needed...
gcDB.adoConnection
...
End Sub

If you want you can easily replace the Select Case with a conditional
compile for specific releases. Other objects would fit this pattern as
well..

ICustomer, CCustomerOra, CCustomerSQL, CCustomerMSA
Private cCust As ICustomer
#If MYDB = "Oracle" Then
Set cCust = New CCustomerOra
...

Handling different data types such as "Money" and "Currency" would be
managed in a similar fashion - create some kind of "CDollar" class and
let
it access either one as needed.

Hey, but don't get me wrong, if you find it easier to manipulate
strings,
then so be it.







.



Relevant Pages

  • Re: String vs. Collection
    ... database I am connecting, the program will "switch" Class to match the ... Public Sub Init(ByRef cls As CProjConfig) ... Private Function IDB_adoConn As ADO.Connection ... ... Private Sub IDB_Init ...
    (microsoft.public.vb.enterprise)
  • Re: String vs. Collection
    ... Public Sub Init(ByRef cls As CProjConfig) ... Private Function IDB_adoConn As ADO.Connection ... ... Private Sub IDB_Init ... Set gcDB = New CMSAccess: ...
    (microsoft.public.vb.enterprise)
  • Re: Re: Please help, IE window DOM (by focus) automation error
    ... I want to ask u if this code will work for Firefox browser document object ... Private WithEvents IE As InternetExplorer ... Private Sub IE_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As ... ' Ref MS Internet Controls .... ...
    (microsoft.public.vb.winapi)
  • Re: An event raise twice when click the button.
    ... Private Sub AddinInstance_OnAddInsUpdateAs Variant) ... Private Sub AddinInstance_OnBeginShutdownAs Variant) ... Private WithEvents m_objInsp As Outlook.Inspector ... Dim tempMailItem As Outlook.MailItem ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: An event raise twice when click the button.
    ... Private Sub AddinInstance_OnAddInsUpdateAs Variant) ... Private Sub AddinInstance_OnBeginShutdownAs Variant) ... Private WithEvents m_objInsp As Outlook.Inspector ... Dim tempMailItem As Outlook.MailItem ...
    (microsoft.public.office.developer.outlook.vba)