« first day (1697 days earlier)      last day (1483 days later) » 
00:00 - 18:0018:00 - 00:00

12:00 AM
RELOAD!
[rubberduck-vba/Rubberduck] 11 commits. 1 opened issue. 2 issue comments. 132 additions. 26 deletions.
 
 
2 hours later…
2:46 AM
 
3:05 AM
[rubberduck-vba/Rubberduck] build for commit 6ce3d6da on next: AppVeyor build succeeded
Merge pull request #4752 from rubberduck-vba/next

Release 2.4.0
[rubberduck-vba/Rubberduck] build for commit 5d0eeb47 on master: GitHub Pages successfully built your site.
 
@MathieuGuindon FWIW the sidebar on the WP site is wee bit incorrect.
 
argh thanks! :)
 
posted on January 28, 2019 by Rubberduck VBA

Unlike quite a number of Rubberduck releases, this time we’re not boasting we above a thousand commits: this time we’re looking at well under 300 changes, but if the last you’ve seen of Rubberduck was 2.3.0 or prior, …trying this release you’ll quickly realize why we originally wanted to release it around Christmas. So, here’s… Continue reading Rubberdu

 
> They’re back, and this time it does work, and it’s another game changer: Rubberduck users no longer need to export any code file to modify module & member attributes!
I think that's inaccurate - we still have an open PR to do that automatically
which will definitely come in next version.
So for now they get inspected and flagged but fixes will be manual (I think?)
Nice post, Mat!
 
Nah, tested it with Battleship, works fine
 
3:41 AM
hm. then I guess I didn't understand the PR - I thought the open PR would write the attributes.
What we have so far is correct behaviors for the annotations.
 
The PR will reduce the amount of back and forth needed to fix both directions, but it ends up working as it is now
 
Cool!
 
now that 2.4's out, we need to merge master into next to ensure the next gets the bump, etc., right?
(and also, thanks, Mat!)
 
3:55 AM
that was it :)
 
no, other way around
?
 
oh
right
 
or maybe that's not necessary?
 
meh, might as well
 
3:56 AM
the master shows it's 1 commit ahead, though.
i assumed it was because of the version bump.
 
no it's the merge commit
 
Rubberduck v2.4.0 https://rubberduckvba.wordpress.com/2019/01/28/rubberduck-v2-4-0/
 
4:15 AM
[rubberduck-vba/Rubberduck] build for commit 5d0eeb47 on master: AppVeyor build succeeded
Merge pull request #4753 from rubberduck-vba/master

Merge pull request #4752 from rubberduck-vba/next
 
ok, master & next are even now
 
Cool, we'll have to work out what goes in next now. I know @Comintern's been pining for the deployment PR to go in sooner than later but I'd rather get others' opinions.
 
so, what's the first PR to go?
lol
@this it still says though?
 
that's my #belts'n'suspenders talking
I put it up as wip mainly because I wanted to get others to test it
because this is unfortunately very untestable.
 
@this My boss may have different opinions about that, but yes...
 
lol
 
this has been making rounds in other media and I thought it pretty telling:
 
5:05 AM
it's up here:
TTGTB
 
 
2 hours later…
7:26 AM
@this My open PR about recovering member attributes tries to fix the following problem. Whenever we rewrite a module, we replace the whole text in the module. Doing this via the code pane makes the VBE remove all member attributes.
The PR introduces an automatic second rewrite that recovers the member attributes.
 
 
3 hours later…
10:12 AM
@MathieuGuindon I would like #4733 to be merged rather sooner than later.
It cannot really break anything because there is no user of the new service yet.
I would like to rebase my branch for an enhancement based on it at some point.
 
 
1 hour later…
11:20 AM
Introduce the ISelection service

This service is a provides access to the active selection and selection of individual modules without involving COM wrappers directly; the interface only uses QMNs and selections.
[rubberduck-vba/Rubberduck] MDoerner pushed commit 1e23c302 to next: Log failed Try* in SelectionService
Merge pull request #4733 from MDoerner/IntroduceSelectionService

