Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:23:16+00:00 2026-06-07T21:23:16+00:00

I have 3 forms and they each have their own grids. The following code

  • 0

I have 3 forms and they each have their own grids. The following code is currently written on form1 but is used by all 3 forms. It works but is very messy and long since it must work for 3 forms that use different databases and contain different columns. Would it be considered more proper to split the code below into 3 separate functions and place on the back of each form containing only the data needed for that specific form ?

Public Class Form1

Public sFilter as string
Public sQuery as string


Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    

Public Sub buildFilter(ByVal form as string)
  select case form 
    Case "form1"
    sFilter = "control_no > 0 and control_no < 10000" 
    Case "form2"
    sFilter = "quantity > 0 and quantity < 7849"
    Case "form3"
    sFilter = "store_id > 10000"
  end select
End Sub

Public Sub buildQuery(form)
  Select case form
    Case "form1"
    sQuery = "Select * FROM dataBase1 WHERE " & sFilter 
    Case "form2"
    sQuery = "Select quantity, first_name, last_name FROM database2 WHERE " & sFilter
    Case "form3"
    sQuery = "Select * FROM dataBase3 WHERE " & sFilter
  End Select
End Sub


End  Class

I was told it would be best to take the above code and place it on the back of each form and only have it work with the form its on. I feel like that isn’t the best approach, but I also feel that the way its currently setup isn’t good either. What would be a good approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:23:17+00:00Added an answer on June 7, 2026 at 9:23 pm

    Build these methods into a common inherited form and then inherit it by your other forms:

    Public MustInherit Class MyInheritedForm
        Inherits System.Windows.Forms.Form
    
        Public sFilter as string
        Public sQuery as string
    
    
        Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    
    
        Public Sub buildFilter(ByVal form as string)
          select case form 
            Case "form1"
            sFilter = "control_no > 0 and control_no < 10000" 
            Case "form2"
            sFilter = "quantity > 0 and quantity < 7849"
            Case "form3"
            sFilter = "store_id > 10000"
          end select
        End Sub
    
        Public Sub buildQuery(form)
          Select case form
            Case "form1"
            sQuery = "Select * FROM dataBase1 WHERE " & sFilter 
            Case "form2"
            sQuery = "Select quantity, first_name, last_name FROM database2 WHERE " & sFilter
            Case "form3"
            sQuery = "Select * FROM dataBase3 WHERE " & sFilter
          End Select
        End Sub
    
    
    End  Class
    

    Then you just need:

    Public Class Form1
        Inherits MyInheritedForm
    
    
    End Class
    

    And your methods come right along with the inheritance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have 22 HTTP servers each running their own individual ASP.NET Caches. They read
I have a group of checkboxes that each have their own name, so they
The main problem is square-space builds their forms with java-script (YUI). They have are
I have a program that I want each person to have their own tab,
I have a simple page consisting of two forms. They cannot be displayed simultaneously
I currently have form that checks if a user has unsubmitted changes when they
2 quick questions: I have done my best to learn about normalization forms, but
I have to interact with a set of web-services that each come with their
I currently have a site where different users can login, and depending on their
I have 3 different login forms on my website and each of them use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.