Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Suppose I have a module
module module_1
end module module_1
And another module which uses the first module.
i wrote it in this way (use module in the main section)
module module_2
use module_1
contains
function func_1
end function func_1
subroutine sub_1
end subroutine sub_1
end module_2
or should i write in this way (use module in every function and subroutine)
module module_2
contains
function func_1
use module_1
end function func_1
subroutine sub_1
use module_1
end subroutine sub_1
end module_2
Answering what you should do is quite opinion-based and hence off-topic. Technically, either is possible.
What we can tell you is the difference. If you use module_1 in the whole module, it will also be acessible through host-association in any future function or subroutine you add into module_2. It is also use-associated and available for all type definitions and module variable definitions in module_2. You might want that, you might not want that. The decision is only up to you. I have certainly used either possibility many times.
If you have reasons to restrict the namespace pollution by only using module_1 in the function and the subroutine, just go ahead and do that. But the reasons must be evaluated by you, there is no universal recipe.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Let there be class Foo which has method isUpToDate(). The method is called multiple times in the application, and when called, is always inverted. I.e., if(!foo.isUpToDate()) { ... }. If the method is refactored to isNotUpToDate() (to avoid putting ! on every call), would it be a good or bad practice?
Edit: To avoid only-opinion-basis, could someone share a reference to some respectable source?
I usually recommend not to use negation in a function name. This is because double negation can become hard to read.
If you use Not in your function name, here is how you would check something is actually up to date.
!foo.NotUpToDate(...)
Thus by trying to avoid negation, you opened the door to double negation; this is bad.
To avoid double-negation, write functions and methods that check the positive statement and use your language not operator.
Like Olivier Melançon said using Not in a function name is not recommended because of double negation. If you only use the inverted form there is usually a better name for the function.
In your case i would suggest using something like NeedsUpdate(...) or IsDirty(...)
No it is not. you should write code in a way that is more understanding and self explained so when someone else(or even yourself after sometime) just just look at your code (even without reading the code documents) he will understand that foo.isUpToDate() determine whether the class is update or not. using ! is not something bad and i guess isUptoDate less confusing than isNotUpToDate However it is up to you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I don't know where to start with this. If there is a way, all I need is an object name or collection name, so I can look up the feature on Microsoft's site, and go from there. But, searching there directly didn't turn anything up.
You're probably looking for the VBE Extensibility Library.
However note that depending on what you're actually trying to do ("modify other VBA code"), it may be very hard, if not impossible to implement.
The library will let you iterate modules, locate their members, pull the actual code into strings (from entire modules or just a given procedure)... but that's as granular as it gets.
If you're trying to do anything that requires understanding of the code's semantics, the VBIDE API won't be enough: you need a lexer and a parser for that... and I've yet to see a successful lexer/parser for VBA, written in VBA.
Good luck!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am fairly new to Objective C and wonder if most people remove or don't remove unused methods. For example, when I create a UIViewController, there are stub methods that I often don't use, and I want to remove them.
You can remove them if you'd like. However, if you leave them in, make sure a call to super is performed in each method so that you don't lose the default implementation. This means you want your empty (for now) method to extend, not override, the functionality of that same method in parent class.
Edit: Having a method implementation that does nothing other than call the same method on super is equivalent to removing the method all together. Super will then be called by default.
I remove them along with all dead code. They just clutter the working code and reduce readability.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have written
sub main ()
'some code goes here
end sub
This is the Module that I defined in the sheet1.And Yes I have only one workbook opened and in the userform1 I have given a command button Ok and when ok is pressed , The main function in sheet1 should be called
sub CommandButton1_Click()
call sheet1.main
end sub
I have tried these The problem Iam facing is , The code works sometimes and sometimes throws an error saying that an undefined object or not set with Occured.Why the code is working for sometimes and not for sometimes? Do i need to make any changes to make it work everytime ? Thank you in advance
The one thing I've found that makes my VBA programming easier is to always fully specify the object you're trying to manipulate (well, except maybe the top-level Application).
That means you should use something like Workbooks(0).Worksheets("Sheet1").main instead of relying on the active workbook.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
The question says it all really.
What are the differences between these two methods that appear to carry out exactly the same function?
Is there guidance to say which should be used or are there conditions when you may use either?
The FileSystem.MoveFile has some more options than File.Move, like for example optionally showing a progress dialog, and creating the destination folder if it doesn't exist.
If you just want to move or rename a file, the File.Move method will be called in the end whichever you use, so calling it directly means slightly less overhead.
I believe they have near-identical functionality. Most people I've seen would prefer to use the latter, because "MyComputer." is a VB.NET-only construct, whereas File.Move is used in both C# and VB.NET. This makes it easier to get help, and easier for C# coders to read the VB.NET code and vice-versa.
I haven't checked My.Computer.FileSystem.MoveFile, but you can state if they are differences moving html files with associated images directories., because File.Move just move the file, but doesn't move the associated directory