| | |
HELP! What does this mean.......?
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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:
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.
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)
x = x + 1 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.
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
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?
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?
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
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.
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.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Quickpak error when porting vb6.0 app from 98 to xp
- Next Thread: problem with Sendkeys
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
6 429 2007 access activex add age append application basic beginner birth c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






