Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

 

I have been porting a program from java to vb.net. In Java you can create class containing an abstract method and assign a method on creation of the class. I was wondering if something like this can be done in VB?

Example:

public abstract class myclass {

abstract public void execute();

}

 

//Code from another class

static myclass myclassvar1 = new myclass () {

public void execute() {

//Stuff here

}

};

static myclass myclassvar2 = new myclass () {

public void execute() {

//Different stuff here

}

};

Posted

Hi PlausiblyDamp

 

To my knowledge the only way to use that is use an other class to Inherit that class. For example when i declare myclassvar1 and myclassvar2, they need to be declared as myclass not the class i use to Inherit myclass.

Posted

I need it to work something like this(I know this is dogy..sorry):

Thanks in advance

 

Public class myclass

Public MustOverride Sub execute()

end class

 

Public class MainClass

 

public myvar1 as myclass

public myvar2 as myclass

 

public sub init()

myvar1 =new myclass

myvar2 =new myclass

myvar1.execute=me.execute1

myvar2.execute=me.execute2

end sub

 

public sub execute1()

'code here

end sub

 

public sub execute2()

'code here

end sub

end class

Posted

Thanks PlausiblyDamp...You Rule

 

Public Class myclass1

 

Public Delegate Sub BlankDelegate()

Public Execute As BlankDelegate

 

End Class

 

Private myvar1 As myclass1

Private myvar2 As myclass1

 

Sub test()

myvar1 = New myclass1

myvar2 = New myclass1

myvar1.Execute = AddressOf sub1

myvar2.Execute = AddressOf sub2

myvar1.Execute()

myvar2.Execute()

End Sub

 

Sub sub1()

MsgBox("Sub1")

End Sub

Sub sub2()

MsgBox("Sub2")

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...