Solved

Need help Convert VB.NET code

Posted on 2011-09-14
12
454 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
  • 6
  • 6
12 Comments
 
LVL 85

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 85

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
 

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 85

Expert Comment

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

    Dim frmName As String = "MaterialInward"
    Dim gridName As String = "UltraGrid1"
    Foo(frmName, gridName)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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 85

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 85

Accepted Solution

by:
Mike Tomlinson earned 500 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 85

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now