944,008 Members | Top Members by Rank

Ad:
Nov 21st, 2005
0

HELP! What does this mean.......?

Expand Post »
Hi everyone,
I have a question about Visual Basics.........

When do the following events occur with a form object: Load, Unload, Activate, Deactivate, GotFocus, LostFocus?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
student2005 is offline Offline
1 posts
since Nov 2005
Nov 21st, 2005
0

Re: HELP! What does this mean.......?

Almost sounds like you are needing answers to a homework assignment, but since I give every one the benefit of the doubt, here are the answers to those questions:

A static variable allows the variable to maintain it's previous value through repeated raises of an event. Meaning that, if you have a variable say "X" and you have a command button. If you add the code snippit to the command button:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. x = x + 1
  2. msgbox x

If the variable X is NOT Static, you should always get the same response (which in this case would be one), because every time the event finishes (every time the code in the button is done running) it destroys all the local variables. So, Every time you click the button, the variable gets re-created, as nothing, and then has 1 added to nothing. It doesn't take a math teacher to know that 1 plus nothing is 1. So, it will always be one, because it's always erased when the code is done.

However, Should the variable be "static" then it will keep it's value until the program terminates, or the value is over-written by the programmer. If, in the code above, the variable X where to be static, then it would constantly add 1 to X's previous value. So, the first time you click the button, it would show 1, the second time, 2, and so forth and so on. Basically, static allows the variable to keep it's value while the program runs.

The difference between passing variables byref and byval, is the ability for the sub or function to manipulate variables. If you pass a variable byval (by it's value), then you are making a xerox copy of the variable, and sending that information to the function. So, even if the function decides to alter the information I have sent to it, the variable that I passed to it, will never be able to be changed. Because the truth is, I never passed it a variable (if it's byval), I only passed it the VALUE of the variable.... not the variable, I only gave it a copy, not the original.

Passing variables byref (by their reference) allows the function to alter the contains of the variable. This all has to do with "scope", and is a really good practice. If I write a function that I want to be able to change the variable in question, so that I don't have to make that change in the main code, I can pass it by reference. Byref is the direct opposite of byval. One is passing a copy of the information to the function, and the other is actually sending it the original data. Understanding byref and byval makes more sense in a language more in depth than VB, such as C or Perl, where pointers and other factors can play a role in programming scope, but for the sake of simple understanding, byval is giving the function a copy of the data, and byref is giving it the actual original data. If changes the copy, no big deal. The original is still in tact. If it's byref, and it changes the data, the data is changed for good.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Nov 22nd, 2005
0

Re: HELP! What does this mean.......?

Hi,

For the even order I found this in MS Access help but I am fairly sure the order is the same in VB.
When opening a form: Open => Load => Resize => Activate
When closing a form: Unload => Deactivate => Close

And quoting the help file:
"When you switch between two open forms, the Deactivate event occurs for the first form, and the Activate event occurs for the second form. If the forms contain no visible, enabled controls, the LostFocus event occurs for the first form before the Deactivate event, and the GotFocus event occurs for the second form after the Activate event."

Hope this helps

Yomet

BTW Comatose - I think you might have posted that very involved reply in the wrong thread, could I be correct?
Reputation Points: 16
Solved Threads: 10
Junior Poster
Yomet is offline Offline
134 posts
since Nov 2005
Nov 22nd, 2005
0

Re: HELP! What does this mean.......?

Hmn,

Strangely enough, the questions that I answered actually were posted! It looks as if he must have edited the thread (or someone else did), and changed the original post :eek: . Strange.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Nov 22nd, 2005
0

Re: HELP! What does this mean.......?

That was kind of what I suspected but I wasn't sure. Howcome someone can modify a posting after a response has been given? I think that should be blocked.

Have fun

Yomet

P.S. Student2005, or whoever modified the original posting - please do NOT modify a posting that has a reply, instead just add a reply to the end of the thread. That way everyone can follow what actually happened.
Reputation Points: 16
Solved Threads: 10
Junior Poster
Yomet is offline Offline
134 posts
since Nov 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Quickpak error when porting vb6.0 app from 98 to xp
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: problem with Sendkeys





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC