Can't assign a property from a module

Hello

I have a form called Mainform and a module called module1.

On the form, there is a statusbar with a label and a progressbar.

Now I have this code in the module:

'// Place a progressbar an our statusbar

Public Sub provide_status(ByVal text As String, ByVal complete As Integer)

Mainform.ToolStripProgressBar1.Visible = True

Mainform.ToolStripStatusLabel1.Text = text

Mainform.ToolStripProgressBar1.Value = complete

End Sub

'// Please call this when your process finishes

Public Sub status_finish()

Mainform.ToolStripProgressBar1.Visible = False

End Sub

I call the first sub from Mainfrm. But it doesn't work. It just does nothing. I had this problem using VB.NET 2003 too. But there is no warning nor an error is raised.

What's up

Can anyone explain me how to do such things in .NET WITHOUT doing great code.

Thanks.




Answer this question

Can't assign a property from a module

  • D-Rain

    1) This routine has to be accesed in various 'add-ins' I will have

    2) complete is the amount of percentage (0-100) the process is completed

    Thanks.


  • unionize

    Ok

    Yes, the code worked well. But since I have to access various Mainform's and/or other form's properties, this isn't just the way. I have to access the properties form a render-loop sub of a 3D engine.

    I've had this issue a year ago with VB.NET 2003, but solved it. (I imported a VB 6 project, and Vb.net automatically created the code necessary for this to work.)

    Can this also be done in VB Express

    Any help is apreciated.



  • Rajavanya

    I'm curious about what your problem is.

    I did a little sample which had a MainForm containing 3 buttons and a status bar. The buttons are to display a message in status bar (ProvideStatus), Hide the status bar (Status_Finish) and to create an instance of Form2,

    Form2 had a single button on which updated the status bar on the mainform.

    The following is the code and the methods can be called from either form resulting in the mainform statusbar being updated. I am storing a reference to mainform in the module and then refering to this in the methods.

    This would seem to be what you are trying to do. In you code you refer to mainform. Is mainform the name of you form class or the instance of the class.

    Try this code out and see if it is doing what your looking to achieve.

    Public Class MainForm
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Module1.MainformVariable = Me
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ProvideStatus("test text", 50)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Status_Finish()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim x As New Form2
    x.Show()

    End Sub
    End Class

    Public Class Form2
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ProvideStatus("form2 - Mainform", 75)
    End Sub
    End Class


    Module Module1
    Public MainformVariable As MainForm '//Reference Variable

    Sub ProvideStatus(ByVal text As String, ByVal complete As Integer)
    MainformVariable.ToolStripStatusLabel1.Text = text
    MainformVariable.ToolStripProgressBar1.Visible = True
    MainformVariable.ToolStripProgressBar1.Value = complete
    End Sub

    Sub Status_Finish()
    MainformVariable.ToolStripProgressBar1.Visible = False
    End Sub
    End Module


  • James McKinnon

    In all probablity... yes.



  • ParkSys

    hi,

    Is your problem solved if yes, could you please mark it as answered

    Thank you,
    Bhanu.



  • neuling700

    A couple of thoughts.....

    1.) Why is this routine in a common WHy not have it in the mainform

    2.) Mainform.ToolStripProgressBar1.Value = complete

    What is complete

    Have you single stepped through this in the debugger it may be getting a quiet exception and returning early.....



  • Paolo Pialorsi

    Here is what I have done:

    Public class Foo

      Public Method A

      Public Method B

      Public Method C

    End Class

     

    In the common do this

    Public CommonClass as new Foo

    In the other classes that need them

     dim Name as WhateverType = CommonClass.MethodA

    Also in the MainForm you can do this:

    Public Sub Doit()

    Me.ToolStripProgressBar1.Visible = True

    Me.ToolStripStatusLabel1.Text = text

    Me.ToolStripProgressBar1.Value = complete

    End Sub

    The latter is the most appropriate.

     



  • TroyMac

    Yes.

    Hm. I'll give it a try.


  • CKa

    Hi.

    The problem was solved. :)

    That was EXACTLY what I needed. Huge thanks!

    The reason of my problem was that I, prior of using visual basic 2005 I used VB5 and VB6. So, I got very confused about the way the new system works ...

    Again, thanks!



  • Can't assign a property from a module