« first day (836 days earlier)      last day (2344 days later) » 

12:00 AM
RELOAD!
 
12:30 AM
> RD already has an inspection for `Variable 'x' is not used`, which catches this:

```vb
Private Sub Test1()
Dim status As String
status = foo
End Sub
```

But it fails to catch unused re-assignments *after* usage:

```vb
Private Sub Test2()
Dim status As String
status = "foo"
Debug.Print status
status = "bar"
End Sub
```

This is related to #882, but instead of being a reassignment *before use*, this inspection is for unused reassignment *after* prior use.
> It's common to find VBA that explicitly destroys local variables before exit. This destruction is not necessary unless there's a pressing need for:

1. Resource management within a procedure.
2. Avoidance of memory leaks caused by circular-reference/reference-count problems.

For example, this code doesn't need to destroy the local variables:

```vb
Sub foo()

Dim wbk As Workbook
Dim sht As Worksheet
Dim sheetCount As Long
Dim var As Variant

Set wbk = ThisWorkbook
 
@Duga #2243 is a dupe?
 
yep
 
Well, I did refer to it and make the (somewhat fine) distinction
 
12:44 AM
or... I don't see what the difference would be
 
IIUC #882 one is: Dim a As String : a = "foo" : a = "bar" : Foo a
 
yup. "foo" is never used
 
> locate an identifier that's assigned a value that's reassigned before it's used
 
and #2243 is Dim a As String : a = "foo" : Foo a : a = "bar"
 
but #2243, is about a variable that is used then reassigned but never subsequently re-used
 
12:46 AM
it still needs basically the same execution graph analysis
 
I don't see how it wouldn't be picked up by the "value not used" inspection
@ThunderFrame it's more about the values assigned to variables, than the variables themselves
 
agreed - just wanted to make sure that #882 considered the re-assignments after use.
 
it has to :)
 
but #2243 is good?
 
yes, but it's covered by #882
 
12:57 AM
> MVCE

```vb
Sub Foo
Dim str As String
End Sub
```
 
lol
 
oops, I meant 2244 is good?
 
Yep
 
I guess #882 would catch #2244, but a dedicated inspection would help to educate.
 
hmm indeed, #882 will have to watch for default values
hmm
the more inspections we come up with, the more it's really starting to look like they need to be reimplemented in a visitor.
we don't need to wreck our brains to come up with AST nodes, they're there in our parse tree
ugh, yeah we need dat context information
so I need a walker to generate AST nodes
and then I need to write a walker that walks the AST
no, I need a way to Visit<T>() AST nodes
 
1:09 AM
> #882 will need to watch for these, they'll pop as "false positives" - perhaps the best way would be to have #882 yield one of two types of inspection results.

Could also be interesting to watch for *default value* initial assignments:

Dim foo As Boolean
foo = False

Dim bar As Integer
bar = 0

Dim something As Foobar
Set something = Nothing

That would also be popping up as a result for #882, so perhaps it should yield one of 3 result types... this defini
> And error blocks:

```vb
Dim status as String
status = "404"
On Error Resume Next
status = MyHttpVuDu
On Error Goto 0
```
 
hmm, why is the VBA.Collection.Count member a method?
 
huh, is it?
 
smells like a getter to me, but marked as a function
 
IKR
And the Scripting.Dictionary.Item is a property but acts like a method :-/
 
1:19 AM
my money is on because it's a parameterized getter
@ThunderFrame per RD or per some COM inspector?
 
You must use Exists(key) before using Item(key)
Dim dic As Scripting.Dictionary
Set dic = New Scripting.Dictionary
'Dictionary has a getter that adds or assigns a key
Debug.Print dic.Item("foo")

Debug.Print dic.Count ' Prints 1
 
@ThunderFrame wtf??
 
that would be a good inspection - and we can know that the scripting runtime is referenced
we wouldn't pick it up with a late-bound dictionary though
but IMO that's fine, it's your problem that you're late-binding things
..right?
 
1:59 AM
Yep. I'm thinking we have an inspection for Collections and Dictionaries that are created but not added to, and one for Collections/Dictionaries that are added to but the Items are never used.
@Vogel612 intuitive, no?
 
rather, "collection is never iterated" perhaps?
would work for arrays too
 
@Mat'sMug we could determine some late-bound Dictionaries by looking at assignments that involve anything like CreateObject("Scripting.Dictionary")
 
yeah
@ThunderFrame I like that, "no item is ever added to collection 'foobars'."
 
It's a bit loose, given the design of some objects, but a warning for "Object variable never uses setter or method members". But Dictionary.Item is an example of a getter that violates the rule.
And we could perhaps identify the return type for an Object returning procedure based on assignments of CreateObject calls inside the procedure?
 
@ThunderFrame wouldn't that already trip variable not used?
 
2:24 AM
Private Sub test()

  Dim col As VBA.Collection
  Set col = New Collection
  Debug.Print col.Count

  Dim dic As Scripting.Dictionary
  Set dic = New Scripting.Dictionary
  Debug.Print dic.Count

End Sub
neither dic nor col have setters or methods called, but RD thinks they've been assigned and used.
 
hmm yep
 
That does raise the question as to whether Debug.Print should be considered usage of a variable...
Re containers not added to, do you trip the inspection if it's passed to another Sub or Function? I frequently use helpers to fill them.
 
good one
 
execution graph is calling
 
totally
 
2:35 AM
at 4:30 AM I'm just nodding though ...
 
re late-bound object assignments, you could even provide an annotation hint for the ProgID/ClsID?
 
BTW. @Mat'sMug do you have some plans for the Regex Assistant? It basically only needs a GUI that allows drag, drop & edit for the treenodes
 
@ThunderFrame we should be able to outright interpret CreateObject :)
@Vogel612 not really, you?
 
neither...
gotta finish StackSTV first ;)
 
2:51 AM
@Mat'sMug - except with evil code like this:
Function PolyApp(appName As String) As Object
  Dim APP As String
  APP = ".Application"
  Select Case appName

    Case "Excel"
      Set PolyApp = Application

    Case "Word"
      Set PolyApp = CreateObject(appName & APP)

    Case "Access"
      Set PolyApp = New Access.Application

    Case "VBE"
      Set PolyApp = Application.VBE

  End Select

End Function
 
3:10 AM
we might actually be able to evaluate that
hmm
or not
 
3:39 AM
I'm tempted to make the AST an XML document, and leverage LINQ-to-XML to navigate, query, and alter it
it would simplify a ton of things
...and probably be a ton slower too
...or would it
Ira Baxter calls it slow, but he's selling his DMS solution so IDK
 
4:00 AM
The slowness of linq to xml stems from it loading the entire xml into memory... but then we'd be having the entire AST in memory anyway. hmm I'm starting to get a good vibe out of this
we could persist AST's in like one line of code
keep metadata about 'em in memory and then only load them from disk when they're really needed
 
IDK - working with XML seems like an unnecessary overhead/abstraction
 
true
but then we need to implement our own e.g. Descendants and Ancestors search methods, and the mechanisms to replace nodes
 
I've been trying to audit a tool that uses XML documents for internal manipulation. It's proved very difficult to understand what's going on. IMO XML is great for serialization, and for transformations, but OOP structures are better/easier for design and use.
although set docCShap = docVBA.Transform(xslCSharp) has an elegance to it.
How about a directed graph?
 
I don't know much CS theory :-/
 
it's an old DB trick for Leaf-Nodes
You assign each node a Left and Right property as you create/walk the tree from top to bottom and left to right.
The nested set model is a particular technique for representing nested sets (also known as trees or hierarchies) in relational databases. The term was apparently introduced by Joe Celko; others describe the same technique without naming it or using different terms. == Motivation == The technique is an answer to the problem that the standard relational algebra and relational calculus, and the SQL operations based on them, are unable to express all desirable operations on hierarchies directly. A hierarchy can be expressed in terms of a parent-child relation - Celko calls this the adjacency list...
 
4:14 AM
IDK, at the end of the day we're going to have some SyntaxTreeVisitor creating nodes such as MemberCallStatementNode and VariableAssignmentNode and abstracting CST nodes like we did for Identifier, just in a more elaborate/complete way
 
+1 for allow different Visitor implementations to be able to decide the order of visitation. Very good idea. — marco-fiset Mar 6 '13 at 15:52
 
I agree xml is probably overkill, but the structure we'll end up with will definitely be xml-serializable nevermind, no way - ast nodes are immutable
@ThunderFrame absolutely. that's what the visitor does
ANTLR already gives us a base class to implement =)
basically we need to take autoboosh's work to the next level, and apply the same methodology to the entire source files
I'll sleep on that
'night!
 
'night
 
 
2 hours later…
6:39 AM
0
Q: c# filter the school by department and count the department with different label

Yafetprivate void ReportOffice_Load(object sender, EventArgs e) { try { connection.Open(); OleDbCommand command = new OleDbCommand(); command.Connection = connection; string query = "select FileNo,Fname,Sex...

 
 
5 hours later…
Kaz
11:45 AM
@Mat'sMug Evidently, Eric liked me enough to refer me to HR to start the formal application process.
Did warn me to expect it to be very robust.
 
Good! I hope all goes well!
 
Kaz
@Mat'sMug You and me both ^^
Though that said, I hope it doesn't happen *too* fast. I'm expecting that we'll finalise contracts for our new back office system in the next fortnight, and it'll take at least 4 weeks to implement. Resigning in the middle of said process would be a very unpalatable decision to have to consider.
 
 
1 hour later…
1:22 PM
@Kaz eh.. there's always something going on right, it's never a good time for an employer to lose key staff ;-)
 
Kaz
1:35 PM
@Mat'sMug Sure, it's never convenient, but there are times when it would be particularly painful.
 
2:32 PM
If your hopefully new employer wants you, they'll be okay with you resigning at your current employer with a longer notice period
 
 
6 hours later…
8:40 PM
1
Q: Writing a particular column of a two-dimension array to a worksheet

Iain SaundersSo I had some great feedback on my code previously here and I was hoping that I could get some further help with writing a column of the array to the worksheet. Below I have an example where I write one column of my array to the worksheet with a loop, but I'm wondering if there wouldn't be a mor...

 
 
2 hours later…
10:37 PM
Anybody else get weird capitalization of some type and/or member names? Eg. usages of Recordset appear as recordset, and causes source control diffs? I think RD can offer a fix for this.
 
10:53 PM
Dim Recordset
and then delete it
You have a variable somewhere that's declared as recordset
There's no fix for that
It's a "feature" of case-insensitive languages
 
It's more of a "feature" of the VBE. If it were a language feature, it would be smart enough to know that Recordset and recordset were the same thing.
Although the language is I guess. The VBE is freakin stoopid.
 
right
 
Although with a code pane replacement, RD could conceivably "fix" that by storing and the capitalization pattern of identifiers. Not sure it would be worth the effort though.
 
11:17 PM
^
 
Create a class called widget, then rename it to Widget, now use it in a standard module, and intellisense, and any code that uses the Widget type will preserve the lower cased version. As @Mat'sMug says, declaring and removing an in-scope variable name as Widget will fix the capitalization
but RD could find any type/member that doesn't match the declaration casing, and automatically apply a fix?
and if it is some badly named/cased variable, then RD could suggest renaming it
Dim collection, add, remove, count, item

Sub foo()
  Dim c As collection
  Set c = New collection


  c.add "foo"
  Debug.Print c.count
  c.remove 1

End Sub
 
@ThunderFrame the problem is that it's another declaration with a different casing that messes it up
@ThunderFrame and doing that would probably contradict local/parameter casing conventions in the code base
e.g. I like naming my setter parameters value and I don't want any tool to mess it up and start renaming it to Value because Range.Value says it's capital V ;-)
Although I can see RD saying "FYI that value parameter is going to change the casing of Range.Value"... but I think there are worse problems in the world's VBA code that need fixing
That said I wonder if that comment will get a response
Just out of curiosity, exactly what motivates having 1980's line numbers in VBA code? — Mat's Mug 1 hour ago
 
LOL
Nice reminder of the 4 hours it took for the OP to look into the first comment I posted.
 
sure, but my first example, where widget is cached... i.e. there aren't any types/variables named widget, and yet the capitalization persists. But if the same code is opened later, the code can recapitalize, and make it look like there are numerous code changes in Source Control
 
meh.. not like people aren't used to that already
@Comintern IKR
 
11:34 PM
If I could down-vote comments, this would be my first:
@Comintern Function MacroLineNum() is not the problem. It basically puts numbers on the lines of code. That function is processing correctly. and is not generating any errors. — A A 5 hours ago
 
Just out of curiosity, exactly what justifies having 1980's line numbers in VBA code? — ThunderFrame 40 secs ago
 
lol
@ThunderFrame I know! My code isn't enough of a PITA to maintain already! I need a little challenge!
...and moar gotos
 
Did you notice that he renumbered all of the lines in the "answer"?
 
Gosh that's dangerous
If they're used at all I mean
On Error GoTo 999
oops, now it's 998
 
Yep. BTW, there isn't any reason to skip numbers any more for inserts though - line numbers don't need to be in any order what-so-ever.
 
11:43 PM
Is his tab size = 28 spaces?
IMO, if you're going to use line numbers, you should make them descending. That way you're aiming for On Error Goto 0 ;-P
 
FWIW if line numbers are ever used, e.g. On Error GoTo 1590, then re-numbering them can introduce nasty hard-to-find bugs. VBA hasn't needed line numbers for anything other than porting old legacy QBASIC code; they're reasonably harmful in new code, if only for the readability hit. — Mat's Mug 14 secs ago
@Comintern but then you get a SERIOUS case of OCD
I know I would!
so they're basically interpreted exactly like line labels then
 
TIL you can overflow a line number:
Sub LineNumbers()
2147483647  Debug.Print "foo"
2147483648  Debug.Print "foo"   'Compile error
End Sub
 
Bwahahaha
 
Suggested fix:
 
a line number can be 0, and you can Goto 0, but you obviously can't On Error Goto 0
 
11:49 PM
Sub LineNumbers()
2147483647  Debug.Print "foo"
Ox80000000: Debug.Print "foo"   'No compile error
End Sub
 
Oh COME ON!!!
 
lol
negative line numbers:
Sub foo()
  &hFFFFFFFF Beep
  &hFFFFFFFE Beep
End Sub
^ compiles and runs
 
FML
@Comintern wait a sec, the vbe understands 0x now????
 
Look a bit more closely...
 
Ox you evil brat
 
11:56 PM
@ThunderFrame I had no idea it recognized hex though. That is ̶a̶w̶e̶s̶o̶m̶e̶ awful.
 
good lord, WHY
 
real QBASIC programmers use HEX line numbers
3
 
Crap. That breaks the indenter.
 
lol
 

« first day (836 days earlier)      last day (2344 days later) »