Solved

VB6 - Creating ActiveX .dll file

Posted on 2006-06-09
13
572 Views
Last Modified: 2012-06-27
Hello All;

  I am a Delphi programmer, and have just installed VB6 Pro. To create ActiveX .dll files.
(I heard that VB was better at this then Delphi was)

  OK, I am learning how to build an ASP script, and in the information that i am reading.
It states that I need to Compile the source-code that I have just written into an ActiveX DLL.

I started up [VB6] and started a new [ActiveX DLL] Project.
(Do not know if this part is right or not?)
In the Blank-Form, I pasted the code that I wrote.
I did a [Debug - Step Into] and it stopped on the following Line

Public Sub Init(dcnDB As Variant, _

With Error:
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Ambiguous name detected: Init
---------------------------
OK   Help  
---------------------------

------------------------------------------------
Can someone please explain to me exactly how to Compile the ASP CLASS into a DLL File?

Thank you for your time.

Carrzkiss (Using VB6 for about 5-minutes now, going to play around with it and see what I can knowledge myself with,
Who knows? Maybe I can find some more use besides just creating DLL files with it :)  )
0
Comment
Question by:Wayne Barron
  • 8
  • 5
13 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16875006
What is your entire code?

Ambigous name detected means that you probrably have 2 variables the same or a procedure that is exactly the same name.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16875048
Hello [egl1044];
(I believe everything is done properly, I followed the instructions from the book
Active Server Pages Bible -  Creating a Discussion Forum)

 
Public Sub Init(dcnDB As Variant, Optional lngID As Long = -1)

    Set m_dcnDB = dcnDB
    m_blnIsNew = (lngID = -1)

    If Not m_blnIsNew Then
       Set m_rsData = m_dcnDB.Execute("SELECT * FROM tblGroups " & _
       "Where GroupID= " & lngID)
       FillObject Me, m_rsData
       m_rsData.Close
     End If
End Sub

Public Sub Save()
'
' This method puts the objects data back into
' The database. This method could use the INSERT
' Statement or a stored procedure, if desired.

Dim objField As ADODB.Field
Set m_rsData = New ADODB.RecordSet
If m_blnIsNew Then
   m_rsData.Open "SELECT * FROM tblGroups" _
   m_dcnDB, _
     adOpenDynamic, _
     adLockOptimistic
     m_rsData.AddNew
Else
   m_rsData.Open "SELECT * FROM tblGroups " _
   "WHERE GroupID = " & m_lngGroupID, _
   m_dcnDB, _
   adOpenDynamic, _
   adLockPressimistic
End If

SaveObject Me, m_rsData

m_rsData.Update
'
' Calling FillObject here allows the
' Unique ID to be picked up in case of
' an addition
'
FillObject Me, m_rsData
m_rsData.Close

End Sub


Public Sub saveObject(objInput As Object, rsInput As ADODB.RecordSet)
       Dim objField As ADODB.Field
       Dim varResult As Variant

   For Each objField In rsInput.Fields
       If objField.Attributes And adFldUpdatable Then
       varResult = CallByName(objInput, objField.Name, VBGet)
   If TypeName(varResult) <> "String" Then
       rsInput(objField.Name) = varResult
   ElseIf varResult <> "" Then
       rsInput(objField.Name) = varResult
   Else
       rsInput(objField.Name) = ""
   End If
 End If
Next objField

End Sub

Public Sub FillObject(objInput As Object, _
   rsInput As ADODB.RecordSet)

   Dim objField As ADODB.Field
   For Each objField In rsInput.Fields
       If Not IsNull(rsInput(objField.Name)) Then
       CallByName objInput, objField.Name, _
         VbLet, rsInput(objField.Name)
      End If
   Next objField
End Sub


Public Sub Init(dcnDB As Variant, _
   Optional lngID As Long = -1, _
   Optional strUserName As string = "")

   Dim strSQL As String
   Set m_dcnDB = dcnDB
   
   m_blnIsNew = (lngID = -1) And (strUserName = "")
   
   If Not m_blnIsNew Then
       StrSQL = "SELECT * FROM tblMembers "
         If lngID <> -1 Then
             StrSQL & "WHERE MemberID = " & lngID
         Else StrSQL <> "" Then
             StrSQL = & "WHERE UserName = '" _
             & StrUserName & "'"
            End If
            Set m_rsData = m_dcnDB.Execute(StrSQL)
            If m_rsData.EOF Then
                Err.Raise vbObjectError + 1, "Member.Init", _
                    "User ID '" & strUserName & "' does not exist."
                  Exit Sub
         End If
             FillObject Me, m_rsData
             m_rsData.Close
      End If
End Sub

