Results 1 to 5 of 5

Thread: [RESOLVED] Class Modules and Forms

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    greenwood,in
    Posts
    24

    Resolved [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
    Last edited by ga80071; Jan 21st, 2005 at 03:18 PM. Reason: Issue resolved - Thank you very much

  2. #2
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    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.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    greenwood,in
    Posts
    24

    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:
    1. Public Function GETDRIVES_INNTGXPFS1() As String
    2. ' THIS SUBROUTINE FINDS ALL OF THE LOGICAL DRIVES AND THEN FINDS THE
    3. ' DRIVE THAT IS NAMED AUTOMATION and is 10 characters long AND RETRIEVES THE DRIVE LETTER
    4. Dim x, y As Integer
    5. 'Search each drive for an "Automation" indication
    6. For x = 0 To Drive1.ListCount - 1
    7. y = InStr(1, Drive1.List(x), "Automation", 1)
    8. If y = 18 Then
    9. 'If found, assign the drive letter and exit the routine
    10. GETDRIVES_INNTGXPFS1 = Mid(Drive1.List(x), 1, 1)
    11. x = Drive1.ListCount - 1
    12. End If
    13. Next
    14. 'GETDRIVES_INNTGXPFS1 = MAPPEDDRIVE_INNTGXPFS1
    15. End Function
    16. Private Sub Form_Load()
    17. GETDRIVES_INNTGXPFS1
    18. End Sub
    19. Public Property Let getdriveletter(ByVal vNewValue As String)
    20. getdriveletter = GETDRIVES_INNTGXPFS1
    21. 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]

  4. #4
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    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:
    1. ' In the Form1
    2. Public Property Get getdriveletter() as String
    3.   getdriveletter = "Some String."
    4. End Property

    VB Code:
    1. ' In the Class module
    2. Public Property Get getdriveletter() as String
    3.   getdriveletter = Form1.getdriveletter()
    4. End Property

    Will that help you out?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    greenwood,in
    Posts
    24

    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:
    1. ' In the Form1
    2. Public Property Get getdriveletter() as String
    3.   getdriveletter = "Some String."
    4. End Property

    VB Code:
    1. ' In the Class module
    2. Public Property Get getdriveletter() as String
    3.   getdriveletter = Form1.getdriveletter()
    4. 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 !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width