Easy Form load question

chadzilla

Member
Joined
Aug 29, 2007
Messages
6
Programming Experience
1-3
Hey all.

I'm very new to VB.net, and the way everything works. I have a very simple question, so here goes.

I have a simple application that has 2 forms. On the first form the user inputs 2 numbers. I then pass those 2 numbers to the second form, and do some calculations and out put that data.

I have the code that does the calculations in the form load section on the second form. The user can then hit a button to take them back to the first form.

I am using

form1.visible = true
me.visible = false

to achieve that.

The program works just fine the first time because form2 loads when I set it to visible the first time, but the second time it doesn't work. I assume that is because form2 has already been loaded, and I am not unloading it by setting the visible property to false.

So here is my question. How do I unload the form so that the second time a user runs my program, the form load code executes?

Thanks for any help!
 
I think you might need a third form to tie both forms together. You'll have to call both forms from within this 3rd form and keep track of data being passed around there.
 
Very funny Makavelli ;) No, you don't need a third form.

Why do you need form Load to execute if you only hide/show forms. What is it you do in Load that have to be done again? Don't you think this could be done otherwise? A property? A method?
 
If there is a better way to do this instead of using form load..I am all ears.

What I am doing is taking 2 numbers from the first page, doing about 30 or so math calculations and then displaying them on the second page.

This is going to be budget software. The user inputs the lot cost and the appraisal value for a house. Then I do some calculations to tell them how much to budget for each item...IE framing, plumbing, electrical, yadda yadda yadda.
 
so how do you pass data now, yadda?
 
Wouldn't it be better to pass the data directly to the form? You can write a property or two for this. You can also call the method that does the math from the setter.
VB.NET:
Private newPropertyValue As Integer
Public Property NewProperty() As Integer
    Get
        Return newPropertyValue
    End Get
    Set(ByVal value As Integer)
        newPropertyValue = value
        DoMath()
    End Set
End Property
(write "property" and press TAB and you get the above structure, and can just change the name and type easily)

You can also use parameters of a method, like Public Sub DoMath(param1 as string, param2 as integer) and call this on you form instance: frm.domath("hi",2).
 
What I am doing is taking 2 numbers from the first page, ...
First, be careful of your wording. A page usually refers to a web page; verify this is a winform application.
Second, if this is a winform app, why one whole form for just entering two numbers? Why not just have one form?

However, Don't let me dissuade you from learning how to pass data between forms as this knowledge is valuable and I'd say questions regarding such are one of the most asked questions here. Due to this, I have a link to a set of articles describing several techniques in my signature that I suggest you read. I'll post it here again in case I change my signature: Multiple Forms.
My comment about one form was a suggestion for improving the application architecture.
 
This is actually a Pocket PC / PC application. The part I am working on right now is the pocket pc part.

The reason I was using 2 forms was because I need to output about 60 fields of data along with labels for each field. IE

Framing cost = (house cost - lot cost) * 20%
Plumbing cost = (house cost - lot cost) * 3%
Electric cost = (house cost - lot cost) * 2%

I am getting house cost and lot cost from the first form. Then when the second form loads I do all my calculations and populate the appropriate labels. I hope that makes better sense.
 
Thread moved to Compact Framework category.

It's always a good idea to say which platform you are working in; the compact framework doesn't include all classes/methods available in the standard framework. :)
 
Back
Top