[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need help Convert VB.NET code

Posted on 2011-09-14
12
Medium Priority
?
509 Views
Last Modified: 2012-05-12

Hello,

How can help me to convert this string to a public shared sub?

Form1.Ultragrid1.DisplayLayout.Bands(0).Columns

I've already 2 string with the information.
FormName as String
Grid as String



0
Comment
Question by:prinsbj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36536713
Try something like:
Public Shared Sub Foo(ByVal FormName As String, ByVal GridName As String)
        Dim frm As Form = Application.OpenForms(FormName)
        If Not IsNothing(frm) Then
            Dim ctls() As Control = frm.Controls.Find(GridName, True)
            If ctls.Length > 0 AndAlso TypeOf ctls(0) Is UltraGrid Then
                Dim grid As UltraGrid = CType(ctls(0), UltraGrid)
                ' ... do something with "grid" ...
            End If
        End If
    End Sub

Open in new window

0
 

Author Comment

by:prinsbj
ID: 36538351
Hello Idle_Mind,

Here the code I use.

Now I've to change something in the code for the formname "MaterialInward" and for the "UltraGrid1" this must be variable.

Hope it's now more clear.

Thanks
For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36538729
Right...so at line #7 where I have { ... do something with "grid" ... }, you could do:

                For Each col In grid.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next

And you'd call Foo() like this:

    Foo("MaterialInward", "UltraGrid1")
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:prinsbj
ID: 36538992
"MaterialInward", "UltraGrid1" should be variable and are now avaliable as strings.

So how can I do this?
0
 

Author Comment

by:prinsbj
ID: 36539077
This is the complet Public Shared Sub code.

I call this Public Shared Sub on this way:

        CWSProps.sub_FillLanguage(Me, Me.Name)

Hope you can give me a script that Replace the text MaterialInward and UltraGrid1.

Thanks!
Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

        For Each ctrl As Control In Page.Controls

            If TypeOf ctrl Is UltraExpandableGroupBox Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraExpandableGroupBox).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            Else
            End If

            If TypeOf ctrl Is UltraLabel Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraLabel).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            End If

            If TypeOf ctrl Is UltraButton Then
                If Len(LocRM.GetString(ctrl.Name.ToString)) >= 1 Then
                    DirectCast(ctrl, UltraButton).Text = LocRM.GetString(ctrl.Name.ToString)
                Else
                End If
            End If

            If TypeOf ctrl Is UltraGrid Then
                Dim col As UltraGridColumn
                For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns
                    If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                        col.Header.Caption = LocRM.GetString(col.Key.ToString)
                    Else
                    End If
                Next
            End If



            If ctrl.Controls.Count > 0 Then
                sub_FillLanguage(ctrl, FormName)
            End If
        Next
    End Sub

Open in new window

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36539086
Seriously?...  =\

    Dim frmName As String = "MaterialInward"
    Dim gridName As String = "UltraGrid1"
    Foo(frmName, gridName)
0
 

Author Comment

by:prinsbj
ID: 36539205
I do not understand what you are saying.

Is there not a each command/code that I can fill in on the place of MaterialInwards and UltraGrid1?

Thanks
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36539615
I don't understand either...

You're passing in:

    Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

And the line in question is:

                For Each col In MaterialInward.UltraGrid1.DisplayLayout.Bands(0).Columns

How do "Page", "FormName", "MaterialInward" and "UltraGrid1" relate to each other?...

You need to convert "FormName" to the Form instance called "MaterialInward"?
Where would "UltraGrid1" come from?...are you going to pass that in to so it becomes?

    Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String, ByVal GridName As String)
0
 

Author Comment

by:prinsbj
ID: 36539664
The following must be happen.

The FormName is passed to the Public shared Sub  (ByVal Page As Control, ByVal FormName As String)

The UltraGrid1 name Should be GridName.String I can get from the Page as Control.Name

So now I need to change my  line

For Each col In FormName.GridName.DisplayLayout.Bands(0).Columns

But this does not work!

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 36539771
I don't quite understand this statement:

    "The UltraGrid1 name Should be GridName.String I can get from the Page as Control.Name"

So you're saying that the grid name should be the name of the current control in the loop?

    For Each ctrl As Control In Page.Controls
        ' ctrl.Name --> GridName?

If yes, try something like this:
Public Shared Sub sub_FillLanguage(ByVal Page As Control, ByVal FormName As String)

        Dim frm As Form = Application.OpenForms(FormName)
    
        For Each ctrl As Control In Page.Controls

            ....

            If TypeOf ctrl Is UltraGrid Then

                If Not IsNothing(frm) Then
                    Dim ctls() As Control = frm.Controls.Find(ctrl.Name, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is UltraGrid Then
                        Dim grid As UltraGrid = CType(ctls(0), UltraGrid)

                        For Each col As UltradGridColumn In grid.DisplayLayout.Bands(0).Columns
                            If Len(LocRM.GetString(col.Key.ToString)) >= 1 Then
                                col.Header.Caption = LocRM.GetString(col.Key.ToString)
                            Else
                            End If
                        Next

                    End If
                End If

            End If

Open in new window

0
 

Author Closing Comment

by:prinsbj
ID: 36539796
Idle_Mind

Thank you. This code works for me perfect.

Super!!!!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36539799
Yay!  =)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question