Introduce the ISelectionService
 
11:35 AM
Out of 9 open PRs, only 5 are neither WIP nor conflicting. That's 4072 (Refactoring dialog refactor), 4582 (Deployment enhancements), 4699 (Clean up persistence service), and 4717 (Inspection toolwindows overhaul). Both 4072 and 4582 are more than a month old and will likely have impacting changes. I'd like to merge those 2 first to ensure they all get field tested as soon as possible.
However, if we merge them, then it means that if we discover any hotfixes needed for 2.4.0, they'd have to go into a separate branch in order to merge into 2.4.X release separately to ensure those don't get into the green release due to hotfixes.
 
12:23 PM
@this Thanks for merging.
I think it would anyway make sense to open a hotfix branch from master should hotfixes be required.
No need to delay further development.
I will resolve the resx conflict of me attributes recovery PR tonight.
I might also pull from #4612, resolve the conflict and open a PR to inarion's fork.
 
@this we've gone from moderately useful instructions to a "sad face" smilie and a QR code. Not sure that's progress...
 
@M.Doerner No problem. If there is no dissenting opinions, I will create a hotfix branch before merging any more PRs. I think that best complement our existing workflow.
@FreeMan IKR?
At least with the QR code, you can use your phone to get a KB article (I think?). In oldies day, you had to scrabble down the pertinent information and if you were oh, so fortunate to have another computer handy, to look it up.
 
Considering how heavy the changes are, I'm also in favor of a hotfix branch. That said: this branch can be created if and when the need arises
 
That is true, but I was thinking of a permanent branch
 
Meh
Branches are a dime a dozen
2
 
12:38 PM
@this but "emoji" are oh so cool with all the young kids. (Most of them have no idea how to use them properly, but whateves).
Congrats on the 2.4 release! I've just installed the .4491 hotfix. ;)
 
@Vogel612 I think there's a contributor who has a bit wee too much branches. Probably thinks they're going out of style and must stockpile.
 
That reminds me, I should clean up me local at some point.
 
@MathieuGuindon upvoted.
 
I'm still getting the occasional crash on exit but I've been otherwise occupied and haven't managed to remember to gather the WER reports. I will make a note to self to remember to do so.
however, I have to do my annual self-evalutation. yech. so it'll be a little while longer...
 
12:54 PM
> Rubberduck.Setup.2.4.0.4488.exe (4.03 MiB) - downloaded 39 times. Last updated on 2019-01-28
> Rubberduck.Setup.2.4.0.4490-pre.exe (4.03 MiB) - downloaded 4 times. Last updated on 2019-01-28
> Rubberduck.Setup.2.4.0.4491-pre.exe (4.03 MiB) - downloaded 1 times. Last updated on 2019-01-28
 
@MathieuGuindon That'd be @FreeMan
standing on the bleeding edge on a toe, he is.
 
> I recently upgraded from 2.3.1.4441 to 2.4.0.4488 and I'm reasonably confident that these false positives haven't been showing up before the upgrade.

For reference, the inspection tells me: *An assignment is immediately overridden by another assignment or is never used.*
I hope upon inspecting the following procedures you will agree with me that the above assessment is objectively false. Also please disregard their mostly nonsensical nature - I tried to condense them as far as possible.
> While I'm not sure if that's the intention of the current inspection, I think this definitely should be a different altogether inspection. Something like `InconsistentDimScopingInspection` -- the main problems is that the `Dim` statements are apparently used outside the blocks. For that reason, dimming them inside a block doesn't really make sense.

This inspection is necessary because otherwise it hides a subtle "feature" of VBA -- the `Dim` statement is "global" to the entire procedure, e
> While I'm not sure if that's the intention of the current inspection, I think this definitely should be a different altogether inspection. Something like `InconsistentDimScopingInspection` -- the main problem is that the `Dim`med variables are apparently used outside the blocks where the statements are. For that reason, dimming them inside a block doesn't really make sense.

