2 Replies - 608 Views - Last Post: 11 September 2009 - 02:53 PM Rate Topic: -----

#1 kcm5052  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-September 09

Methods In A Class

Posted 11 September 2009 - 08:37 AM

I think I just need a push in the right direction. I cannot seem to get my sub from an instance of my class, once instantiated, to run when I click on the button. My Code in the class is


When I click this:
Private Sub btnBark_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBark.Click
		mydawg.bark()
	End Sub


I want this code to execute:
Sub bark()
		MessageBox.Show("WOOF WOOF")
	End Sub


Thanks in advance for any help you guys give me.
Mentor Edit: :code:

This post has been edited by AdamSpeight2008: 11 September 2009 - 02:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Methods In A Class

#2 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Methods In A Class

Posted 11 September 2009 - 09:27 AM

The code suggests that you should have a declaration of mydawg that is Public or Private within the code and it has been initialized with lines like:
Dim mydawg As DawgClass
mydawg = New DawgClass()


Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • Joined: 29-May 08

Re: Methods In A Class

Posted 11 September 2009 - 02:53 PM

So want this code to execute (Its contained in you dawg class):
Sub bark()
 MessageBox.Show("WOOF WOOF")
End Sub


By default this it private to your class, which means it can only be called from within that class.

It really simple to solve by adding the keyword Public
Public Sub bark()
 MessageBox.Show("WOOF WOOF")
End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1