0 Replies - 1083 Views - Last Post: 24 June 2014 - 05:15 AM Rate Topic: -----

#1 ThijsVB  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-June 14

Functions

Posted 24 June 2014 - 05:15 AM

Does anybody now how to create something (function, sub etc.) to create a couple of lines of code, which can be used in different subs. Now I have 24 different subs which all have to have (almost) the same code. So how do I combine this?
for example; W11 and W12 have to have the same code, the only difference is that in W12 is says w12.location and in w11 it says w11.location

The code works btw
Here is my code:

Public Class Form1
    Dim a As New Point
    Dim b As New Point
    Dim c As New Point

    

    Private Sub W12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles W12.Click
        a = W12.Location
        b.X = a.X + 70
        b.Y = a.Y - 70
        Mog.Location = b
        Mog.Visible = True
    End Sub

    Private Sub Mog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mog.Click
        If a = W12.Location Then
            W12.Location = Mog.Location
            Mog.Visible = False
            Mog2.Visible = False
        ElseIf a = W11.Location Then
            W11.Location = Mog.Location
            Mog.Visible = False
            Mog2.Visible = False
        End If

    End Sub

    Private Sub W11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles W11.Click
        a = W11.Location
        b.X = a.X + 70
        b.Y = a.Y - 70
        c.X = a.X - 70
        c.Y = a.Y - 70
        Mog.Location = b
        Mog2.Location = c
        Mog.Visible = True
        Mog2.Visible = True
    End Sub

    Private Sub Mog2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mog2.Click
        If a = W11.Location Then
            W11.Location = Mog2.Location
            Mog.Visible = False
            Mog2.Visible = False
        End If
    End Sub
End Class


Thanks!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1