Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External Subroutine

Status
Not open for further replies.

wrchto

IS-IT--Management
Jan 3, 2001
14
AT
Hi!

Maybe this is an idiot's-question but I hope, you can help me!
I want to write a subroutine which is useable from any other VB-programs. I want to call it from VB-programs but also from Excel-VBA-programs. I do not know which type of program I have to write. Do I have to write a dll? Or an exe? I want to make the user-identification with this subroutine and I want to use it's functions in my other programs without coding it new in every program.

Please help me!

Thank you
Tom
 
Tom,

you should make a dll, compile it and register.
that's all!

regards
Johan
 
Do you have any examples for programming a dll? I tried to use the VB-help but I think I'm too silly. What must I declare in the dll and how must I make my call in my main-prog?

Thank you
Tom
 
Tom,

There's actually not much to it. Here's a small example of a dll.
You have 1 module (LogError.bas) to write any message to your immediate window, and 1 class (Point.cls) which holds 3 variables (x, y & z) with some functions.
To recreate you open a new project (ActiveX DLL) and inser the following code:

---MODULE CODE---
Public Sub PrintErrorLog(strMessage As String)
Debug.Print strMessage
End Sub
---END MODULE CODE---

---CLASS MODULE CODE---
Private m_dblX As Double
Private m_dblY As Double
Private m_dblZ As Double

Public Property Let CoX(NewValue As Double)
m_dblX = NewValue
End Property

Public Property Get CoX() As Double
CoX = m_dblX
End Property

Public Property Let CoY(NewValue As Double)
m_dblY = NewValue
End Property

Public Property Get CoY() As Double
CoY = m_dblY
End Property

Public Property Let CoZ(NewValue As Double)
m_dblZ = NewValue
End Property

Public Property Get CoZ() As Double
CoZ = m_dblZ
End Property

Public Function Move(AddX As Double, AddY As Double, AddZ As Double) As Boolean
On Error GoTo errhandler

m_dblX = m_dblX + AddX
m_dblY = m_dblY + AddY
m_dblZ = m_dblZ + AddZ
Move = True
Exit Function

errhandler:
PrintErrorLog "Error in Function Move"
Move = False
End Function

Public Function GetPoint() As String
GetPoint = "X: " & CStr(Round(m_dblX, 2)) & ", Y: " & CStr(Round(m_dblY, 2)) & ", Z: " & CStr(Round(m_dblZ, 2))
End Function
---END CLASS MODULE CODE---

Note: Set the description in Project Properties to the name you want VB to display in your references later on.

Then you create the dll.
Register it.
Add it to the Refernces for each program where you want to use it. (if the Dll is registered, it should be in the list)

That's it!

Regards,
Johan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top