Results 1 to 12 of 12

Thread: simple help needed

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    Unhappy 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!!

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: simple help needed

    Quote 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.
    My Blog.

    Ryan Jones.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Sub Command1_Click()
    2. TestJob "Hack"
    3. End Sub
    Now, within the function, strFName = "Hack" and strLName will equal whatever it is set to when it is used within the function.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    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!!

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: simple help needed

    Quote 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
    My Blog.

    Ryan Jones.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    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!!

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: simple help needed

    Quote 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.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    Re: simple help needed

    pulling from an MSAccess DB
    -juster21-

    You are the First Brigade!!

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: simple help needed

    Quote Originally Posted by juster21
    pulling from an MSAccess DB
    So you know how to write an SQL query?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    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!!

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    23

    Re: simple help needed

    Resolved
    -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
  •  



Click Here to Expand Forum to Full Width