This inspection is necessary because otherwise it hides a subtle "feature" of VBA -- the `Dim` statement is "global"
> Alright, so I'm totally aware that there's no thing like different scopes within a procedure (`With` blocks may be an exception). The only reason I put the `Dim`s in those blocks is because it seemed the most logical place. (And some of them might even be the result of the `Move Closer to Usage` QF.)

But what about the `IssueWithStaticVariable` procedure? Is this a similar case? If so, how?
> Alright, so I'm totally aware that there's no thing like different scopes within a procedure (`With` blocks may be an exception). The only reason I put the `Dim`s in those blocks is because it seemed the most logical place. (And some of them might even be the result of the `Move Closer to Usage` QF.)

But what about the `IssueWithStaticVariable` procedure? Is this a similar case? If so, how?

Edit: And of course, @bclothier is totally correct. Moving the `Dim` outside of the blocks will ma
> It seems like the code analysis does not take Static locals into account. I'd assume this specific case never worked, though...

Note that the inspection is not about Dim statements, but about assignments. It seems that the code path analysis incorrectly scopes Dim statements to their direct parent node instead of propagating them up the "scope tree".
> I'm pretty sure `IssueWithStaticVariable` is a separate issue (and a legitimate one at that); it shouldn't have had fired any results.

As for inspection results disappearing when the `Dim` statement has been moved outside the block, this is more of a readability issue and a benefit for the programmer, not for the compiler. Seeing it inside a block makes me think it should be confined to only that block. So I want to be warned if I'm misusing a variable outside the block. One way we can do
 
1:20 PM
@Duga This makes me think, though - do we want to also inspect for conditional assignments of the variable which may not be expected?
I've seen code that wrongly assumes that a variable will always have a value assigned due to it being inside a If...Then block to guard against a runtime error or something like that.
 
@this That's me, holding on by a hang nail! :)
 
> > Seeing it inside a block makes me think it should be confined to only that block. So I want to be warned if I'm misusing a variable outside the block.

While I can follow your reasoning, I don't think it's globally applicable. Can I assume your primary coding background is in a language that offers such different scopes? As someone who basically learned coding in/from VBA, I wouldn't have called that misuse. (What, you can tell that from my MCVE? *cough*) I can see the merit in handling it
 
1:50 PM
@this #4717 can wait until I implement changes to address #3960 and #4028.
 
> Indeed - VBA is in the minority when it comes to scoping resolution. Several languages normally scope the declarations to the same block it is declared and consider them invalid outside the block.

Even so, I started with VBA long before I learnt C# so I have been accustomed to the famous "wall of the declarations" that is very commonplace throughout VBA. `Move closer to usage` is one way to fix it but to put it at very first assignment when they are used later somewhere in the procedure fe
 
@Comintern Cool.
 
Pretty sure those were the last 2 outstanding issues for the inspection results that aren't already covered by #4717, although I'll do another check when I go through and make sure the CE pulls closed everything it should have.
 
2:05 PM
Alright. Gonna merge the deployment PR on its own for now, because if this fails spectacularly, I'd rather have to revert only one PR than other PRs.
 
> Just tossing my $.02 in here, the Assignment is not used inspection should not care about the location of the `Dim` within the procedure at all. It is inspecting for a superfluous assignment and nothing more.

