3

I am trying to search a large VB6 project for where a variable gets assigned. If I just use the Find dialog and enter the variable name in the “Find What” textbox, it opens many windows where the variable is used, but I would like to just get the lines where the variable is the first thing at the beginning of a line (where the variable is being assigned to).

I have tried using the “Use Pattern Matching” option, but I must not be using it correctly; when I search VB6 Help, it just says that option searches using pattern matching characters, without mentioning what "pattern matching characters" are allowed.

MikeC
  • 208
  • 3
  • 12

2 Answers2

3

A solution that uses the VB6 editor using the VB6 Find dialog with the "Use Pattern Matching" option, to find lines where an assignment to a variable is made is:

yourVariableName*=

where the wildcard pattern matching character is used. It doesn't actually require the variable name to be at the start of a line, and may give some extra hits, but is simple and easy to use within the VB6 code editor.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
MikeC
  • 208
  • 3
  • 12
  • I was going to suggest the simpler "VariableName =" search, but neither that nor @StayOnTarget's solution handles the cases where the variable is assigned as a result of a ByRef function call. In fact, I can't think of any search method, even with an external editor, that would find these cases, unless the editor actually does source code analysis. – Mark Moulding Jul 15 '21 at 19:12
  • @MarkMoulding I only made a small edit to this answer, just for the record. – StayOnTarget Jul 15 '21 at 19:20
  • 1
    @MarkMoulding That is the approach I usually use... `VarName = `, with a single space before and after the `=`. As the VB6 IDE doesn't support real regex, that's about the best you can ask for without 3rd-party tools (there may be some plugins I dont know that do it in the IDE, though). As for the `ByRef` case, the only thing I've ever found useful for that is a watch with "Break when Value Changes" selected, and run the code over some useful portion. Other than that, I can't think of any way to handle a `ByRef` set. – User51 Jul 15 '21 at 21:08
  • This link seems to have the wildcard characters that can be used in the VB6 Find dialog with the “Use Pattern Matching” option: https://learn.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/wildcard-characters-used-in-string-comparisons – MikeC Jul 19 '21 at 19:07
0

If you can set your search mode to use regular expressions, you can indicate start of line with a caret. ie, the "^"

FOO at start of line would be found by entering ^FOO in the search box

JSS
  • 15
  • 5
  • The VB6 editor does not support regular expressions, but an external editor could work; thanks for the example. – MikeC Jul 14 '21 at 20:24
  • I'd try @User51's solution first. If that for some reason gives unsatisfying results, I've used [TextCrawler](https://www.digitalvolcano.co.uk/textcrawler.html) in the past for larger search and search & replace operations. – Hel O'Ween Jul 19 '21 at 14:07