Public Sub Save()
   '
   ' This method puts the objects data back into the database.
   ' This method could use the INSERT statement or a stored procedure, if desired.
   '
   Dim objField As ADODB.Field
   
   If Not Valid() Then
      Err.Raise vbObjectError + 1, "Member.Save", _
           "Required fields were missing. Please review all fields again and resubmit."
        Exit Sub
   End If
   
   Set m_rsData = New ADODB.RecordSet
   If m_blnIsNew Then
      m_rsData.Open "SELECT * FROM tblMembers", _
            m_dcnDB, _
              adOpenDynamic, _
              adLockOptimistic
        m_rsData.AddNew
  Else
      m_rsData.Open       "SELECT * FROM tblMembers " _
        & "WHERE MemberID = " & m_lngMemberID, _
        m_dcnDB, _
        adOpenDymanic, _
        adlockPessimistic
  End If
 
      SaveObject Me, m_rsData
        
        m_rsData.Update
        '
        ' Calling FillObject here allows the
        ' Unique ID to be picked up in case of an addition
        '
        FillObject Me, m_rsData
        m_rsData.Close
        
  End Sub
 
  Private Function Valid()As Boolean
 
     Valid = True _
          And (m_strUserName <> "") -
            And (m_strFirstName <> "") _
            And (m_strLastName <> "") _
            And (m_strPassword <> "")
            
End Function      


   Public Property Get ReplyTo() As Message
   
     If RefreshObject(m_objMember, m_lngMember, m_lngReplyToId, "ReplyToID")
   Then
     
       Set m_objReplyTo = New Message
       m_objReplyTo.Init m_dcnDB, m_lngReplyToID
   End if
   
     Set ReplyTo = m_objReplyTo
      
   End Property
   
   Public Property Get Member() As Member
   
      If RefrehObject(m_objMember, m_lngMemberID, "MemberID")
      Then
           Set m_objMember = New Member
             m_objMember.Init m_dcnDB, m_lngMemberID
        End If
        Set Member = m_objMember
      
      End Property
      
      Public Property Get Group() As Group
      
         If RefreshObject(m_objGroup, m_lngGroupID, "GroupID")
            Set m_objGroup = New Group
              m_objGroup.Init m_dcnDB, m_lngGroupID
         End If
         Set Group = m_objGroup
        
      End Property
      
      Public Function RefrehObject(objInput As Object, _                                  
        lngID As Long, strProperty As String) As Boolean
        
        Dim blnTest As Boolean
        blntest = objInput Is Nothing
        If Not blntest Then
        blnTest = blnTest Or _
        (CallByName(objInput, strProperty, VbGet) <> lngID)
        End If
        RefreshObject = blnTest
        
      End Function
      
      Public Sub Init(scnDB As Variant, Optional lngID As long = -1)
      
      Set m_dcnDB = dcnDB
      m_blnIsNew = (lngID = -1)
      
      If Not m_blnIsNew Then
      Ser m_rsData = m_dcnDB.Execute("SELECT * FROM tblMessages" _
      & "WHERE MessageID = " & lngID)
      FillObject Me, m_rsData
      m_rsData.Close
  End If
End Sub

    Public Seb Save()
      
      Dim objField As ADODB.Field
      
      Set m_rsData = New ADODB.RecordSet
      if m_blnIsNew Then
         m_rsData.Open "SELECT * FROM tblMessages", _
         m_dcnDB, _
         adOpenDynamic, _
         adLockOptimistic
         m_rsData.AddNew
      Else
         m_rsData.Open "SELECT * FROM tblMessages", _
         & "WHERE MessageID = " & m_lngMessageID, _
         m_dcnDB, _
         adOpenDynamic, _
         adLockPessimistic
      End If
      
      SaveObject Me, m_rsData
      m_rsData.Update
      
      FillObject Me, m_rsData
      m_rsData.Close
End Sub

Private Sub Class_Terminate()

    Set m_objGroup = Nothing
      Set m_objMember = Nothing
      Set m_objReplyTo = Nothing
      
End Sub

Public Property Get Member() As Member
            
         If RefreshObject(m_objMember, m_lngMemberID, "MemberID")
         Then
             Set m_objMember = New Member
               m_objMember.Init m_dcnDB, m_lngMemberID
          End If
            Set Member = m_objMember
    End Property
      
      Public Property Get LastMessage() As Message
      
           If RefreshObject(m_objLastMessage, m_lngLastMessageID, "LastMessageID")
       Then
           Set m_objLastMessage = New Message
             m_objLstMessage.Init m_dcnDB, m_lngLastMessageID
         End If
            Set LastMessage = m_objLastMessage
             
    End Property
      
      Public Property Get Group() Group
      
          If RefrehObject(m_objGroup, m_lngGroupID, "GroupID")
            Then
            Set m_objGroup = New Group
            m_objGroup.Init m_dcnDB, m_lngGroupID
      End If
        Set Group = m_objGroup
   
   End Property
         
      
   Public Sub Init(dcnDB As Variant, _
      Optional lngMemberID As Long = -1, _
        Optional lngGroupID As Long = -1)
        
        Set m_dcnDB = dcnDB
        m_blnIsNew = (lgnMemberID = -1)
        
        If Not m_blnIsNew Then
           Set m_rsData = m_dcnDB.Execute("SELECT * FROM tblSubScriptions " _
             & "WHERE MemberID = " & lngMemberID _
             & " AND GroupID = " & lngGroupID)
        Fill
        m_rsData.Close
        End If
        
      End Sub
      
      Private Sub Fill()

    Dim objField As ADODB.Field  
      
      For Each objField In m_rsData.Fields
        If Not IsNull(m_rsData(objField.Name)) Then
        CallByName Me, objField.Name, VbLet, _
        m_rsData(objField.Name)
      End If
      Next objField
      
      End Sub
      
      Public Sub Save()
      
      Dim objField As ADODB.Field
      Set m_rsData = New ADODB.RecordSet
      If m_blnIsNew Then
         m_rsData.Open "SELECT * FROM tblSubscriptions", _
         m_dcnDB, _
         adOpenDynamic, _
         adLockOptimistic
      Else
         m_rsData.Open "SELECT * FROM tblSubscriptions", _
         & "WHERE MemberID = " & m_lngMemberID _
         & " AND GroupID = " & m_lngGroupID, _
         m_dcnDB, _
         adopenDynamic, _
         adLockPessimistic
      End If
      
      For Each objField In m_rsData.Fields
          m_rsData(objField.Name) = CallByName(Me, ObjectField.Name, VbGet)
            Next ObjField
            
            End Sub
            
            Private Sub Class_Terminate()
               Set m_objGroup = Nothing
               Set m_objLastMessage = Nothing
               Set m_objMember = Nothing
