Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

CHANGE FORM TEXT AT CLASS AT RUNTIME

Hi All,

I want to show progress at form text.
I want to change it at class called from the form.

How could I do it ?

Thank you.
0
emi_sastra
Asked:
emi_sastra
  • 15
  • 13
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Either:
(a) Tightly Coupled -- Pass a reference to your form into the Class
(b) Loosely Coupled -- Make the Class raise a custom Progress event that the Form subscribes to (the form updates itself when the event is received)
0
 
emi_sastraAuthor Commented:
Hi Idle_Mind,

I try :

Form :

Call Show_Form_Text (me)


Class :

sub Show_Form_Text (byref frm as form)
   frm.text = "In Proses"
    Application.DoEvents()

End sub

Very weird, it doesn't work ?

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If this:

    Call Show_Form_Text (me)

is called from the Form as you say, then either Show_Form() is located in the form itself, or it is located in a Module somewhere.

There is no way it could be in the Class though.

Please show more complete code and I can help you.  =)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
emi_sastraAuthor Commented:
Below code is at form :
Call Show_Form_Text (me) is at form.


Below code is at class:

Sub Show_Form_Text (byref frm as form)
   frm.text = "In Proses"
    Application.DoEvents()
End sub

Is it clear enough ?

Thank you.


0
 
emi_sastraAuthor Commented:
Below code is at form let's say Form1:
Call Show_Form_Text (me) is at form.


Below code is at class let's say Class1:

Sub Show_Form_Text (byref frm as form)
   frm.text = "In Proses"
    Application.DoEvents()
End sub

Is it clear enough ?

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
If Show_Form_Text() is in a class, then you'd either need an instance of it:

    ' ... from within the FORM ...
    Dim sc As New SomeClass
    sc.Show_Form_Text(Me) ' <-- note the "sc" in FRONT of the method call

Or it would be Shared, in which case it would be prefaced the by class name:

    ' ... from within the FORM ...
    SomeClass.Show_Form_Text(Me) ' <-- note the "SomeClass" in FRONT of the method call

You have neither, which indicates to me that Show_Form_Text() is not in the class but instead either in the form itself of a Module.

As I said before, please show more complete code and I can help you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here's a made-up example:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sc As New SomeClass(Me)
        sc.Foo()
    End Sub

End Class

Public Class SomeClass

    Private MyForm1 As Form1

    Public Sub New(ByVal F1 As Form1)
        Me.MyForm1 = F1
    End Sub

    Public Sub Foo()
        For i As Integer = 1 To 100
            If Not IsNothing(MyForm1) Then
                MyForm1.Text = i
                System.Threading.Thread.Sleep(55)
                Application.DoEvents()
            End If
        Next
    End Sub

End Class

Open in new window

0
 
emi_sastraAuthor Commented:
Too long to show it all and might get confused, here is a simple sample :

Public class Form1

    Private Sub btnSummit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles       btnSummit.Click
        Dim Class1 As New Class1
        Class1.Show_Form_Text(Me)
        Class1 = Nothing
    End Sub

End Class

Public class Class1
    public Sub Show_Form_Text (byref frm as form)
          frm.text = "In Proses"
         Application.DoEvents()
   End sub
End Class

Hope this is clear enough.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That should work, and does.   *Remarkably similar to my example above!  =)

If you want help with your code then I would need to understand your actual situation better.

I'm not a "code psychic"...  =O
0
 
emi_sastraAuthor Commented:
- That should work, and does.   *Remarkably similar to my example above!  =)
But it does not work.

- If you want help with your code then I would need to understand your actual situation better.
- I'm not a "code psychic"...  =O
Sure.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I placed your example code into a NEW, BLANKproject and it worked fine.

If it's not working for you, then either you have other code in the existing project interfering somehow, or your environment is corrupt.
0
 
emi_sastraAuthor Commented:
Please see below code :

Public Sub Generate_New_Member(ByRef frm As Form)

        Dim trxTransaction As SqlTransaction = Nothing

        Using conApp As SqlConnection = New SqlConnection(strSQLCompanyConnection)
            conApp.Open()

            Dim cmdSQLCommand As SqlCommand = conApp.CreateCommand()

            trxTransaction = conApp.BeginTransaction
            cmdSQLCommand.Transaction = trxTransaction

            frm.Text = "ADD NEW MEMBER NO. : " & intCount & _
                       vbCrLf & _
                       "NEW MEMBER : " & strNewMemberId & _
                       vbCrLf & _
                       "SPONSOR MEMBER : " & strSponsorMemberId & _
                       vbCrLf & _
                       "UPLINE MEMBER : " & strUplineMemberId

            Application.DoEvents()

            Insert_To_Genealogy(strNewMemberId, strUplineMemberId, strSponsorMemberId, cmdSQLCommand)

            trxTransaction.Commit()

        End Using

