Results 1 to 14 of 14

Thread: why does this make my computer work real slow

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Post

    when i move the play list, instead of moving it, it makes a copy of it to the place where i move it, like sometimes when you get an illigal operation, and you move it, it just kinda leaves a copy of the form on your screen, well this is like that, and after that, my computer works very slow.... i have 1328mb of ram, and my resources are high, well here's the code:

    Code:
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
    Private Declare Sub ReleaseCapture Lib "user32" ()
    Const WM_NCLBUTTONDOWN = &HA1
    Const HTCAPTION = 2
    
    Private Sub Form_Load()
        frmMP3.Visible = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim lngReturnValue As Long
        If Button = 1 Then
            Call ReleaseCapture
            lngReturnValue = SendMessage(frmPlaylist.hwnd, WM_NCLBUTTONDOWN, _
            HTCAPTION, 0&)
    
            For inta = 1 To 500
                For intb = 1 To 3030
    
                    If frmPlaylist.Left = frmMP3.Left + frmMP3.Width + inta Then
    
                        If frmPlaylist.Top = frmMP3.Top + frmMP3.Height - intb Then
                
                            MsgBox "you're close to the right"
                        End If
                    End If
                
                    If frmPlaylist.Left = frmMP3.Left + frmMP3.Width - inta Then
                
                        If frmPlaylist.Top = frmMP3.Top + frmMP3.Height - intb Then
                    
                            MsgBox "you're close to the left"
                        End If
                    End If
                Next intb
            Next inta
        End If
    End Sub
    if anyone could let me know how to fix it, i'd appreicate it
    NXSupport - Your one-stop source for computer help

  2. #2
    Guest
    I see you found your problem with Next inta line .
    Next inta goes after Next intb rather than before it .

    You should try adding some DoEvents to that code dimava, I'm sure it may speed up the process a little bit.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    but if i put the NEXT INTA first, an error comes up
    NXSupport - Your one-stop source for computer help

  4. #4
    Guest
    Uh..dimava?
    I said you found the error by yourself.
    You posted before asking why the code errors, but you found it already. So it's fine.

    'For a = 0 to 10 'a-begin
    'For b = 0 to 10 'b-begin
    'whatever-a
    'whatever-b
    'or
    'whatever-b
    'whatever-a
    'Next b 'b-end first
    'Next a 'a-end second

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    but my problem is that it makes my computer run very slow, and after i move it, it moves, and it leaves the image of the form, from where i moved it
    NXSupport - Your one-stop source for computer help

  6. #6
    Guest
    Why the heck do you have so much ram???

    1.3 Gig of RAM?!?!!?!?!?

    Makes my 256MB look puny. Well my computer is puny actually. Gotta overclock it or something. Gotta overclock my 3dfx card too.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    sorry, i ment 128meg, does anyone have the answer to my question?
    NXSupport - Your one-stop source for computer help

  8. #8
    Guest
    Put some DoEvents in some (or all) of your loops.

    Code:
    For X = 1 To 128
     lblX.Caption = X
    Next X
    
    'differs from
    
    For X = 1 To 128
     lblX.Caption = X
     
     DoEvents
    Next X

  9. #9
    Guest
    Originally posted by dimava
    sorry, i ment 128meg, does anyone have the answer to my question?
    I said:

    You should try adding some DoEvents to that code dimava, I'm sure it may speed up the process a little bit.
    And then Dreamlax said:

    Put some DoEvents in some (or all) of your loops.
    Come arn' dimava, pay attention .
    You may want to listen to the things I say, I have helped many people out with great code.
    So just read everything I say, it may help you to become President someday..or at least someone of importance!..or not.

  10. #10
    Guest
    Ok, let's begin dimava.

    We will begin with why you got the error.

    'For a = 0 to 10 'a-begin <-start first For
    'For b = 0 to 10 'b-begin <-start second For
    'whatever-a 'process first For
    'whatever-b 'process second For
    'Next b 'b-end first <-finish what's inside first
    'Next a 'a-end second <-then finish what's outside

    Hope that's a little better understanding.


    Q: What is the DoEvents function good for and why do we use it?

    VB's definition: Yields execution so that the operating system can process other events.

    A better understanding would be that you process all the code first before the DoEvents and then continue on to the next.

    'blah blah blah
    'blah blah blah
    'blah blah blah
    'DoEvents 'process all code above before continuing on the the next
    'blah blah blah
    'blah blah blah
    'blah blah blah

    Why is it used?

    DoEvents can prevent freezing of code.
    It is not harmful.
    It is mostly used in the For...Next Statement because it can freeze most of the time, whatever code is in there, or at least be really slow.
    But with DoEvents, you can do other stuff while the code is being processed.

    [Edited by Matthew Gates on 11-20-2000 at 01:36 AM]

  11. #11
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Angry Don't discourage people from asking questions by mocking them.

    Firstly I think you're all being very rude to dimava. Secondly I think you are all missing the point.

    DoEvents does not speed up the operation. How about looking at what happens in the For...Next loops, and how many times it happens?

    500 * 3030 = 1515000

    Why are those If statements performed more that 1.5 million times?

    Shrog

  12. #12
    Guest
    Hey, DoEvents gives the 'effect' of making it go faster. If you can see what it is doing and where it is up to, it seems faster than having to wait for it to finish.

  13. #13
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186

    Pay attention

    You're still missing the point. Painting flames on a car to make it look faster, does not change it into a bicycle.

    Dimava wants to determine if one form is being dragged close to the edge of another form. This should be a quick test, and should not require DoEvents. Can you not see that?

    Dimava,
    The problem is that your coding is in a loop. You are trying to check every possible point near the edge of the form to see if it is equal to the edge of the other form. This is performed 1.5 million times. That is why it's slow.

    What you need to do is get rid of the loop, and just check whether the distance between the forms is smaller that a certain amount.

    Code:
     
      Dim DistFromLeft As Single
      Dim DistFromTop As Single
      Dim DistFromRight As Single
      Dim DistFromBottom As Single
    
      DistFromLeft = Abs(frmMP3.Left - frmPlayList.Left - frmPlaylist.Width)
      DistFromTop = Abs(frmMP3.Top - frmPlayList.Top - frmPlaylist.Height)
      DistFromRight = Abs(frmMP3.Left + frmMP3.Width - frmPlayList.Left)
      DistFromBottom = Abs(frmMP3.Top + frmMP3.Height - frmPlayList.top)
     
      If DistFromLeft < 500 and DistFromTop < 3030 Then
        MsgBox "You are close to the Left"
      End If
    
      If DistFromRight < 500 and DistFromTop < 3030 Then
        MsgBox "You are close to the Right"
      End If

    Shrog

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks
    NXSupport - Your one-stop source for computer 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