Re another inspection for where the `Dim` is placed within the module, if we want to inspect that, IMO it should be opened as another issue and tagged with enhancement. For that one, I'd suggest something more along the lines of "Variable used outside of implied scope", at a hint lev
[rubberduck-vba/Rubberduck] bclothier pushed 20 commits to next (only showing some of them below)
[rubberduck-vba/Rubberduck] bclothier pushed commit dcfd96f2 to next: Clean up the csproj files and try to use solution; put in comment block for future fix and dry the current approach of enumerating the projects
[rubberduck-vba/Rubberduck] bclothier pushed commit 1d78230f to next: Convert fields into parameters to make it a bit less stateful.
[rubberduck-vba/Rubberduck] bclothier pushed commit d8cdb8bc to next: Address review comments and some refactoring
[rubberduck-vba/Rubberduck] bclothier pushed commit 13721382 to next: Reverse the messaging
[rubberduck-vba/Rubberduck] bclothier pushed commit b778c907 to next: Improve logging
[rubberduck-vba/Rubberduck] bclothier pushed commit 374c8e76 to next: Additional bug fixes & tweaks
[rubberduck-vba/Rubberduck] bclothier pushed commit d428c587 to next: Add an explicit nuget restore target
[rubberduck-vba/Rubberduck] bclothier pushed commit 16e7e3e0 to next: Add the missing quotes around exes that has full path.
[rubberduck-vba/Rubberduck] bclothier pushed commit 25c817db to next: Merge branch 'next' of github.com/rubberduck-vba/Rubberduck into DeploymentEnhancement
Merge pull request #4582 from bclothier/DeploymentEnhancement

Deployment enhancements - hopefully make it easier for contributors to ... *contribute*.
 
@Duga looks outside to see if sky's falling -- thinks to himself, not yet. But definitely soon.
 
2:39 PM
[rubberduck-vba/Rubberduck] build for commit f56d14ac on next: AppVeyor build succeeded
> Closing this as this is now made obsolete by PR #4582
[rubberduck-vba/Rubberduck] bclothier is playing around with a project card
> This should be addressed by the PR #4582 but not tested. Reopen if this is still an issue.
> > I'd suggest using the terminology "Implied scope" to describe it.

..but I liked "Hungarian Location" :rofl:

I would add that declaring inside the "implied scope" makes it much easier to later refactor and extract a method manually.
> So, to summarize:
All of the presented cases in the OP are in need of some smartening-up? And examples 1, 2, 4 and 5 warrant a new inspection about *Hungarian Location*, err.. *Implied Scope*.
> So, to summarize:
All of the presented cases in the OP are in need of some smartening-up? And examples 1, 2, 4 and 5 warrant a new inspection about *Hungarian Location*, err.. *Implied Scope*.

Edit:
> I would add that declaring inside the "implied scope" makes it much easier to later refactor and extract a method manually.

Agreed. Also, I've started to notice a certain smell when the same `VariableThatIFoundHardToNameCorrectly` appeared again in later sections of the code: There alw
> @Inarion TBH it looks like the inspection is somehow mistakenly tracking declarations instead of assignments; the reported false positives are indeed false positives - the goal behind this inspection is to warn about cases such as these:

```vb
'If bar Then '' conditional block makes no difference
foo = 42 ' assignment not used
'End If
foo = 74
```

In other words, it means to identify instructions where a variable is assigned, *and then assigned again before the value is read*, i
> @retailcoder That was my understanding as well and what led me to opening this issue. :)

(That tangent on general scoping was interesting and educational, though.)
> @retailcoder but conditional block should be considered for this case, no?

```
foo = 74
If bar Then
foo = 42
End If
```
> @Inarion TBH it looks like the inspection is somehow mistakenly tracking declarations instead of assignments; the reported false positives are indeed false positives - the goal behind this inspection is to warn about cases such as these:

```vb
'If bar Then '' conditional block makes no difference
foo = 42 ' assignment not used
'End If
foo = 74
```

In other words, it means to identify instructions where a variable is assigned, *and then assigned again before the value is read*, i
> @retailcoder but conditional block should be considered for this case, no?

```
foo = 74
If bar Then
foo = 42
End If
```

Granted, this might be a case where it can be better rewritten as:

```
If bar Then
foo = 42
Else
foo = 74
End If
```

but the assignment before the conditional block is a common pattern for ensuring there's a sane value given in case where conditional block don't apply or something like that.
> @bclothier why though? Whether the assignment is conditional or not makes no difference - this is different though:

```vb
foo = 72 'assignment is used in at least 1 execution path
If bar Then
Debug.Print foo
End If
```

IMO the above case shouldn't trip the inspection though. Or should it?
 
