Reuse code problem 
Author Message
 Reuse code problem

I have a module that I call to fill upp a listview.

The forms name is f_Meny and the listview's is List1.

Now to my problem:

 I want to use the same sub to fill List2 on f_form2, I can't figure out how
I can to that.

Today I must copy the sub and past in it and change little in code and then
it works,  but it must be a way to reuse the sub I have.

Here is the sub I want to reuse:

Public Sub lista_List1(ByVal frm As f_Meny)

Dim i As Int32

With frm.List1

    .View = View.Details

    .Items.Clear()

    .Columns.Clear()

    .Columns.Add("HsNr", 100, HorizontalAlignment.Left)

    .Columns.Add("HsName", 80, HorizontalAlignment.Left)

While DataReader.Read()

    .Items.Add(DataReader("HsNr"))

    .Items(i).SubItems.Add(DataReader("HsName"))

    i = i + 1

End While

End With

ExitHere:

DataReader = Nothing

End Sub

Regars

Kenneth



Fri, 22 Oct 2004 13:24:57 GMT  
 Reuse code problem

Quote:
> I have a module that I call to fill upp a listview.

> The forms name is f_Meny and the listview's is List1.

> Now to my problem:

>  I want to use the same sub to fill List2 on f_form2, I can't
> figure out how
> I can to that.

> Today I must copy the sub and past in it and change little in
> code and then it works,  but it must be a way to reuse the sub I
> have.
> Here is the sub I want to reuse:

> Public Sub lista_List1(ByVal frm As f_Meny)

Pass the List, not the Form:

Public Sub lista_List1(ByVal list As listbox)

Quote:

> Dim i As Int32

> With  frm.List1

With List

Quote:

>     .View = View.Details
> [...]

Or, if possible, write your own listbox (inherited from Listbox) and place
it on both forms.

Armin



Fri, 22 Oct 2004 18:07:55 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How do I reuse code in the Code-Behind section of an ASPX page

2. How to reuse code in Access ?

3. Reuse of Code OCX?

4. Warning- careful when reusing code

5. Code ReUse Tip

6. Q: Regarding MDI and the reuse of controls and code

7. code reuse

8. Code Reuse

9. Reuse of VB3 code into VB5?

10. Reusing ActiveX Control/Code in Win GUI/MSIE

11. FYI: VBPJ's Policy on Code Reuse

12. Reuse code when interfaces implements the same method

 

 
Powered by phpBB® Forum Software