So if I read this correctly.
This is a function that will return a value and the value will defined as a String.
The function has arguments which are,
1. string which is defined as a String.
2. start as a Long (long number)
3. an optional argument that called Optional.
The question I have here, which is also the question I will have eventually with the Score Keeping database we discussed a week or so ago, …is how to I trigger the function (such as the function in the score keeping data base) and How do I pass the variable, which in this case are “string” and “start”. I am working my way through the book when work is not overwhelming so I am guessing I will eventually get to it.
I am connecting the dots but they are not all connected yet.
Thanks,
Bill
Bill Singer
From: MSAccessProfessionals@groups.io <MSAccessProfessionals@groups.io> On Behalf Of Duane Hookom
Sent: Tuesday, March 23, 2021 10:56 AM
To: MSAccessProfessionals@groups.io
Subject: Re: [MSAccessProfessionals] Going through Book.
If MS didn't have a Mid() function the declaration might look something like:
Public Function Mid(string As String, start As Long, Optional [ length ] As Long) as String
The arguments in []s are optional which you can also use in your own user-defined functions
Duane
From: Bill Singer <Bill.Singer@at-group.net>
OK, that helps. So in
Function modIF_IF1(Rating As Long) As String
“Rating” is the argument I need to supply and it is defined as Long and the result of the Function modIF_IF1 will give me a result that will be defined as a String.
From: jebryme
Hi Bill!
The basic difference between a function and a sub is the function returns data. In your example it will return a string. You want to use functions when you plan to use the data without storing it in the underlying data for example you can use a function as a field in a query to manipulate the data. A sub on the other hand returns no data and is often used to edit records or add records in the data.
I know to how enter the argument from the Immediate window. Next I am going to have to figure out how to pass a variable from a query or another VBA program.
Thanks for your help.
Bill
Minnesota
Access 365
From: Bill Singer
Can someone help me to understand this.
I am going through the book Access 2010 VBA programming Inside Out and I come across to ways to do the same thing (I believe).
I am trying to understand the difference between FUNCTIONS and SUB ROUTINES and whey the first statement is different (and when to use each).
Here is the Sub example.
Sub modIF_IF_Simple(Rating As Long)
Here is the Function Example
Function modIF_IF1(Rating As Long) As String
What is the difference and why is the “As String” needed at the in the function and not the sub.
Thanks,
Rookie,
Bill Singer
Minnesota
Access 365
Tidak ada komentar:
Posting Komentar