3:12 PM
@Duga absolutely not!! You're using foo for something that should be sufficient.
 
yeah, makes sense
 
Is Debug.Print a real use though? It's completely non-functional.
 
> The difference is that in all cases, the `foo` has `72` assigned, which may be used.

In the earlier example, we had
```
foo = 72
foo = 42
```
which would flag a result for lack of use of the first assignment. However,

```
If bar Then
foo = 42
Else
foo = 72
End If
```

shouldn't raise any result, even though there are potentially unused assignment depending on the value of `bar`. This can be transformed into this:

```
foo = 72
If bar Then
foo = 42
End If
```
 
@Comintern I kind of agree in principle that we might not want to count the Debug calls. OTOH, I'm not sure if we should bother until we have AvalonEdit so that we can dim out the Debug statements like R#(?)/VS(?) does.
 
@Comintern I'd say it is... unless... unless we had an option to exclude Debug.Print and Debug.Assert calls from analysis
 
3:21 PM
^
I think we need that first.
 
per-inspection settings :)
 
Both of those make sense. I'm assuming that we aren't treating it specially anywhere else at this point.
 
I can see scenarios where we have variables that are debug-only.
Yeah, I don't think so?
@MathieuGuindon I think you meant to said a can of worms
 
I'm guessing any scenario with a debug-only variable should really be in a precompiler block.
 
3:22 PM
Except.... it can get really fugly
 
@MathieuGuindon Hmmm, sounds fun.
 
@Comintern well there's an idea: "wrap Debug call in conditionally-compiled block"
 
Imagine you have a procedure where you have Debug.Print in 3 places in a procedure.
 
Debug.Print can have horrendous performance penalties in practice because writing to the immediate window is expensive.
 
And I've already got a hint of an idea on how to do it.
 
3:23 PM
so you going to end up with 4 #If blocks in the procedure.
that'd be .... fun.
 
then your procedure is doing too many things ;-)
 
@Comintern FWIW, it's somehow a less problem w/ Access, especially if you ship ACCDE by default. In that case, all Debug statements are automatically stripped out.
 
It can be a huge problem in Excel.
 
tell them to get you a xlsxe file format, then.
:-D
(hmm. I wonder if .xlsb would have the same effect?)
 
3:27 PM
Huh. That's a good question.
 
probably not if you still have the source code.
 
3:49 PM
Morning gents
 
posted on January 28, 2019 by CommitStrip

 
4:05 PM
0
Q: User Confirmation using a Userform Modeless and DoEvents

Lucas Raphael PianegondaCan this be done more efficiently? The code does the following: Do Stuff Show UserForm and ask user to confirm the shown data is ok User can manipulate and controll excel as usual As soon as user clicks the "yes" button "do some other stuff" is called The Module Sub ControlDataUI() Dim Ui ...

 
@Feeds rather blatant iMac there, is that an indictment of Apple users?
 
uh... PSD wasn't a big enough cluestick?
 
@QuackExchange Looking forward to the "why is my code so slooooow follow-up to that one".
 
> @retailcoder I think that the definition you gave of what to report is slightly off, too. I think the following would make more sense.

It should report all assignments in any code path such that in all subsequent code paths the variable is either reassigned before use or never used at all.
 
4:21 PM
@QuackExchange quickie posted
 
That's exactly where I would have gone with that. Everyone seems to forget that you can raise custom events.
 
@Comintern What?!? VBA does custom event?!?
WHY DID NO ONE TELL ME THAT
 
For some values of "everyone"?
 
More likely, the tutorials they used contained only a brief paragraph and obscure example in the last chapter, and they went "meh, I guess I don't need it."
 
Appendix Z or something like that.
 
