Hi srod,
I have had a play with Comate and it has made a difficult task very easy for me.
I use it to check a pile of Excel Worksheets for a Sample ID.
Here is my humble Code
Code: Select all
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;
; EXCEL Sample Find ( Finds Sample ID in Worksheet Files )
;
; Version 0.1
;
; Program By Leo
;
; Programmed in PureBasic Version 4.20
;
; Last Updated 9/12/2008
;
; Comate by Stephen Rodriguez
;
; nxSoftware
;
; http://www.nxSoftware.com
;
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
IncludePath "C:\PureBasic\Demo code\Comate\"
XIncludeFile "COMate.pbi"
Global Find$ = ""
OpenWindow(0, 0, 0,820,600," EXCEL Sample Find ",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ListIconGadget(1, 10, 10,295,580,"File Name",200,#PB_ListIcon_GridLines)
ButtonGadget (2,315, 10,100, 20," Find String ")
StringGadget (3,420, 10,170, 20,"")
ListIconGadget(5,315, 70,495,520,"File Name",200,#PB_ListIcon_GridLines)
StringGadget (6,315, 40,495, 20,"Remember - this search routine is case sensitive and will only find an 'exact' match to the Find String.")
TextGadget (7,625, 10,150, 20," Default Excel Search Column",#PB_Text_Border)
StringGadget (8,780, 10, 30, 20,"B")
AddGadgetColumn(1, 2,"Date" , 74)
AddGadgetColumn(5, 2,"Case No." ,100)
AddGadgetColumn(5, 3,"Sample ID",135)
AddGadgetColumn(5, 4,"Row" , 38)
If ExamineDirectory(0,"C:\ELISA\Upload\","Worksheet*.xls")
While NextDirectoryEntry(0)
FileName$ = DirectoryEntryName(0)
If DirectoryEntryType(0) = 1 ; Directory type
FileDate = DirectoryEntryDate(0,#PB_Date_Modified)
AddGadgetItem(1, -1, FileName$ + Chr(10) + FormatDate("%dd/%mm/%yyyy", FileDate))
EndIf
Wend
Else
MessageRequester("Error","Can't examine this directory: C:\ELISA\Upload\",0)
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 2
ClearGadgetItemList(5)
Gosub CheckFile
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
End
CheckFile:
Find$ = GetGadgetText(3)
For Files = 0 To CountGadgetItems(1)
File$ = GetGadgetItemText(1,Files)
CDate$ = GetGadgetItemText(1,Files,1)
SetGadgetItemColor(1,Files,#PB_Gadget_BackColor,RGB(100,220,240),0)
Lookin$ = "Workbooks\Open('C:\Elisa\Upload\"+File$+"')"
Define.COMateObject ExcelObject, WorkBook
ExcelObject = COMate_CreateObject("Excel.Application")
;ExcelObject\SetProperty("Visible = #True")
WorkBook = ExcelObject\GetObjectProperty(Lookin$)
If ExcelObject
t = 1
Repeat
Cell$ = ExcelObject\GetStringProperty("Cells(" + Str(t) + ",2)") ; Cells(Row,Column)
position = FindString(Cell$,Find$,1)
If position > 0
Cell1$ = ExcelObject\GetStringProperty("Cells(" + Str(t) + ",1)")
AddGadgetItem(5,-1,File$ + Chr(10)+Cell1$ + Chr(10) + Cell$ + Chr(10) + Str(t) + Chr(10) + "B")
EndIf
t = t + 1
Until Cell$ = ""
ExcelObject\Invoke("Quit()")
ExcelObject\Release()
EndIf
Next Files
Return
Its not that flash but it works, but I have a few questions ?
How do I deal with a requester that pops up if a different version of Excel was used to create the file.
" Do you want to save the changes to ------- ? Yes No Cancel "
I want to be able to see the progress of the search, highlight each file as it has been checked. I can not get that to work am I doing something silly or is it due to Comate?
Are there any ways of speeding up the search ( I gather most of the time is used up opening and closing Excel )
Regardless, Comate is great and I will be doing a lot more with it in the future.
Thanks