[RESOLVED] Class Modules and Forms
I am trying to write a DLL and the problem that I having is that I need to get the value of a string variable from form1 of a Class Module (clGetAutomationDrives) to the Class module (clGetAutomationDrives). Can anyone tell me how to do this. This is my first exposure to Class Modules. Here is the code within the Class Module (form1):
Public Function GETDRIVES_INNTGXPFS1() As String
' THIS SUBROUTINE FINDS ALL OF THE LOGICAL DRIVES AND THEN FINDS THE
' DRIVE THAT IS NAMED AUTOMATION and is 10 characters long AND RETRIEVES THE DRIVE LETTER
Dim x, y As Integer
'Search each drive for an "Automation" indication
For x = 0 To Drive1.ListCount - 1
y = InStr(1, Drive1.List(x), "Automation", 1)
If y = 18 Then
'If found, assign the drive letter and exit the routine
GETDRIVES_INNTGXPFS1 = Mid(Drive1.List(x), 1, 1)
x = Drive1.ListCount - 1
End If
Next
'GETDRIVES_INNTGXPFS1 = MAPPEDDRIVE_INNTGXPFS1
End Function
Private Sub Form_Load()
GETDRIVES_INNTGXPFS1
End Sub
Public Property Let getdriveletter(ByVal vNewValue As String)
getdriveletter = GETDRIVES_INNTGXPFS1
End Property
Here is the code in the class module (clGetAutomationDrives):
Public MAPPEDDRIVE_INNTGXPFS1 As String
Public GETDRIVES_INNTGXPFS1 As String
Public Function loadform()
Form1.Visible = True
End Function
Public Property Get getdriveletter() As String
getdriveletter = GETDRIVES_INNTGXPFS1
End Property
Here is the code in the test form to test the DLL:
Option Explicit
Private Sub Command1_Click()
Dim test As New clGetAutomationDrives
' Create the objects
Set test = New clGetAutomationDrives
MsgBox test.loadform
Debug.Print "GETDRIVES_INNTGXPFS1="; getdriveletter
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Re: Class Modules and Forms
I can help you.
1) Place your original code in [Highlight=VB] tags, I can't read it.
2) Define, very briefly, how the Form and the Class have to interact.
ie.. The Class needs a String from the Form, or I need to pass a String from the Class to the Form. From your statements, I can't tell which you are trying to do.
Re: Class Modules and Forms
I am trying to write a DLL and the problem that I having is that I need to get the value of a string variable from form1 of a Class Module (clGetAutomationDrives) to the Class module (clGetAutomationDrives). Can anyone tell me how to do this. This is my first exposure to Class Modules
GOAL: I have created a form that is in a Class Module project. I need to get a text string from this form to the Class Module:
Here is the code within the Class Module (form1):
VB Code:
Public Function GETDRIVES_INNTGXPFS1() As String
' THIS SUBROUTINE FINDS ALL OF THE LOGICAL DRIVES AND THEN FINDS THE
' DRIVE THAT IS NAMED AUTOMATION and is 10 characters long AND RETRIEVES THE DRIVE LETTER
Dim x, y As Integer
'Search each drive for an "Automation" indication
For x = 0 To Drive1.ListCount - 1
y = InStr(1, Drive1.List(x), "Automation", 1)
If y = 18 Then
'If found, assign the drive letter and exit the routine
GETDRIVES_INNTGXPFS1 = Mid(Drive1.List(x), 1, 1)
x = Drive1.ListCount - 1
End If
Next
'GETDRIVES_INNTGXPFS1 = MAPPEDDRIVE_INNTGXPFS1
End Function
Private Sub Form_Load()
GETDRIVES_INNTGXPFS1
End Sub
Public Property Let getdriveletter(ByVal vNewValue As String)
getdriveletter = GETDRIVES_INNTGXPFS1
End Property
Here is the code in the class module (clGetAutomationDrives):
[Highlight=VB]
Public MAPPEDDRIVE_INNTGXPFS1 As String
Public GETDRIVES_INNTGXPFS1 As String
Public Function loadform()
Form1.Visible = True
End Function
Public Property Get getdriveletter() As String
getdriveletter = GETDRIVES_INNTGXPFS1
End Property
[Highlight=VB]
Here is the code in the test form to test the DLL:
[Highlight=VB]
Option Explicit
Private Sub Command1_Click()
Dim test As New clGetAutomationDrives
' Create the objects
Set test = New clGetAutomationDrives
MsgBox test.loadform
Debug.Print "GETDRIVES_INNTGXPFS1="; getdriveletter
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
[Highlight=VB]
Re: Class Modules and Forms
1) Make a Public Property on the Form that exposes the String.
2) Make a Public Property on the Class that exposes the Form's Public Property.
VB Code:
' In the Form1
Public Property Get getdriveletter() as String
getdriveletter = "Some String."
End Property
VB Code:
' In the Class module
Public Property Get getdriveletter() as String
getdriveletter = Form1.getdriveletter()
End Property
Will that help you out?
Re: Class Modules and Forms
Quote:
Originally Posted by Dave Sell
1) Make a Public Property on the Form that exposes the String.
2) Make a Public Property on the Class that exposes the Form's Public Property.
VB Code:
' In the Form1
Public Property Get getdriveletter() as String
getdriveletter = "Some String."
End Property
VB Code:
' In the Class module
Public Property Get getdriveletter() as String
getdriveletter = Form1.getdriveletter()
End Property
Will that help you out?
Thank you very much. I am a bit embarrassed how easy that was. Oh well, thanks again for your help !