Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > When i move code to Module it no longer works?


Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2002, 03:54 PM
NO1
Guest
 
Posts: n/a
Default When i move code to Module it no longer works?


I have this code that moves a head using SRCCOPY, SRCAND, And SRCPAINT.
you know for Sprites. now i made the code and made it a public function and called the function using case select (thanks to this Forum) But when i move the code to a .BAS module it no longer works and it gives me a sub or function not defined error. Is this move not possible.
Reply With Quote
  #2  
Old 04-26-2002, 03:56 PM
VB_ACK
Guest
 
Posts: n/a
Default

You're either not calling your function properly or naming it improperly.
Reply With Quote
  #3  
Old 04-26-2002, 03:56 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

It's more than possible. Why not post the code and maybe we can tell what you messed up in the move.
Reply With Quote
  #4  
Old 04-26-2002, 04:04 PM
NO1
Guest
 
Posts: n/a
Default

This is the Sprite Function It uses an array. When it's in the form in works but when i move it to it's own mod it don't.
Code:
Public Function jackNod()
Dim lResult As Long
    Dim picOldBack As StdPicture
    Dim StartTimer As Single
    Dim sngInterval As Single
    Dim iCounter As Integer
    Dim iNumFrames As Integer
    
    'We'll first make a copy of the background where the animation
    'will play. This is so we can restore it after the animation
    'does play
    lResult = BitBlt(picDisplay.hDC, 0, 0, imgSprite(1).Width, imgSprite(1).Height, Me.hDC, 0, 0, SRCCOPY)
    Set picOldBack = picDisplay.Image
    
    'Lets set our delay interval and number of frames
    sngInterval = 0.1
    StartTimer = Timer
    iNumFrames = 4
    
    'No we will loop through the Frames.
    For iCounter = 0 To iNumFrames - 1
        
        'Now we will cut out the area of the background to make room
        'for the sprite. We do this by using BitBlt to paint the Mask
        'Using the SRCAND. This will cut out only the black areas
        'of the mask
        Set picDisplay.Picture = imgMask(iCounter).Picture
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCAND)
        
        'Now we will paint the sprite in the hole we cut out of the
        'background with the mask using SRCPAINT
        Set picDisplay.Picture = imgSprite(iCounter).Picture
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCPAINT)
        Me.Refresh
        
        StartTimer = Timer
        Do While Timer < StartTimer + sngInterval
            DoEvents
        Loop
        
        'Refresh the background
        Set picDisplay.Picture = picOldBack
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCCOPY)
        
    Next
    
    'Now lets loop it backwards
    For iCounter = iNumFrames - 1 To 0 Step -1
        
        'Cut out the mask
        Set picDisplay.Picture = imgMask(iCounter).Picture
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCAND)
        
        'SRCPAINT the Sprite
        Set picDisplay.Picture = imgSprite(iCounter).Picture
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCPAINT)
        Me.Refresh
        
        StartTimer = Timer
        Do While Timer < StartTimer + sngInterval
            DoEvents
        Loop
        
        'Refresh the background
        Set picDisplay.Picture = picOldBack
        lResult = BitBlt(Me.hDC, 0, 0, imgSprite(iCounter).Width, imgSprite(iCounter).Height, picDisplay.hDC, 0, 0, SRCCOPY)
        
    Next
    
    Me.Refresh
End Function




This is How i call the function in the form

Private Sub cmdMove_Click()

Select Case True

Case txtControl.Text = "Nod"
Call jackNod

Case Else
End Select

End Sub


And this is the Sprite stuff in it's own Mod

Option Explicit

Public Const SRCAND = &H8800C6
Public Const SRCPAINT = &HEE0086
Public Const SRCCOPY = &HCC0020
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Last edited by dcl3500; 04-27-2002 at 12:36 AM.
Reply With Quote
  #5  
Old 04-26-2002, 04:07 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

picDisplay <--

That's one problem, if not THE problem. Your module doesn't know your form. Either pass the form to the function, or name the control explicitly. i.e.

Formname.picDisplay
Reply With Quote
  #6  
Old 04-26-2002, 04:07 PM
rive
Guest
 
Posts: n/a
Default

'picDisplay' is not known in the module. You'll have to prefix it with the form name on which it resides.

So use Form1.picDisplay ...
Reply With Quote
  #7  
Old 04-26-2002, 04:09 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

*reboot wonders if rive works for Thinker, Inc.
Reply With Quote
  #8  
Old 04-26-2002, 04:09 PM
rive
Guest
 
Posts: n/a
Default

Like vultures circling around a dying animal
Reply With Quote
  #9  
Old 04-26-2002, 04:17 PM
NO1
Guest
 
Posts: n/a
Default

You Guys are the Thanks Alot
You helped a young mind out
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->