Is there something interfere it ?

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I would have to understand the context in which Generate_New_Member() is called and whether the Form reference you passed in is actually the same reference to the Form you think it is.  It could also be possible that there is an exception is being thrown but is being simply consumed and ignored by a Try/Catch block further up the call chain.

Would need to see even more code to make a good guess as to what the problem is.
0
 
emi_sastraAuthor Commented:
- I would have to understand the context in which Generate_New_Member() is called and whether the Form reference you passed in is actually the same reference to the Form you think it is.  
Sure it is.

- It could also be possible that there is an exception is being thrown but is being simply consumed and ignored by a Try/Catch block further up the call chain.
Let me try again to make sure.

Thank you.
0
 
emi_sastraAuthor Commented:
Here I've got :

            frm.Text = "ADD NEW MEMBER NO. : " & intCount & _
                       vbCrLf & _
                       "NEW MEMBER : " & strNewMemberId & _
                       vbCrLf & _
                       "SPONSOR MEMBER : " & strSponsorMemberId & _
                       vbCrLf & _
                       "UPLINE MEMBER : " & strUplineMemberId

            Application.DoEvents() ---> I trace here, the frm.Text  has data on it.

Without debug, the form text show no text except Icon.

Thank you.


0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"I trace here, the frm.Text  has data on it."

So the debugger shows data in the Text() property for ~some~ Form.  This doesn't prove anything except that the thing you passed in is a valid form reference.  It doesn't tell me whether you have passed in the correct reference.

Does the text appear in the actual form at this point?

You say that you're sure the form reference is correct....but the code doesn't work.

Still seems like a reference problem to me.

Would still need to see more code to understand where the breakdown is.
0
 
emi_sastraAuthor Commented:
Please see below caller code :

Private Sub btnSummit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSummit.Click

        Dim strFormText As String = Me.Text

        Dim clsMember As New clsMember
        clsMember.Generate_New_Member(Me)

        Me.Text = strFormText

        //some code here

        clsMember = Nothing

        MsgBox("Generate Selesai ...!", MsgBoxStyle.Information, Me.Text)

    End Sub

Very strange, please see the screen shot with remark Me.Text = strFormText


Thank you.
FIRST-SCREEN.PNG
PROGRESS-SCREEN.PNG
SECOND-SCREEN.PNG
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I'm not seeing it yet either.

What is happening in Insert_To_Genealogy()?
0
 
emi_sastraAuthor Commented:
- I'm not seeing it yet either.
The progress screen show no text as I mention before.

So the last screen (second screen) If I do not restore the form text (me.text = strFormtext)
This is pretty obvious that the :

frm.Text = "ADD NEW MEMBER NO. : " & intCount & _
                       vbCrLf & _
                       "NEW MEMBER : " & strNewMemberId & _
                       vbCrLf & _
                       "SPONSOR MEMBER : " & strSponsorMemberId & _
                       vbCrLf & _
                       "UPLINE MEMBER : " & strUplineMemberId

            Application.DoEvents()

show empty text.

- What is happening in Insert_To_Genealogy()?
It just insert data to table, no screen operation.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Lol...no.  I see the problem in the screenshots.  

I'm not seeing what is causing the problem yet.  =)

In Generate_New_Member(), add a MessageBox after Application.DoEvents:

            frm.Text = "ADD NEW MEMBER NO. : " & intCount & _
                       vbCrLf & _
                       "NEW MEMBER : " & strNewMemberId & _
                       vbCrLf & _
                       "SPONSOR MEMBER : " & strSponsorMemberId & _
                       vbCrLf & _
                       "UPLINE MEMBER : " & strUplineMemberId

            Application.DoEvents()
            MessageBox.Show("Check the title bar...")

Does the text on the form update while that messagebox is showing?
0
 
CodeCruiserCommented:
And how do you think the form title is going to show all that text including the line breaks?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
On my system the line breaks get ignored and it all gets displayed in the form title bar.
0
 
emi_sastraAuthor Commented:
Hi Idle_Mind,

I am sorry, just back again.
Let me try again by remark it all of the except the frm.text=..... and doevents.

Thank you.
0
 
emi_sastraAuthor Commented:
I see the problem, it caused by vbcrlf.

Thank you very much for your help.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
LOL...

Posts by Idle_Mind: 11
Posts by CodeCruiser: 1

=)
0
 
emi_sastraAuthor Commented:
Oops, I am sorry, did not notice Code Cruiser name.

Should split :

Code Cruiser : And how do you think the form title is going to show all that text including the line breaks?
Idle_Mind: On my system the line breaks get ignored and it all gets displayed in the form title bar.

Thank you.
0
 
emi_sastraAuthor Commented:
Hi Idle_Mind,

Would you please reopen this question for provide fair points.

Thank you.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Don't worry about it bud.  Glad you got a solution.
0
 
emi_sastraAuthor Commented:
I have requested Moderator to reopen it.

Thank you.
0

Featured Post

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.

  • 15
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now