Results 1 to 4 of 4

Thread: [RESOLVED] How to split form into module, form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Resolved [RESOLVED] How to split form into module, form

    Hi, please help. I'd like to split form into module and form, to have form readable and smaller for other functions
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type VS_FIXEDFILEINFO
    4.     dwSignature As Long
    5.     dwStrucVersionl As Integer
    6.     dwStrucVersionh As Integer
    7.     dwFileVersionMSl As Integer
    8.     dwFileVersionMSh As Integer
    9.     dwFileVersionLSl As Integer
    10.     dwFileVersionLSh As Integer
    11.     dwProductVersionMSl As Integer
    12.     dwProductVersionMSh As Integer
    13.     dwProductVersionLSl As Integer
    14.     dwProductVersionLSh As Integer
    15.     dwFileFlagsMask As Long
    16.     dwFileFlags As Long
    17.     dwFileOS As Long
    18.     dwFileType As Long
    19.     dwFileSubtype As Long
    20.     dwFileDateMS As Long
    21.     dwFileDateLS As Long
    22. End Type
    23.  
    24. Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" _
    25.         (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
    26. Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" _
    27.         (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    28. Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" _
    29.         (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    30. Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _
    31.         ByVal Source As Long, ByVal length As Long)
    32.  
    33. Private sFileVer As String
    34.  
    35. Private Sub DisplayVerInfo(sFullFileName As String)
    36.     'modified slightly from the example in the API Viewer from [url]http://www.allapi.net/[/url]
    37.     Dim rc As Long
    38.     Dim lDummy As Long
    39.     Dim sBuffer() As Byte
    40.     Dim lBufferLen As Long
    41.     Dim lVerPointer As Long
    42.     Dim udtVerBuffer As VS_FIXEDFILEINFO
    43.     Dim lVerbufferLen As Long
    44.    
    45.    '*** Get size ****
    46.     lBufferLen = GetFileVersionInfoSize(sFullFileName, lDummy)
    47.     If lBufferLen < 1 Then
    48.         'MsgBox "No Version Info available!"
    49.         Exit Sub
    50.     End If
    51.    
    52.     ReDim sBuffer(lBufferLen)
    53.     rc = GetFileVersionInfo(sFullFileName, 0&, lBufferLen, sBuffer(0))
    54.     rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
    55.     MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
    56.    
    57.     sFileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)
    58. End Sub
    59.  
    60. ' --- to have only this part in form
    61. Private Sub Command1_Click()
    62.     DisplayVerInfo Text1.Text
    63.     Form1.Caption = sFileVer
    64. End Sub
    65. ' -----------------------------------

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: How to split form into module, form

    Copy the code to a module (exept the code you already marked), and change the two following lines:
    Private sFileVer As String
    Private Sub DisplayVerInfo(sFullFileName As String)

    In these lines the word Private must be replaced with Public

    EDIT: both the form and the module should have an Option Explicit, so don't remove it from the form, but copy it to the module.
    Frans

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to split form into module, form

    Even better - move the code as Frans said, then get rid of sFileVer and change the following lines:

    VB Code:
    1. Public Function DisplayVerInfo(sFullFileName As String) As String
    2.  
    3. ' and at the end of the procedure:
    4.     DisplayVerInfo = Format$(udtVerBuffer.dwFileVersionMSh) & "." & _
    5.                      Format$(udtVerBuffer.dwFileVersionMSl) & "." & _
    6.                      Format$(udtVerBuffer.dwFileVersionLSh) & "." & _
    7.                      Format$(udtVerBuffer.dwFileVersionLSl)
    8. End Function
    Then use it like this:
    VB Code:
    1. Private Sub Command1_Click()  
    2.     Form1.Caption = DisplayVerInfo(Text1.Text)
    3. End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Thumbs up Re: How to split form into module, form

    Thanks guys, it works!!

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