If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

VB Multiple Form Passing ?

I'm just learning Visual Basic. It's kind of fun but my VB book really sucks. I've been doing a little searching. And Thought I might ask the great communtity of Antionline. So here goes. I've got this program I'm supposed to do as an assignment.

The main form is supposed to calculate which i got ok. The calculations is done. Then once it outputs to the label captions. I'm supposed to move the answers from the captions to a summary form. The whole point of the summary form is to display today's totals. So everytime there is a calculation on the main form it's supposed to print out to the calculations on the labels, then move to the summary form. Now how do I move the output from the captions on the main form to the seperate summary form? And then how do I keep on adding to the summary everytime there is a calculation?

Option Explicit
'This is were I get stuck, I put in the labels for the output but then what? And how do I keep
' adding totals from the main form everytime there is a calculation?

Private Sub Form_Load()
lblSumParts.Caption = "<insert somthing here>" 'The total amount of parts for the day
lblSumHours.Caption = "<insert somthing here>" ' The total number of hours for the day
lblSumTotal.Caption = "<insert somthing here>" ' The main total from the main form
End Sub

Does antionline have syntax highlighting for posting code? I didn't see anything so I just used the quote thingy.

Its been a very long time since I programmed in VB, but global variables are one option, the other option is to have the objects/variables in one form reference the object/variable of the other form in somewhere that gets called when the user goes back and forth between forms (or if they don't use something like mouse-over (there are better choices than this one, I just don't remember all of the various event options for a form)).

There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

Thanks Simon that was a big help. I got it to show the same info on the 2nd form. I'm gonna put it in a string and that way everytime there is a calculation on form1 it will added it to the string on form2. I'm not sure if it makes anysense but your example did help. I was at the microsoft site looking on diferent ways I could do it. My Visual Basic Compiler doesn't come with the help, which sucks so I usually have to go wondering around.

I should have mentioned this earlier, but I would highly recommend that you avoid the use of global variables where possible. If you can access the data from exisiting objects and variables, it is 'cleaner' to do that rather than create a new and global variable...Object Oriented Programming is 'a good thing'...

Neb

There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

Nebulus and DTech are right in saying that you shoud avoid global variables.
Refering to the other form's variables is one way to do it, but if you wanted to push it one step further, you would call a public sub or function on the other form to update its private variable(s) with the new one(s) you would pass as parameter(s). The public function on that second form would then do whatever logic should be down with the updated variables.

The point of this is that all the logic related to the updating is contained in a single place. Lets say that later you want to have another form update the summary fields, and that you had already added logic that, for example, wrote the summary in a sentence and displayed it on the summary form. On that new form you would only need to call that public sub/function of the summary form where all the displaying logic is contained.