|
-
May 26th, 2005, 01:31 PM
#1
Thread Starter
Junior Member
simple help needed
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
 -juster21-
You are the First Brigade!!
-
May 26th, 2005, 01:35 PM
#2
Re: simple help needed
 Originally Posted by juster21
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 
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
Last edited by sciguyryan; May 26th, 2005 at 01:39 PM.
-
May 26th, 2005, 01:36 PM
#3
Re: simple help needed
Welcome to the forums juster21.
strLName is local to the function itself.
strFName is passed to the function from the calling routine. Example:
VB Code:
Private Sub Command1_Click()
TestJob "Hack"
End Sub
Now, within the function, strFName = "Hack" and strLName will equal whatever it is set to when it is used within the function.
-
May 26th, 2005, 01:45 PM
#4
Thread Starter
Junior Member
Re: simple help needed
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)
 -juster21-
You are the First Brigade!!
-
May 26th, 2005, 01:49 PM
#5
Re: simple help needed
 Originally Posted by juster21
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)
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
-
May 26th, 2005, 01:51 PM
#6
Thread Starter
Junior Member
Re: simple help needed
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?
 -juster21-
You are the First Brigade!!
-
May 26th, 2005, 01:55 PM
#7
Re: simple help needed
 Originally Posted by juster21
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?
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.
-
May 26th, 2005, 01:59 PM
#8
Thread Starter
Junior Member
Re: simple help needed
pulling from an MSAccess DB
 -juster21-
You are the First Brigade!!
-
May 26th, 2005, 02:01 PM
#9
Re: simple help needed
 Originally Posted by juster21
pulling from an MSAccess DB
So you know how to write an SQL query?
-
May 26th, 2005, 02:15 PM
#10
Thread Starter
Junior Member
Re: simple help needed
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?
 -juster21-
You are the First Brigade!!
-
May 26th, 2005, 02:21 PM
#11
Re: simple help needed
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.
-
May 26th, 2005, 08:52 PM
#12
Thread Starter
Junior Member
 -juster21-
You are the First Brigade!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|