Ticket #2988: rangefindBug.au3

File rangefindBug.au3, 2.7 KB (added by TheAppleFreak <theapplefreak@…>, 9 years ago)

Minimal file to show the nature of the bug, as tested with Excel 2007.

Line 
1#include <Excel.au3>
2#include <Array.au3>
3
4; AutoIT 3.3.12.0 (Production), tested with Excel 2007.
5;
6; _Excel_RangeFind test file
7;
8; Testing search functionality by searching for strings in and across sheets.
9
10; Create Excel object
11Local $oExcel = _Excel_Open()
12
13; Create two new sheets, both with one sheet each.
14Local $oBookNumbers = _Excel_BookNew($oExcel, 1)
15Local $oBookLetters = _Excel_BookNew($oExcel, 1)
16
17; Populate sheets with data.
18For $i = 1 To 100
19        $oBookNumbers.Sheets(1).Range("A" & String($i)).Value = $i
20        $oBookLetters.Sheets(1).Range("A" & String($i)).Value = _Excel_ColumnToLetter($i)
21Next
22
23; Define search results variable
24Local $search
25
26MsgBox(0, "Active sheet", "The following four searches search the active sheet. These work as expected.")
27
28; Set the active sheet to the sheet with numbers...
29$oBookNumbers.Sheets(1).Activate
30
31; These searches will work just fine.
32$search = _Excel_RangeFind($oBookNumbers, "42", "A1:A100")
33_ArrayDisplay($search, """42"" on active sheet (numbers) with range as string")
34$search = _Excel_RangeFind($oBookNumbers, "42", $oBookNumbers.Sheets(1).Range("A1:A100"))
35_ArrayDisplay($search, """42"" on active sheet (numbers) with range as object")
36
37; Set the active sheet to the one with letters...
38$oBookLetters.Sheets(1).Activate
39
40; Once again, both of these searches should also work fine.
41$search = _Excel_RangeFind($oBookLetters, "AF", "A1:A100")
42_ArrayDisplay($search, """AF"" on active sheet (letters) with range as string")
43$search = _Excel_RangeFind($oBookLetters, "AF", $oBookLetters.Sheets(1).Range("A1:A100"))
44_ArrayDisplay($search, """AF"" on active sheet (letters) with range as object")
45
46MsgBox(0, "Cross-sheet", "The following four searches search the inactive book. The first and third fail, but do not return errors.")
47
48; Set the active sheet to the one with letters...
49$oBookLetters.Sheets(1).Activate
50
51; Despite each book only having one sheet, the string search fails if the search sheet is not active.
52$search = _Excel_RangeFind($oBookNumbers, "42", "A1:A100")
53_ArrayDisplay($search, """42"" on numbers sheet with range as string. Failed search")
54$search = _Excel_RangeFind($oBookNumbers, "42", $oBookNumbers.Sheets(1).Range("A1:A100"))
55_ArrayDisplay($search, """42"" on numbers sheet with range as object")
56
57; Set the active sheet to the one with numbers...
58$oBookNumbers.Sheets(1).Activate
59
60; Same thing with searching numbers.
61$search = _Excel_RangeFind($oBookLetters, "AF", "A1:A100")
62_ArrayDisplay($search, """AF"" on letters sheet with range as string. Failed search")
63$search = _Excel_RangeFind($oBookLetters, "AF", $oBookLetters.Sheets(1).Range("A1:A100"))
64_ArrayDisplay($search, """AF"" on letters sheet with range as object")