• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 563
  • Last Modified:

VB.NET - How to substitute frame name with the string variable?

Hi!

I pass two variables to the procedure. One is output to be printed in the form's textbox and another is a form's Name. How do I actually substitute Form1 with the frmName to make sure that the text is printed in the textbox of the form that I need?

I can implement it using Select Case or if.. then basing on frmName value, but I wonder how to do that avoiding it.

Thanks!
Public Sub Result(ByVal output As String, ByVal frmName As String)
        With Form1.txtServerStatus
            .Text &= vbCrLf & output
        End With
    End Sub

Open in new window

0
Zaurb
Asked:
Zaurb
  • 3
  • 2
1 Solution
 
knk53Commented:
Dont pass the form name as a string.  Pass the form as an object of the type of form it is.  
Public Sub Result(ByVal output As String, ByVal frmIN As MYFORMTYPE)
Of course if you have different Form Classes you are trying to pass to this procedure you may need to subclass all of the forms to a single class so that they include a text box called txtServerStatus.

 
0
 
ZaurbAuthor Commented:

I have 5 forms with the similar content and similar design, but not exactly the same functionality.
Depending on which specific form is used for working, I pass a form name variable to a class, that does the rest of the processing. txtServerStatus is available on all forms and prints the information on steps carried out in the class.
Since there're several users working contemporaneously they will see different information in the txtServerStatus, depending on operations they make.
For this reason, I pass the form name to a class, so that after procedures execute, they will print the result to a specific form.

As for this:
Public Sub Result(ByVal output As String, ByVal frmIN As MYFORMTYPE)

How should I implement it in my case?

0
 
knk53Commented:
You have 5 forms that are very similar with slight variations in functionality.  You would want to make a base form that contains the common objects and functionallity.  Then make the 5 specific forms by INHERITING from the base form.  This will allow the 5 specific forms to have exactly the same COMMON objects and functions and still give you the ability to modify them for their individualized functionality.
To make a base form, simply add a new form to your project.  Design it with any common components and call it  frmBASE.   For example, on frmBase put a textbox called txtServerStatus in the appropriate place to be used for the 5 forms you need.
To create your 5 specific forms, right click on  your project and select ADD INHERITED FORM. Name the new form and pick frmBASE from the selection list.  A new form exactly like frmBase will be added to your design editor.
Individualize each of the 5 forms for their unique functionallity.  Then you can create functions like the one below which allows a FORM of type frmBASE as a parameter.  Within the function, all members and properties of frmBASE are accessible.
Create Public Sub Result(ByVal Output as String, ByVal frmIn as frmBASE)
      frmIn.txtServerStatus will be accessible
 
From any of the five forms you can call Result(mystring,ME)
 
Hope this helps


0
 
knk53Commented:
I thought about this problem some more.   You could use a case statement instead of inheritance.  For example
 
Public Sub Result(ByVal output As String, ByVal frmName As String)
    Select Case frmName
       Case "FORM1"
                    frm1.txtServerStatus.Text &= vbCrLF & output
      Case "FORM2"

                    frm2.txtServerStatus.Text &= vbCrLF & output
End Select
End Sub  
Of course to do this, frm1 and frm2 would have to be global variable names.   You could declare
     Public frm1 as FORM1 = new FORM1()
I have done workarounds like this before as opposed to recreating all of the forms as inheritted from a base form.
 
Good Luck
0
 
ZaurbAuthor Commented:
This is actually how I do it now. And it seems to be the less complicated way to deal with this problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now