How do I change this sub into a function

levyuk

Well-known member
Joined
Jun 7, 2004
Messages
313
Location
Wales, UK
Programming Experience
3-5
VB.NET:
[size=2][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Delete_Item([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] s [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]Object[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] DataGridCommandEventArgs)
DT = Session([/size][size=2][color=#800000]"Cart"[/color][/size][size=2])
DT.Rows(e.Item.ItemIndex).Delete()
Session([/size][size=2][color=#800000]"Cart"[/color][/size][size=2]) = DT
dg.DataSource = DT
dg.DataBind()
LabelTotal.Text = [/size][size=2][color=#800000]"£"[/color][/size][size=2] & Cart.GetItemTotal(DR, DT)
[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub
[/color][/size]

How do I turn the above sub into a function in another Class so that I can call it something like this

Dim Cart as new Cart
Cart.Delete()

How can I make that work?
 
A function is a method that returns a value. The way you are saying that you want to call the method looks like it is still a procedure, which is a method that does not return a value. I assume that what you have provided is an event handler. The only variable you are using inside the method that is local to the method is e.Item.ItemIndex, so if you can get the equivalent of this value from another source then you can use essentially the same code.
 
Back
Top