4:32 PM
Makes me think - does any language used by the same crowd (e.g. non-professional programmers) have the same tendencies? (would say Python but not sure if that's a fair comparison)
 
@Feeds It was bound to be done eventually. #GitDoneWrong
 
@this I'm having a hard time even thinking of a comparable language.
 
I asked because is it the fault of the non-programmer author or is it the fault of the language?
 
@this wait what?!
 
if most VBA coders are basically your Friday afternoon coder, they don't have much incentives to evolve beyond few functions that does the job.
 
4:36 PM
Definitely the fault of the non-programmer author IMO.
 
and would probably see stuff like classes or interfaces or events as "overcomplicating" things.
If all he wanted was to spit a text file out from some web scraped data + his company data.... what's all that nonsense about class then?
One god procedure is good nuff, he'd say.
 
The problem arises when lack of familiarity with language features compels the non-programmer to "re-invent a wheel", which invariably comes out square instead of round.
 
Unfortunately too easy to do w/ VBA.
 
IKR?
There was an SO question over the weekend about how to use Excel's Choose function on a VBA array, and I was like "um... there's a VBA Choose function".
 
lol
 
4:46 PM
OK, since nobody else has mentioned it, I'll bite and ask why you need to know the order that worksheets were added. It sounds like you're trying to treat the worksheets themselves as data, which indicates a design problem. — Comintern 49 secs ago
 
:-)
 
thanks for biting. the question stroke me as weird, but I was more curious about hth I'd do that than wth OP would want to do that
 
Same here. The question is decent in and of itself.
 
In other words, you guys are at the point where you stop worrying about why and more worry about how again.
Simply because how is more interesting because it pushes your limits.
I find programming is a cycle between those two, really.
 
cue that Jurassic Park gif
 
4:49 PM
It just struck me as an odd thing to need - OP is probably doing something weird, and relying on the ordinal of the worksheet is kind of like relying on the name of a database table.
 
so i looked up choose cuz id never heard of it
 
But...
 
and what i see is a wrapper for an array?
 
You mean I shouldn't do select * from FooTable???
 
thats not as good as an array
 
4:51 PM
If it's a UI thing, like keeping the tabs in order on the workbook, what OP probably needs is how to insert a sheet at the correct ordinal.
 
@KySoto sort of
INDEX is a more powerful array-wrapper :)
 
i cant think of a situation id realistically use it
but hten again, i work in access 99% of the time, not excel
 
@Comintern What OP really needs is a programing class.
 
LOL
 
lol
 
4:52 PM
I've been thinking about mine, TBH.
 
think of CHOSE like some kind of Select Case where you can parameterize the branching, and need to hard-code the branches to be Case 1, Case 2, etc.
 
I think after I finish a few classes worth of material, I could get the U I went to to work with me on hosting it.
 
I'm trying to remember if I've ever used Choose.
 
I could work with them to set it up as an associates degree targeting people who want to be career programmers.
 
I am sure I can count the times I used Choose on one hand. I probably used Switch function more.
 
4:54 PM
Yeah, its usefulness is right up there with the Impl operator.
 
Probably should have a kind of code contest to find actual uses for those useless functions. :D
 
I should try writing a procedure sometime that uses all of the bizarro language elements.
 
With the condition being that the use must be legitimate and not convoluted or something liket hat.
That'll be hard to define, though.
 
IOW "Community Challenge: Submit a PR to docs.microsoft.com to improve the shitty examples"?
 
4:56 PM
Now that'd be interesting. That also means you have to actually keep the example short, too.
 
Exp would be hard to work in there, although it does have some oddly specific uses.
 
@Makoto You browse SO on your couch? I laud your productivity as I comment from bed. — TylerH 2 hours ago
 
I've submitted several PR for docs because VBA != VB.
 
ah but it's VBAVB...
 
VBA Impl VB?
 
5:09 PM
Don't think that works. That would work if VBA was a strict subset of VB but I don't believe it is.
(BTW - it's Imp, not Impl)
 
You can see how often I use it.
 
When the VBA example code doesn't even compile...
 
So uh, I was just looking at the WP stats: 2019 is already ahead of 2015 as a whole =)
 
Wouldn't VBA be a strict subset of VB6 though?
 
No I don't think so, because of host application stuff.
 