End Sub
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16875067
VB is telling you that Public Sub Init is being used twice, by looking at your code I can see that the First and Third procedures are exactly the same name. (Init)
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16875072
I wrote it exactly how it is in the book?
Humm. I have never messed around with Developing 'Classes' before
So, am a little loss on this issue.

It states in the book that
[Quote]
You should also have an Init and Save method
[/Quote]

The
Public Sub Init
Are the same, as for the 1st line, but different through-out it's indivisual Sub's.

How would I correct this issue, so that it will compile?
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16875111
You need to change the name of one of the Init procedures because there are exactly the same.

Public sub InitA()
Public sub InitB()

If you rename them then you will remove the ambigous name detected error. However I am sure that there will be alot more errors in the code from what I can off hand.

Is there something else I could show you of interest instead of jumping right into database's?
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16875124
I will give this a shot
Public sub InitA()
Public sub InitB()

[Quote]
Is there something else I could show you of interest instead of jumping right into database's?
[/Quote]

What exactly you referring too?

-------
Reason behind wanting to do this .dll file with ASP.

I am a Site Developer, and been working with ASP on a low-level Technical basis with a few years now.
This paticular script in this book, seems to be exactly what I am needing for one of our Company Sites
Of which we are "Building Software & ASP Site(s)" for.

So, at the moment, I have no other choice but to learn what I am right now.

But, you are more then welcome to give me some pointers on other ventures as well.
As I first started out with VB back around VB5 (I think), of which it did not last long,
Before I got into Delphi, which was the best choice for "me" to have made.

But, I am interested in learning anything that I can about VB
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

Author Comment

by:Wayne Barron
ID: 16875174
I am getting an Error on this line

Public Sub SaveObject(objInput As Object, rsInput As ADODB.Recordset

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

User-defined type not defined
---------------------------
OK   Help  
---------------------------
Which I done some reading up on this Error for:
[Quote]
check project references for DAO - if this reference is missing, you can not work with databases
[/Quote]

And I checked and it was listed but was not checked, so I have it checked now, and restarted VB
And still get the same error on the same line.

(And yes you was right, I had a few errors that had to be replaced
Like:    seb   was suppose to be   sub
Do not know how many more I have, But I will find out eventually)
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 125 total points
ID: 16877135
It looks like the major portion of your code is using ADO? I don't know much about ASP and I very rarely do any database programming. However if your using ADO then you will need to add a reference to Microsoft ADO.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16908276
Hello egl1044;

Would you have a link (or) some information on this?  [reference to Microsoft ADO]
I need to do some research on it, so that I can figure this issue out.

Thanks
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16939268
Any more idea's on this one [egl1044]?
If not, then I am going to close/refund on it.
But if you can help to provide some usful information that would be great.

Thanks
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16968919
egl1044
I went ahead an awarded you a [C] for this, just to get it out of my [Opened] Questions.
I would have preferred that you would have come back in and atleast finished what you started.
But that did not happen.
No big deal, I will work on this project again on another day, and "hope" that someone
Will better assist me by following up on there information that they give.

Best Regards
Carrzkiss
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16971846
Some of us have to work to you know
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16972850
No offense. Work or not.
You posted your last comment here on:  06/10/2006
It is now:  06/23/2006

You were so busy working, that you could not come in here and help to provide a simple link.
But yet, you were not busy enough to go to other places to assist in their issue.

Please, find another excuse except for saying that you "have to work"

Answered Questions
1 06/20/2006
2 06/16/2006
3 06/15/2006

Comment Histrory
1 06/21/2006
2 06/21/2006
3 06/20/2006
4 06/19/2006
5 06/19/2006
6 06/17/2006
7 06/17/2006
8 06/17/2006
9 06/14/2006
10 06/13/2006
11 06/12/2006



0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 115
add text to end of existing text in file 16 62
VBA filters 2 39
Getting warning: You are about to delete 1 row(s) 9 37
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 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

20 Experts available now in Live!

Get 1:1 Help Now