Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimizing drag function
#1
Well, I am adding a custom top bar to my game (the bar at the top of everything with a minimize, maximize, and exit button). I am coding it myself and made this code to drag it. It occurs when you click on the label that is over the dragable part of the bar.

x2 and y2 are integers to store the original location of the cursor (when the user clicks on the bar).

Code:
Private Sub lblDragBar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    x2 = X
    y2 = Y
End Sub

Private Sub lblDragBar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case Button
        Case 1
            If x2 > X Then frmMirage.Left = frmMirage.Left + (X - x2)
            If x2 < X Then frmMirage.Left = frmMirage.Left - (x2 - X)
            If y2 > Y Then frmMirage.top = frmMirage.top + (Y - y2)
            If y2 < Y Then frmMirage.top = frmMirage.top - (y2 - Y)
    End Select
End Sub

Is there any way to optimize this?
Reply
#2
This is a good place for my question I have been wondering forever haha.

Do With statements actually optimize anything?
Reply
#3
simply yes
in stead of evaluating/reading the part multiple times
it reads With once and reuses what it read the first time
Reply
#4
So this:
[code]Public Sub ItemEditorInit()
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Added gfx constant.
'****************************************************************

frmItemEditor.picItems.Picture = LoadPicture(App.Path & GFX_PATH & "items" & GFX_EXT)

frmItemEditor.txtName.Text = Trim(Item(EditorIndex).Name)
frmItemEditor.scrlPic.Value = Item(EditorIndex).Pic
frmItemEditor.cmbType.ListIndex = Item(EditorIndex).Type

If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_WEAPON) And (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex
Reply
#5
basically yes..
Reply
#6
Interesting. Any clue as to how much improvement we're looking at if one was to optimize all of the initializations with 'With'?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)