class libary

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patr0805
    New Member
    • Sep 2007
    • 48

    #1

    class libary

    Here is what I want it to do:
    1: My form uses my class library dll to use a command called moveobject
    2: My form sends button1 to the byval
    3: The button on the form is moving

    Here is what it does right now:
    1: My form uses my class library dll to use a command called moveobject
    2: My form sends button1 to the byval
    3: Returning an error

    I want to use the objects in the designer in the class library like this (GM is the name of my class library):

    This is the form:

    [CODE=vbnet] Dim GMF As GM.functions
    Private Sub Button8_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button8.Click
    GMF.Move_fixed( Me.Button1, "1", 10)
    End Sub[/CODE]

    This is the class library:

    [CODE=vbnet]Public Class functions
    Dim way2
    Dim obh As Object
    Dim sp
    Public Function Move_fixed(ByVa l objectname As Object, ByVal way As String, ByVal speed As String)
    way2 = way
    obh = objectname
    timer(speed)
    End Function
    Dim tt
    Public Function timer(ByVal time As String) _
    As String
    tt = 100
    sp = time
    InitializeCompo nent()
    End Function
    Private Sub InitializeCompo nent()
    Me.Timer1 = New System.Windows. Forms.Timer
    'Timer1
    '
    Me.Timer1.Inter val = tt
    '
    'Form1
    Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles Timer1.Tick
    If way2 = "1" Then
    With obh
    .Left = .Left + sp
    .top = .top + sp
    End With
    End If
    If way2 = "2" Then
    With obh
    .top = .top + sp
    End With
    End If
    If way2 = "3" Then
    With obh
    .Left = .Left - sp
    .top = .top + sp
    End With
    End If
    If way2 = "4" Then
    With obh
    .Left = .Left + sp
    End With
    End If
    If way2 = "5" Then
    Timer1.Enabled = False
    Timer1.Stop()
    End If
    If way2 = "6" Then
    With obh
    .Left = .Left - sp
    End With
    End If
    If way2 = "7" Then
    With obh
    .Left = .Left - sp
    .top = .top - sp
    End With
    End If
    If way2 = "8" Then
    With obh
    .top = .top - sp
    End With
    End If
    If way2 = "9" Then
    With obh
    .Left = .Left + sp
    .top = .top - sp
    End With
    End If
    Timer1.Enabled = True
    End Sub
    Friend WithEvents Timer1 As System.Windows. Forms.Timer
    End Class[/CODE]
    Last edited by Killer42; Oct 29 '07, 02:25 AM. Reason: Added CODE=vbnet tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    You are wanting to Pass the Form Control to class module, in that case you should not pass with "ByVal".
    Remove ByVal for the Object and check..

    REgards
    Veena

    Comment

    • patr0805
      New Member
      • Sep 2007
      • 48

      #3
      Its still not work because when I remove byval it returns.

      I have VB.NET

      Comment

      • cugone
        New Member
        • Sep 2007
        • 20

        #4
        Try passing the form by reference (ByRef)

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by cugone
          Try passing the form by reference (ByRef)
          Yes, I think they changed things. In VB6, ByRef was the default, so you only ever had to specify when you wanted to pass by value. In later versions, I believe ByVal is now the default, so if you want to pass a reference you need to say so.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by patr0805
            Its still not work because when I remove byval it returns.
            Huh?! It returns what?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              On a slightly more positive note, I would recommend changing that big long stream of If way2 = tests. A Select Case would be the ideal, or you could just convert all but the first into ElseIf statements. Either way, it would make the code much easier to maintain.

              At present, to be certain of what will happen at any point, you have to read carefully through all the prior ones, to ensure that the value of way2 can't change. Either of the two suggested alternatives would make the options all mutually exclusive, removing this requirement. This would have the added advantage of executing (very slightly) faster, since it would stop checking the rest of the conditions once it hit the True one.

              Comment

              • patr0805
                New Member
                • Sep 2007
                • 48

                #8
                Hi the code is working 100% when I copy it directly inside the code in the form application, but it dont work in a class library that is the problem and yes Byval is now the default.

                This is what I want it to do:
                form with a button>uses class library>button is moving

                Comment

                Working...