Hi everybody,
On most of the forms I create that have date textboxes, I usually add a command for today's date and yesterday's date.
In the past when I've written the code for each of the buttons, I've written an individual private function for each button (I may have between 1-10 today and yesterday buttons on a given form).
I'm curious, is this way efficient or would it be better for me to write one public function in a module and call that function in the OnClick event for each command button and just pass the textbox as a parameter? I was thinking that I would still have to create a different set of command buttons for each textbox, so I wasn't sure which way would be the most efficient.
Thanks...
4 1598
This is what I came up with. You can use one set of buttons to do all the date controls.
Placed in a module. - Public Function ChangeDate(ButtonVal as Boolean, ControlDate as Date) as Date
-
If ButtonVal Then
-
ChangeDate = DateAdd("d",-1,ControlDate)
-
Else
-
ChangeDate = DateAdd("d",1,ControlDate)
-
End If
-
End Function
Placed in the Forms Module - Private Sub PreviousButton_Click()
-
Me(ctlName) = ChangeDate(1, Me(ctlName))
-
Me(ctlName).SetFocus
-
End Sub
-
-
Private Sub NextButton_Click()
-
Me(ctlName) = ChangeDate(0, Me(ctlName))
-
Me(ctlName).SetFocus
-
End Sub
-
-
Private Sub Text0_GotFocus()
-
ctlName = Me.ActiveControl.Name
-
Me.PreviousButton.Enabled = True
-
Me.NextButton.Enabled = True
-
End Sub
-
-
Private Sub Text0_LostFocus()
-
ctlName = ""
-
Me.PreviousButton.Enabled = False
-
Me.NextButton.Enabled = False
-
End Sub
Hi Don,
I'm guessing from your suggestion that it would be more efficient to use a module and call the function from a private subroutine, as opposed to writing the same code in multiple private subs.
I actually had a function written to do something similar to what you wrote before, although it's not as nice as what you wrote, but was curious if this was the most efficient route to take.
Thanks for your help...
Your quite welcome beacon.
NeoPa 32,556
Expert Mod 16PB
As far as efficiency goes, calling a public procedure is actually less efficient in terms of code execution (The effect would be entirely negligible though, especially when combined with human interaction).
HOWEVER, it is far, far more efficient as far as development time goes.
I would certainly recommend a public procedure above coding something over and over again.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sara |
last post by:
Hi -
I've been reading the posts for a solution to my query, and realize
that I should ask an "approch" question as well.
We receive our production data from a third party, so my uers import...
|
by: mark |
last post by:
Hello-
i am trying to make the function addbitwise more efficient. the code
below takes an array of binary numbers (of size 5) and performs
bitwise addition. it looks ugly and it is not elegant...
|
by: Dave Rudolf |
last post by:
Hi all,
Normally, I would trust that the ANSI libraries are written to be as
efficient as possible, but I have an application in which the majority of
the run time is calling the acos(...)...
|
by: Tomás |
last post by:
dynamic_cast can be used to obtain a pointer or to obtain a reference.
If the pointer form fails, then you're left with a null pointer.
If the reference form fails, then an exception is thrown....
|
by: Frederick Gotham |
last post by:
Commonly, people may ask a question along the lines of, "Which code
snippet is more efficient?".
If the code is anything other than assembler (e.g. C or C++), then
there's no precise answer...
|
by: burningsunorama |
last post by:
Hi guys!
This is maybe a too 'academic problem', but I would like to hear your
opinions, something like pros and cons for each approach....
... Recently we've had at work a little talk about the...
|
by: vamshi |
last post by:
Hi all,
This is a question about the efficiency of the code.
a :-
int i;
for( i = 0; i < 20; i++ )
printf("%d",i);
b:-
int i = 10;
|
by: OldBirdman |
last post by:
Efficiency
I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm...
|
by: anon.asdf |
last post by:
In terms of efficieny:
Is it better to use multiple putchar()'s after one another as one gets
to new char's
OR
is it better to collect the characters to a char-array first, and then
use...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |