Solved

Clear Public Property VB.NET

Posted on 2014-11-04
6
175 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
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!

 
LVL 63

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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