please explain the difference between the variables assigned at the top of your function and those assigned using the Dim statement
ex. Public Function TestJob (strFName as String)
Dim strLName as String
Please explain diff between FName and LName
Printable View
please explain the difference between the variables assigned at the top of your function and those assigned using the Dim statement
ex. Public Function TestJob (strFName as String)
Dim strLName as String
Please explain diff between FName and LName
Welcome to the VBForums juster21 :)Quote:
Originally Posted by juster21
It depends in which context you mean, they are different in a few ways.
Firstly, a variable that is defined outside a sub or function is considered global (Accessible to all functions and subs).
The ones that are defined within the function are called perameters, these are used to pass non-global variables inot a funciton.
If you cna be more specific about what you wna tot know it would be easier to answer.
Cheers,
RyanJ
Welcome to the forums juster21.
strLName is local to the function itself.
strFName is passed to the function from the calling routine. Example:Now, within the function, strFName = "Hack" and strLName will equal whatever it is set to when it is used within the function.VB Code:
Private Sub Command1_Click() TestJob "Hack" End Sub
I guess I'm confused with what I would use "Dim" for versus what I would include in the Function name....i.e. Public Function TestJob(HERE)
Quote:
Originally Posted by juster21
Aj, OK.
Dim tells VB to create a local variable within a function (Or, outside them in soem cases).
When you declare them in a functions decleration you could say they are like persuado variables, all they do is allow you perform opperations on other variables that are passed into a function when it is called :)
It can be kind of hard to explain and understand... ;)
Cheers,
RyanJ
I'm writing a job that will be pulling several first names, last names, phone numbers, addresses, ages, etc. Could you give me an example of what this might look like to make sure i'm on the right page?
Where are you pulling them from? Database? What kind of database?Quote:
Originally Posted by juster21
Text file?
If you are pulling them from a database, you may not need a sub or function. A straight SQL query may suffice.
If you are pulling them from a text file, then you may, depending on the application needs, need to do some string parsing in which case a function or a sub may be needed.
pulling from an MSAccess DB
So you know how to write an SQL query?Quote:
Originally Posted by juster21
Public Function Add_People(ctl As Control) As MyRetVal
Dim strLName As String
Dim strFName As String
This is a snippet from what I have...any benefit in having something in Dim statement as opposed to on top?
You are talking about the difference between a local variable and a passed parameter.
The local variable can only be used within the Function, but the parameter may be passed from anywhere within your project that is it permissible to call the function.
Both have their benefits, but attempting to compare the two is like attempting to compare apples and oranges. They have completely differant meanings and purposes.
Resolved