5:11 PM
That's the OM, not the language.
 
VB6 doesn't have that same context
No, I'm not really thinking of host's OM
 
So more like how the implicit scoping works then?
 
hmm, not sure if there's actually a difference. I'm sure VB has its appobject stuff - I'm thinking more about the project types, the fact that the file doesn't exist independent, the document module types which must be provided by the application.
IINM, VB6 does not have a equivalent for document module?
(there's a UserDocument but that's slightly different, I've been told?)
 
UserDocument is more like the MFC object I think.
 
Right, and also the project stream storage vs. filesystem.
 
5:14 PM
Although in Office, that's essentially what the document types are too, although I can't speak for Access.
 
If I had a better understanding of what MFC object is, other being a massively frustrating crapload, I would be able to answer.
 
Semantics then. I'd still call VBA a subset of the language.
I.e. just because I could use CLang or VS to compile c++ doesn't mean the language is different.
 
Hmm. you might be right from the standpoint of grammar.
 
It's not just grammar though - there are functions that are defined in VB6 that aren't available in VBA.
 
The examples I cited above had nothing to do with grammar, I think.
 
5:18 PM
I.e. WeekdayName
 
Circle and Line come to mind, too nevermind, those are special-cased statements, not functions
 
Yeah, but that's a reference thing.
Wait, what?
no way.
WeekdayName totally does exist in the VBA.
VBA.Strings.WeekdayName
 
wtf is it doing in VBA.Strings though
 
Wut? You're right. The docs I'm looking at are wrong.
 
VBA.DateTime.Date$, but VBA.Strings.WeekdayName
 
5:20 PM
@MathieuGuindon I have to double check but I think Access reports can use those. Never used it (and I doubt majority of Access users even know about those)
well the function returns a string....
 
@MathieuGuindon I could see the argument that it's kind of like a "format".
 
uh-huh
as is Date$
and Error$
 
But yeah, VBA.DateTime.Date$ is weird AF.
 
Date$ should never be used IMO. It encapsulates everything that can go wrong with date handling into one function.
 
^. The correct use is Format(), fin.
 
5:23 PM
Should be named VBA.DateTime.ScrewUpMyDatesInSubtleWays
 
@Comintern I smell an inspection
 
I think we've considered an inspection for handling dates as strings in the past.
 
and I really do not like the fact that you can too easily do Date = #2035-01-29# 'Look, ma, time traveling!
I think that inspection would be worth a metric ton of gold.
 
I see far too much abuse of the date handling.
actually probably can write off a dozen inspections for date data types alone.
 
5:24 PM
At least.
 
Date() + 1.5 <= cringeworthy
 
Because of the implicit "cast"?
 
Date() + 365 <= WTF, haven't you heard of the leap year?
well, casting isn't the real problem. The real problem is that you can't be expected to get consistent results that you would get w/ DateAdd()
 
I'm pretty sure you can with that one, that should always return the same result as adding 36 hours with DateAdd.
 
?CDate(0) + 0.5
12:00:00 PM
?CDate(0) - 0.5
12:00:00 PM
 
5:30 PM
uhhhh
 
The thing is that how it's implemented, it's "OK" to add by whole numbers. But fractional part don't work the same way.
But the real point is that when you abuse dates like that, you've violated the encapsulation of the Date data type and are now treating it like a just another Double which may not have the same outcomes when you do use correct date arithmetic functions.
 
Uh, that's the correct result though.
 
no.
 
The issue there is the 0 and 1 date bug.
?CDate(43493) + 0.5
1/28/2019 12:00:00 PM
?CDate(43493) - 0.5
1/27/2019 12:00:00 PM
 
?DateAdd("h", 12, CDate(0))
12:00:00 PM
?DateAdd("h", -12, CDate(0))
12/29/1899 12:00:00 PM
This shows that - 0.5 shortcut is not equivalent to "subtract 6 hours"
 
5:34 PM
That's "incorrect" in the same way.
 
What? No, those are different answers. DateAdd() gave correct answers.
 
so it looks like 12/30/1899 just doesnt exist
 
no, that's the epoch.
Let me make it more explicit....
 
i mean if you use cdate(0) you dont get the date portion
just a time
 
I guess my point is that you shouldn't expect anything to work around the epoch.
 
5:36 PM
?Format$(CDate(0) + 0.5,"yyyy-mm-dd hh:nn:ss")
1899-12-30 12:00:00
?Format$(DateAdd("h", 12, CDate(0)),"yyyy-mm-dd hh:nn:ss")
1899-12-30 12:00:00
?Format$(CDate(0) - 0.5,"yyyy-mm-dd hh:nn:ss")
1899-12-30 12:00:00
?Format$(DateAdd("h", -12, CDate(0)),"yyyy-mm-dd hh:nn:ss")
1899-12-29 12:00:00
 
note to self: write about "default interface"
@Greedo the "default interface" of a class is the interface presented by an object declared As [ClassName] - in other words As UserForm1 includes the members of UserForm inherited from the base class, and the members of UserForm1 defined in UserForm1, but not the members of IDialogView defined in some hypothetical IDialogView class that UserForm1 would be implementing with Implements IDialogView. — Mathieu Guindon 14 mins ago
 
it's not just epoch, though. You can get the same behavior with dates predating the epoch, too. I don't think you can get that after the epoch.
But if doing arithmetic on the date "leaks", that's good enough reason to stop violating the encapsulation that the Date data type and its related functions provides, no?
Not all valid values of a double are also a valid value of Date.
 
Oh, there are plenty of reasons to do that.
 
Anyway, I'd want an inspection on stupid expressions like MyDate + 0.5 because it's not going to behave the same for any given value of MyDate.
 
So 2 inspection results for 1 expression?
This one is interesting:
?CDate(0) + CDate(.5)
12:00:00 PM
?CDate(0) - CDate(.5)
-0.5
 
5:44 PM
lol wut
 
Does the run-time itself only consider a positive Double to be typed Date?
 
Well, someone who looked at this claims that the fractional portion of the Date is always positive
IOW, if you took out the fractional part of the Double for any given value of wholes/sign, it would always yield the same time of day
 
As in distance from the epoch, sure. I was more curious about the implicit typing going on.
 
It's still Double in its structure - just that it's interpreted differently.
 
?CDate(0) + CDate(1.5)
12/31/1899 12:00:00 PM
?CDate(0) - CDate(1.5)
-1.5
But VBA is definitely treating the first as a Date and the second as a Double there.
If that's the case, we'll need to account for it in our permissive asserts.
 
5:51 PM
?IsDate(CDate(0) - CDate(1.5)), IsDate(CDate(-1.5))
False         True
?CDbl(CDate(-1.5)) = CDbl(DateAdd("h", -36, CDate(0)))
False
hmm.
?CDbl(CDate(-1.5)), CDbl(DateAdd("h", -36, CDate(0)))
-1.5          -2.5
Did I screw it up?
 
> 5.5.1.2.3 Let-coercion to and from Date
A Date value may be converted to or from a standard Double representation of a date/time, defined as the fractional number of days after 12/30/1899 00:00:00. As Date values representing times with no date are represented as times within the date 12/30/1899, their standard Double representation becomes a Double value greater than or equal to 0 and less than 1.
VBA is off spec on this.
 
Permissive assert... I have a dangling article about that somewhere.
 
gasps Joel Spolsky is wrong?!? Say it ain't so!
 
5.5.1.2.3 says that if the source declared type and the destination declared type are both Date, "The result is a copy of the source date."
It should only be treating it as a Double if there is a let-coercion to a numeric type.
 
In documentation somewhere else, it says that the date can be anything from 100-01-01 to 9999-12-31 23:59:59
I'm pretty sure the Double allows for more values beyond that range but AIUI, Date will only accept values for those.
 
00:00 - 18:0018:00 - 00:00

« first day (1697 days earlier)      last day (1483 days later) »