Solved

Clear Public Property VB.NET

Posted on 2014-11-04
6
158 Views
Last Modified: 2014-11-09
Hi I have an application where I am using Public Property x As String to carry information from one form to another. The issue is when I get back to the beginning it is remembering the values instead of accepting new ones. Is there a way to clear all values of Public Properties on the last form?
0
Comment
Question by:takwirirar
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:ReneD100
ID: 40421701
What do you mean with 'when I get back to the beginning?'
0
 
LVL 1

Author Comment

by:takwirirar
ID: 40421754
I have 7 forms. Step 1, 2, 3 etc. So I could set a Public Property at Step 2 then carry all the way to Step 7 however when I press Finish at Step 7 the application comes back to Step 1 again.
0
 
LVL 5

Expert Comment

by:ReneD100
ID: 40421862
I'm still confused - are we talking about 7 different forms or 7 instances of the same form? And is the property defined on the form or in a separate class? If we have 7 instances, then each instance will have it's 'own' property x and thus it's own value. The fact it is 'public' just means it's accessible from 'outside'. If you need the 7 forms to store in a common variable (and thus overwrite) you could either carry it over when the form gets closed, or you could created an application wide (global) variable. In this case you add a module and define a public string there.
Hope this helps a bit.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40421865
Can you post some code to show us what you are doing so that we have a better understanding of your needs.
0
 
LVL 1

Accepted Solution

by:
takwirirar earned 0 total points
ID: 40421938
Hey guys, thanks for all your responses. I just found my error.  I was running my code under Form_Load instead of Form_Activated http://msdn.microsoft.com/en-us/library/system.windows.forms.form.load(v=vs.110).aspx showed me that the Load is only for the first time instead of every time the Form runs.

The erroneous code was

Public Class Step_1
    Public Property ProductType As String

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ProductType = TextBox1.Text
        Me.Hide()
        Step_2.Show()
    End Sub
End Class

Public Class Step_2
    Public Property ProductType As String

    Private Sub Step_2_Load(sender As Object, e As EventArgs) Handles Me.Load
	Label10.Text = Step_1.ProductType

	Me.Hide()
        Step_1.Show()

    End Sub
End Class

Open in new window


Hopefully that make sense
0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 40431035
Found the error was to do with my code
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

17 Experts available now in Live!

Get 1:1 Help Now