Results 1 to 5 of 5

Thread: Making a class module..

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Making a class module..

    I want to make a class module for adding effects to my form.

    So far i have added the following to a class module:
    VB Code:
    1. Option Explicit
    2.  
    3. Public Sub BlendForm(ByRef iobject As Form)
    4. Dim z As Long
    5. Dim r As Byte, g As Byte, b As Byte, flag As Byte, d(3) As Byte
    6.  r = 255: g = 255: b = 255: flag = 0
    7.         For z = 0 To iTimes
    8.             iobject.BackColor = Disco
    9.         Loop
    10. End Sub
    11.  
    12. Private Function Disco() As Long
    13.  
    14.     If flag Then
    15.         r = DoIt(1, r)
    16.         g = DoIt(2, g)
    17.         b = DoIt(3, b)
    18.         flag = flag - 1
    19.     Else
    20.         r = Ran(1, r)
    21.         g = Ran(2, g)
    22.         b = Ran(3, b)
    23.         flag = 50
    24.     End If
    25.         Disco = RGB(r, g, b)
    26.  
    27. End Function
    28.  
    29. Private Function DoIt(ByVal a As Byte, ByVal c As Byte)
    30.     If ((d(a) = 2 And c < 255) Or c = 0) Then
    31.         c = c + 1
    32.         d(a) = 2
    33.     Else
    34.         If ((d(a) = 1 And c) Or c = 255) Then
    35.             c = c - 1
    36.             d(a) = 1
    37.         End If
    38.                 If a = 3 Then
    39.             If (d(1) + d(2) + d(3) = 0) Then flag = 1
    40.         End If
    41.     End If
    42.  
    43.     DoIt = c
    44.  
    45. End Function
    46.  
    47. Private Function Ran(ByVal a As Byte, ByVal c As Byte)
    48.    
    49.     If ((Rnd > 0.667 Or c = 0) And c < 255) Then
    50.         c = c + 1
    51.         d(a) = 2
    52.     ElseIf ((Rnd <= 0.5 Or c = 255) And c > 0) Then
    53.         c = c - 1
    54.         d(a) = 1
    55.     Else
    56.         d(a) = 0
    57.     End If
    58.  
    59.     Ran = c
    60.    
    61. End Function

    and in my form i wrote

    VB Code:
    1. Option Explicit
    2. Dim ifrm As FrmEffects
    3.  
    4. Private Sub Form_Load()
    5. Set ifrm = New FrmEffects
    6.     ifrm.BlendForm (Form1)
    7. End Sub

    But its returning crazy errors..i hope someone will help me here. Thanks

  2. #2
    Hyperactive Member
    Join Date
    May 2002
    Location
    Chicago
    Posts
    271

    Re: Making a class module..

    Try with the following changes:

    VB Code:
    1. Option Explicit
    2. Dim z As Long
    3. Dim r As Byte, g As Byte, b As Byte, flag As Byte, d(3) As Byte
    4.  
    5. Public Sub BlendForm(ByRef iobject As Form)
    6. Dim iTimes As Long
    7.  
    8.  r = 255: g = 255: b = 255: flag = 0
    9.         For z = 0 To iTimes
    10.             iobject.BackColor = Disco
    11.         Next
    12. End Sub
    13.  
    14. Private Function Disco() As Long
    15.  
    16.     If flag Then
    17.         r = DoIt(1, r)
    18.         g = DoIt(2, g)
    19.         b = DoIt(3, b)
    20.         flag = flag - 1
    21.     Else
    22.         r = Ran(1, r)
    23.         g = Ran(2, g)
    24.         b = Ran(3, b)
    25.         flag = 50
    26.     End If
    27.         Disco = RGB(r, g, b)
    28.  
    29. End Function
    30.  
    31. Private Function DoIt(ByVal a As Byte, ByVal c As Byte)
    32.     If ((d(a) = 2 And c < 255) Or c = 0) Then
    33.         c = c + 1
    34.         d(a) = 2
    35.     Else
    36.         If ((d(a) = 1 And c) Or c = 255) Then
    37.             c = c - 1
    38.             d(a) = 1
    39.         End If
    40.                 If a = 3 Then
    41.             If (d(1) + d(2) + d(3) = 0) Then flag = 1
    42.         End If
    43.     End If
    44.  
    45.     DoIt = c
    46.  
    47. End Function
    48.  
    49. Private Function Ran(ByVal a As Byte, ByVal c As Byte)
    50.    
    51.     If ((Rnd > 0.667 Or c = 0) And c < 255) Then
    52.         c = c + 1
    53.         d(a) = 2
    54.     ElseIf ((Rnd <= 0.5 Or c = 255) And c > 0) Then
    55.         c = c - 1
    56.         d(a) = 1
    57.     Else
    58.         d(a) = 0
    59.     End If
    60.  
    61.     Ran = c
    62.    
    63. End Function

    VB Code:
    1. Option Explicit
    2. Dim ifrm As frmEffects
    3.  
    4. Private Sub Form_Load()
    5. Set ifrm = New frmEffects
    6.     ifrm.BlendForm Form1
    7. End Sub
    Sometimes what you're looking for is exactly where you left it.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Making a class module..

    Don't put Form1 in brackets in the function call, otherwise it is treated as an expression evaluation and passed ByVal where instead you want ByRef.

    Also, maybe you should make a property to hold the form reference, set that first, and then there is no need to pass a reference to each of the effect functions.

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a class module..

    Quote Originally Posted by |2eM!x
    But its returning crazy errors..
    Anything specific or just "something crazy has happened"?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Making a class module..

    Quote Originally Posted by |2eM!x
    But its returning crazy errors..i hope someone will help me here. Thanks
    What are the specifics on the "crazy errors"?

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