Hi

I have a one form with code that has lots of subs and was wondering if i can shift some of these subs to a class or module to make the main form coding less clutered.

Thanks

The short answer is yes. If you provide more information then perhaps a longer answer would be possible.

Yes u can move ur code in some other module and then directly call the function or so....

like database connections could be in different modules....
the user inputs like u need a text or a number can be in different modules....

creating modules is very good step as if the code is reusable no need to enter the complete code....one u create a module just calling the function will be fine....

My code is used for the datagridview so a calculation can be made on form load. Whenever i try to shift this code to a module or class i get a error message of object not found

Thanks for any help

Public Sub StartUpData()

    DG1.RowCount = 2
    DG2.RowCount = 1
    DG3.RowCount = 10
    DG4.RowCount = 5


    DG1.DefaultCellStyle.SelectionBackColor = Color.White
    DG1.DefaultCellStyle.SelectionForeColor = Color.Black
    DG2.DefaultCellStyle.SelectionBackColor = Color.White
    DG2.DefaultCellStyle.SelectionForeColor = Color.Black
    DG3.DefaultCellStyle.SelectionBackColor = Color.White
    DG3.DefaultCellStyle.SelectionForeColor = Color.Black
    DG4.DefaultCellStyle.SelectionBackColor = Color.White
    DG4.DefaultCellStyle.SelectionForeColor = Color.Black


    With DG1.Rows(0)
        .Cells(0).Value = True
        .Cells(1).Value = "Jan"
        .Cells(2).Value = 2000
        .Cells(3).Value = 1.00
    End With

    With DG1.Rows(1)
        .Cells(0).Value = True
        .Cells(1).Value = "Feb"
        .Cells(2).Value = 2000
        .Cells(3).Value = 2.59
    End With

    With DG1.Rows(2)
        .Cells(0).Value = True
        .Cells(1).Value = "March"
        .Cells(2).Value = 2000
        .Cells(3).Value = 5.36
    End With

    End Sub

In ur module along with the control names u need to mention the form names with it...

Form1.dg1.Datasource = dt .... 'somthing like this....else the module wont understand its is referring to which object...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.