![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? |
#3
| |||
| |||
|
|
Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) -- Marsh |
#4
| |||
| |||
|
| "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote in message news:l7tfd6l4g8bjbd7r797ff4upro5d4icj3t (AT) 4ax (DOT) com... Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) -- Marsh Thanks Marsh. But I'm still missing something here. If I use Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) to identify if 'CloseSub:' exists, I get 'True' returned. If I then use empty variables such as: Dim lngSLine As Long, lngSCol As Long, lngELine As Long, lngECol As Long in vInsertLine = Mdl.Find("CloseSub:", lngSLine, lngSCol, lngELine, lngECol) or vInsertLine = Mdl.Find("CloseSub:", 1,1,CountOfLines, 1000) I still get 'True'. If this line is supposed to return a value (StartLine), how do I get to it? -- Bob Darlington Brisbane |
#5
| |||
| |||
|
|
"Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) But I'm still missing something here. If I use Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) to identify if 'CloseSub:' exists, I get 'True' returned. If I then use empty variables such as: Dim lngSLine As Long, lngSCol As Long, lngELine As Long, lngECol As Long in vInsertLine = Mdl.Find("CloseSub:", lngSLine, lngSCol, lngELine, lngECol) or vInsertLine = Mdl.Find("CloseSub:", 1,1,CountOfLines, 1000) I still get 'True'. If this line is supposed to return a value (StartLine), how do I get to it? I worked this out, so please disregard my last post. I only needed to use: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) then vInsertLine = lngStartLine I hadn't realised that the variable within the function call got reset. An example in the Help screen would have been helpful though. |
#6
| |||
| |||
|
|
Bob Darlington wrote: "Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) But I'm still missing something here. If I use Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) to identify if 'CloseSub:' exists, I get 'True' returned. If I then use empty variables such as: Dim lngSLine As Long, lngSCol As Long, lngELine As Long, lngECol As Long in vInsertLine = Mdl.Find("CloseSub:", lngSLine, lngSCol, lngELine, lngECol) or vInsertLine = Mdl.Find("CloseSub:", 1,1,CountOfLines, 1000) I still get 'True'. If this line is supposed to return a value (StartLine), how do I get to it? I worked this out, so please disregard my last post. I only needed to use: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) then vInsertLine = lngStartLine I hadn't realised that the variable within the function call got reset. An example in the Help screen would have been helpful though. Right! Don't forget that using a literal (eg. 1) or an expression (eg. lngStartLine + lngCount) means that the found line/position value can not be set in the argument. In that sense, my use of StartLine+1 was a poor example. Using lngStartLine + lngCount may be saving you from the problem of lngCount being set to the found line by every Find, but technically you should only be using lngCount. If you set lngCount to CountOfLines, then you should reset lngCount to CountOfLines before each use of Find. This is really only important if you are searching for a multi line string. -- Marsh |
#7
| |||
| |||
|
|
"Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote in message news:661hd6pgq7m30fm804mfdbqh2g4ufbhlli (AT) 4ax (DOT) com... Bob Darlington wrote: "Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) But I'm still missing something here. If I use Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) to identify if 'CloseSub:' exists, I get 'True' returned. If I then use empty variables such as: Dim lngSLine As Long, lngSCol As Long, lngELine As Long, lngECol As Long in vInsertLine = Mdl.Find("CloseSub:", lngSLine, lngSCol, lngELine, lngECol) or vInsertLine = Mdl.Find("CloseSub:", 1,1,CountOfLines, 1000) I still get 'True'. If this line is supposed to return a value (StartLine), how do I get to it? I worked this out, so please disregard my last post. I only needed to use: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) then vInsertLine = lngStartLine I hadn't realised that the variable within the function call got reset. An example in the Help screen would have been helpful though. Right! Don't forget that using a literal (eg. 1) or an expression (eg. lngStartLine + lngCount) means that the found line/position value can not be set in the argument. In that sense, my use of StartLine+1 was a poor example. Using lngStartLine + lngCount may be saving you from the problem of lngCount being set to the found line by every Find, but technically you should only be using lngCount. If you set lngCount to CountOfLines, then you should reset lngCount to CountOfLines before each use of Find. This is really only important if you are searching for a multi line string. I thought I had it licked until I came to finding 'End Sub' The first 2 calls below work fine, but the third can't find 'End Sub' (which certainly exists). That is Mdl.Find("End Sub", lngStartLine, 0, lngStartLine + lngCount, 20) returns false. This call should pick up where no error trap has been included. If Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine ElseIf Mdl.Find("Exit Sub", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine ElseIf Mdl.Find("End Sub", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine End If Any idea why 'End Sub' should be a special case? |
#8
| |||
| |||
|
|
Bob Darlington wrote: "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote in message news:661hd6pgq7m30fm804mfdbqh2g4ufbhlli (AT) 4ax (DOT) com... Bob Darlington wrote: "Bob Darlington" <bob (AT) notheredpcman (DOT) com.au> wrote "Marshall Barton" <marshbarton (AT) wowway (DOT) com> wrote Bob Darlington wrote: Each of my Report_Open events includes a 'CloseSub:' label, and I want to insert a new line of code immediately before that line (in each of 54 reports). I can check whether or not 'CloseSub:' exists using: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) This yields true or false, but I then need to identify the line at which it occurs. Looking up help for 'Find' yields the following sentence: "To determine the position in the module at which the search text was found, pass empty variables to the Find method for the StartLine, StartColumn, EndLine, and EndColumn arguments. If a match is found, these arguments will contain the line number and column position at which the search text begins (StartLine, StartColumn) and ends (EndLine, EndColumn)." My question is how to pass 'empty variables' and then how to read the 'StartLine' result from that procedure. Can anyone help? An empty variable is just a Variant that has not been assigned a value. I've never tried that aspect of the Find method, but I believe it implies the search starts at the first character on the first line and goes throught the last line. I generally use Long (probably not technically correct) variables with 1,1,CountOfLines, 1000 for the first Find and use the values Find sets in the variables for where the match was found. You can then use the Lines method to inspect the line with the match or something like mdl.Lines(StartLine-1,1) to refer to the previous line. If you are trying to find a match multiple times in the same module the Find would look like mdl.Find(..., StartLine+1, ...) But I'm still missing something here. If I use Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) to identify if 'CloseSub:' exists, I get 'True' returned. If I then use empty variables such as: Dim lngSLine As Long, lngSCol As Long, lngELine As Long, lngECol As Long in vInsertLine = Mdl.Find("CloseSub:", lngSLine, lngSCol, lngELine, lngECol) or vInsertLine = Mdl.Find("CloseSub:", 1,1,CountOfLines, 1000) I still get 'True'. If this line is supposed to return a value (StartLine), how do I get to it? I worked this out, so please disregard my last post. I only needed to use: Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) then vInsertLine = lngStartLine I hadn't realised that the variable within the function call got reset. An example in the Help screen would have been helpful though. Right! Don't forget that using a literal (eg. 1) or an expression (eg. lngStartLine + lngCount) means that the found line/position value can not be set in the argument. In that sense, my use of StartLine+1 was a poor example. Using lngStartLine + lngCount may be saving you from the problem of lngCount being set to the found line by every Find, but technically you should only be using lngCount. If you set lngCount to CountOfLines, then you should reset lngCount to CountOfLines before each use of Find. This is really only important if you are searching for a multi line string. I thought I had it licked until I came to finding 'End Sub' The first 2 calls below work fine, but the third can't find 'End Sub' (which certainly exists). That is Mdl.Find("End Sub", lngStartLine, 0, lngStartLine + lngCount, 20) returns false. This call should pick up where no error trap has been included. If Mdl.Find("CloseSub:", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine ElseIf Mdl.Find("Exit Sub", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine ElseIf Mdl.Find("End Sub", lngStartLine, 0, lngStartLine + lngCount, 20) Then vInsertLine = lngStartLine End If Any idea why 'End Sub' should be a special case? I don't think "End Sub" is a special anything. You can probably see what's happening if you step through the code and watch lngStartLine. I suspect that it found a CloseSub or Exit Sub after the last End Sub. The important part of the procedure is the context where this code is used, i.e. where/when/how you set lngStartLine and if the code is in a loop. This sure appears to only be useful if you are looping to find all of the strings in a module. When you do that you can either go through the module 3 times, once for each search string or you have to check all three Finds to see which one occurs first and use that for the next Find. -- Marsh |
![]() |
| Thread Tools | |
| Display Modes | |
| |