If by passing variables you mean passing them and not using them? please clarify your question...but if so
There are two general ways to pass a variable...
In Visual Basic speak they are By Value and By Reference
In C speak there is passing a variable and passing a pointer to a variable
Using VB:By Value or C: Passing:
+/-) The function will not be able to edit the variable you give it
-) A copy of the variable must be created this takes more ram and calls to allocate the space etc... slower but not really noticeable
Using VB:By Reference or C: Pointers:
+/-) The function can edit the variable you pass
+) No copy is made and the memory address of your variable is passed to the function
When you pass 'By Value' you are giving the function a copy of the variable so if have the following VB code:
...
sName = "Bob"
bResult = CheckMyName(sName)
MsgBox sName
....
Public Function CheckMyName(ByVal sPName) As Boolean
sPName = "David"
End Function
Now yes im using plain old VB code here... but your question wasn't exactly full of information to help with answering it :)
That code will simply show a message box with "Bob" as it passes the sName variable by value so it makes a copy... now if change the function just a little...
...
sName = "Bob"
bResult = CheckMyName(sName)
MsgBox sName
....
Public Function CheckMyName(ByRef sPName) As Boolean
sPName = "David"
End Function
This code will show a messagebox of "David" as we passed the variable by reference
hope you get what i mean... if not, ask and i can clarify
2006-11-26 12:22:22
·
answer #1
·
answered by Anonymous
·
0⤊
1⤋
I noticed you had a few questions out about programming...
there are no disadvantages of passing variables. there are no advatanages to passing variables either. passing variables is just what you do in code.
For example... *wink*... suppose i wanted to print the numbers 1 through 5 to the screen.
i could write some code that would look like this:
Console.Write(1);
Console.Write(2);
Console.Write(3);
Console.Write(4);
Console.Write(5);
the numbers that i passed to the function are all constants. I can't change the value of 1, or 2, or 3 etc... they're all constant values. (hence the term constants)
if i used a variable (which comes from the word varies) i could rewrite the code like thie
int x = 1;
Console.WriteLine(x);
x++;
Console.WriteLine(x);
x++;
Console.WriteLine(x);
x++;
Console.WriteLine(x);
x++;
Console.WriteLine(x);
x++;
The output would be exactly the same as the last segment of code i just showed you. This is true because as the program runs, x is increment by 1 each time the "x++;" statement is executed.
This code is a little bit redundant. I can easily rewrite this code using a loop.
int x = 0;
while(x < 5)
{
x++;
Console.WriteLine(x);
}
code like this is much cleaner and easier to read. as an experienced programmer, i can tell that between those curly brackets x will vary between 0 and 5.
loops like the one above is very common in programming. it is so common that authors of these programming languages have decieded to make write a special kind of loop that will do the exact same thing only in a cleaner and neater fashion.
for(int x = 0; x < 5; x++)
{
Console.WriteLine(x);
}
as you can see, this takes a lot less space to write. this is called a for loop. the previous loop is called a while loop.
the for loop has three parameters. these parameters are seperated by semi-colons. the first parameter lets the for loop know what you are using as the control variable. the next parameter is what the for loop uses to test to see whether or not it should terminate, or stop looping. the thrid parameter tell the for loop what to do to change the control variable.
the first parameter that i'm passing to the for loop is "int x = 0". the second parameter that i'm passing to the for loop is "x < 5". the third parameter that i'm passing to the for loop is "x++".
if you're just starting to learn how to program (and have no prior experience), i would suggest going to a local bookstore and buying a good book on the language you're studying. You shouldn't buy your first book off the internet. You should go to the bookstore and flip through a couple pages and see how the author talks about programming. You'll find it easier if the author writes as if they're sitting right next to you sipping a cup of coffee and guiding you through the learning process.
Best of wishes.
2006-11-26 16:50:43
·
answer #2
·
answered by Anonymous
·
0⤊
1⤋
As the word goes "Variables" mean a value that keeps on changing from time to time.
The advantage is that you can recall the currrent value by calling the variable.
e.g. If I want all the odd numbers, A=1 and I add 2 to A for every iteration to get odd numbers, then calling the variable A would give me its current value(the last value at end).
The disadvantage is that you cannot get all the values that the variable has undergone unless you have stored it at each phase of operation.
e.g. all odd numbers less than 10 would result in A = 9 with end result. But to use or save all the values, you will need more such variables or much better way something called as Lists. that would give you result 1,3,5,7,9.
Hope that helps you understand.
2006-11-26 10:55:50
·
answer #3
·
answered by fuse 2
·
0⤊
1⤋
heavily pondering the ramifications of any law takes time. The Congressmen have staffs to help them circulate over upcoming rules and make exams of its features, sturdy or undesirable. One shrink back of an prolonged-drawn out technique is it supplies opportunistic politicians of undertaking to stick their beef initiatives onto the bill that has little to do with the unique reason. additionally, it may basically be that the desire extremely is prompt. yet i think of this reasoning could hardly be used. If there is an instantaneous desire, call a church or volunteer alleviation employer. The reaction would be quicker. i think of incredibly some the fund raising they do coincides with dinners and lunches with lobbyists. that's an excellent use of time. they are in a position to strengthen money for his or her reelection and choose which expenditures to pass on the comparable time.
2016-12-10 16:37:18
·
answer #4
·
answered by ricaurte 4
·
0⤊
0⤋