#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Program.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #region Includes ##################################### #include #include #include #include #include #include #endregion ########################################### GUI_Draw() Func GUI_Draw() Local $h_GUI = GUICreate("Appointments", 201, 215, -1, -1, $WS_SYSMENU) GUISetIcon(@ScriptFullPath) GUICtrlCreateLabel("Number Of Patients", 25, 11, 145, 17, $SS_CENTERIMAGE) Local $id_PatientTotal_cbo = GUICtrlCreateCombo("", 25, 29, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) Local $s_Clinic = Clinic_GetStrings('Patient Total') ; get a list for selectable patient numbers GUICtrlSetData(-1, $s_Clinic, StringRegExpReplace($s_Clinic, "\|.*$", "")) GUICtrlCreateLabel("Patient Blocks", 25, 53, 145, 17, $SS_CENTERIMAGE) Local $id_PatientBlock_cbo = GUICtrlCreateCombo("", 25, 70, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) $s_Clinic = Clinic_GetStrings('Patient Blocks') ; get a list for selectable students GUICtrlSetData(-1, $s_Clinic, StringRegExpReplace($s_Clinic, "\|.*$", "")) GUICtrlCreateLabel("Available Clinics", 25, 95, 145, 17, $SS_CENTERIMAGE) Local $id_PatientClinic_cbo = GUICtrlCreateCombo("", 25, 112, 145, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) Local $s_Clinic = Clinic_GetStrings('Clinic Names') ; get a list of clinic names GUICtrlSetData(-1, $s_Clinic, StringRegExpReplace($s_Clinic, "\|.*$", "")) ; fill the combo with the clinic names and set the first one in the list as the default Local $id_Book_btn = GUICtrlCreateButton("Book", 60, 144, 75, 25) ControlFocus($h_GUI, '', $id_Book_btn) ; give the book button focus #Region Constants ################################ ; set the constants that relate to the different property columns in $av_RangeRead/ excel spreadsheet Local Enum _ $e_LastName, _ $e_FirstName, _ $e_DOB, _ $e_Sex, _ $e_Address, _ $e_Zip, _ $e_Phone, _ $e_VisitReason, _ $e_Insurance, _ $e_Clinic, _ $e_Prov, _ $e_ApptTime, _ $e_ApptDate #EndRegion Constants ################################ Local $i_Total = 0 ; number of loops to do (times array is read from = number of patients selected) Local $as_ClinicChars = '', $av_RangeRead = '' ; initialise array variables GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $id_Book_btn GUISetState(@SW_HIDE, $h_GUI) ; hide the gui $i_Total = GUICtrlRead($id_PatientTotal_cbo) ; get the patient number $s_Clinic = GUICtrlRead($id_PatientClinic_cbo) ; get the clinic number $i_StartRow = Student_ReturnRow($id_PatientBlock_cbo) ; get the row to start the workbook read from $av_RangeRead = WorkBook_ReadToArray($i_StartRow, $i_StartRow + $i_Total - 1) ; get the values between the ranges ;~ _ArrayDisplay($av_RangeRead) For $i = 1 To $i_Total WinWaitActive("Untitled - Notepad") ;I want to manually open notepad so all 6 patients will go through the same loop ControlSend("[CLASS:Notepad]", "", "Edit1", $av_RangeRead[$i - 1][$e_LastName] & ',' & $av_RangeRead[$i - 1][$e_FirstName] & @CR) $as_ClinicChars = Clinic_GetStrings($s_Clinic) ; get the clinic specific tabs spaces etc For $j = 1 To $as_ClinicChars[0] ; loop and perform the clinic specific key presses ControlSend("[CLASS:Notepad]", "", "Edit1", $as_ClinicChars[$j]) Next ControlSend("[CLASS:Notepad]", "", "Edit1", $av_RangeRead[$i - 1][$e_Sex] & @CR) Next GUISetState(@SW_SHOW, $h_GUI) Case $GUI_EVENT_CLOSE Program_Exit() EndSwitch WEnd EndFunc ;==>GUI_Draw ; #FUNCTION# ==================================================================================================================== ; Name ..........: Clinic_GetStrings ; Description ...: Returns Clinic related values based on the passed parameter ; Syntax ........: Clinic_GetStrings($s_Clinic) ; Parameters ....: $s_Clinic - The string of the clinic to process ; Return values .: Success - Clinc Name Passed: Returns an array with the characters for use with ControlSend ; Other string: Returns a list of string for loading combo boxes ; =============================================================================================================================== Func Clinic_GetStrings($s_Clinic = '') Switch $s_Clinic Case 'Patient Total' ; min/max number of patients that are selectable Return '1|2|3|4|5|6' Case 'Patient Blocks' ; Return 'Trainer|Student #1|Student #2|Student #3|Student #4|Student #5' Case 'Clinic Names' Return 'Clinic 1|Clinic 2|Clinic 3|Clinic 4|Clinic 5|Clinic 6|Clinic 7|Clinic 8|Clinic 9|Clinic 10' & _ '|Clinic 11|Clinic 12|Clinic 13|Clinic 14|Clinic 15|Clinic 16|Clinic 17|Clinic 18|Clinic 19|Clinic 20' & _ '|Clinic 21|Clinic 22|Clinic 23|Clinic 24|Clinic 25|Clinic 26|Clinic 27|Clinic 28|Clinic 29|Clinic 30' Case Else Local $s_Return = '' Switch $s_Clinic Case 'Clinic 1' $s_Return = '{TAB 2}|{RIGHT 3}' Case 'Clinic 2' ; add keystrokes here Case 'Clinic 3' ; add keystrokes here EndSwitch Return StringSplit($s_Return, '|') ; split the keystrokes to an array EndSwitch EndFunc ;==>Clinic_GetStrings ; #FUNCTION# ==================================================================================================================== ; Name ..........: Program_Exit ; Description ...: Runs tasks related to program clean up and exits the running program ; Syntax ........: Program_Exit() ; Parameters ....: None ; Return values .: None ;================================================================================================================================ Func Program_Exit() WorkBook_ReadToArray(); close excel ; any other clean up duties Exit ; bye EndFunc ;==>Program_Exit ; #FUNCTION# ==================================================================================================================== ; Name ..........: WorkBook_ReadToArray ; Description ...: Reads the value, formula or displayed text from a cell or range of cells of the specified workbook and worksheet ; Syntax ........: WorkBook_ReadToArray([$_Action = 'Open']) ; Parameters ....: $i_StartRow - The row to start the range read from (when using an A1 range) ; $i_EndRow - The row to end the range read (when using an A1 range) ; Return values .: Success - $i_StartRow > 0: Returns an array of values read from the specified range ; $i_StartRow = 0: Closes the Excel instance opened by _Excel_Open() ; Remarks .......: A static variable $o_Excel keeps the value of the excel object returned by _Excel_Open() after exiting ; the function ; =============================================================================================================================== Func WorkBook_ReadToArray($i_StartRow = 0, $i_EndRow = 0) Local Static $o_Excel = '' If Not $i_StartRow Then If IsObj($o_Excel) Then _Excel_Close($o_Excel) Else Local $s_WorkBook = 'D:\Example Format.xlsx' ; change this to your file $o_Excel = _Excel_Open() ; open an excel instance Local $o_Workbook = _Excel_BookOpen($o_Excel, $s_WorkBook) ;this will open the chosen xls file. Local $av_RangeRead = _Excel_RangeRead($o_Workbook, 'NURSE Training Pts', 'B' & $i_StartRow & ':N' & $i_EndRow) ; B and N cols contain the info Return $av_RangeRead EndIf EndFunc ;==>WorkBook_ReadToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: Student_ReturnRow ; Description ...: Reads the info from a control and returns an integer based on the value returned from the read ; Syntax ........: Student_ReturnRow($i_CtrlID) ; Parameters ....: $i_CtrlID - Control to read the info from ; Return values .: Success - Returns an integer to be used as a row number ; =============================================================================================================================== Func Student_ReturnRow($i_CtrlID) Local $i_Row = '' Switch GUICtrlRead($i_CtrlID) Case 'Trainer' $i_Row = 3 Case 'Student #1' $i_Row = 10 Case 'Student #2' $i_Row = 17 Case 'Student #3' $i_Row = 24 Case 'Student #4' $i_Row = 31 Case 'Student #5' $i_Row = 38 EndSwitch Return $i_Row EndFunc ;==>Student_ReturnRow