Jump to content

Recommended Posts

Posted (edited)

Hey there everyone. I am currently in the process of writing a macro to collect information for 5000 users. The users that I am collecting data from is currently running a wide range of platforms. Including windows NT4(mostly), 2000 and XP. Because of this and the fact that Autoit does not react very well with office 97 applications I have decided to make my back end text based. This has worked fairly well until I started to add huge amout of data's to the application.

I was wondering if anyone can suggest ways /other methods to make my code execute faster. I am aware that my code is a bit sloppy and that I am not the worlds best autoit coder :) (Some of the things on this forum is just amazing).

Please have a look at the following code. I have added a zip file with some test data that might be of help.

CODE
;=====================================================================

;-------------------------------------------------------------INCLUDES

;=====================================================================

#include <GuiConstants.au3>

#include <Array.au3>

#Include <GuiCombo.au3>

#include <File.au3>

#Include <GuiListView.au3>

#include <IE.au3>

;=====================================================================

;--------------------------------------------------------------OPTIONS

;=====================================================================

AutoItSetOption("MustDeclareVars", 1)

AutoItSetOption("GUICloseOnESC", 1)

AutoItSetOption("TrayIconDebug", 1)

HotKeySet("{F1}", "STARTHELP")

;=====================================================================

;------------------------------------------------------------Variables

;=====================================================================

Global $BUnitL, $one, $two, $SearchByLs, $MaxUser, $MainArray, $CURTXT

Global $DataPath = @ScriptDir &"\SDATA\"

Global $OtherPerfMessage = "Other Peripherals Eg: locally Attached Printers, PDA, Digital Cameras, Headphones/mic ...etc"

Global $LineCount = "1"

Global $TXTFileList[100]

Global $search, $TC, $TI, $str1, $str2, $str3, $TI2, $str4, $xlpath

Global $Txtname, $Label_STEP1, $Label_STEP2

Global $LCount

Global $MainGui

Global $Label_Name

Global $Combo_BUbyAlphabet

Global $Combo_Businessunit

Global $mainList

Global $Button_Close

Global $Button_AMEND

Global $Button_NEW

Global $Button_DELETE

Global $msg

Global $listCnt

Global $AmendGui

Global $listNumber, $NEWUserGui, $BuildingList

Global $ListInfo

Global $Label_1

Global $Label_2

Global $Input_LastName

Global $Input_FirstName

Global $Group_5

Global $Label_6

Global $Input_AMUsername

Global $Input_AMFloor

Global $Input_AMBuilding

Global $Label_10

Global $Label_11

Global $Group_12

Global $Label_14

Global $Checkbox_Blackberry

Global $Checkbox_Laptop

Global $Checkbox_Scanner

Global $Edit_OtherPh

Global $Label_18

Global $Button_AMCancel

Global $Button_AMSaveClose

Global $listCnt

Global $ask1

Global $tcnt1

Global $lineRead

Global $LineTest

Global $tSt

Global $info

TXTList()

Global $maxlines = "12"

Global $MaxUser = $LineCount + 1

Global $MainArray[$MaxUser][$maxlines]

Global $NEWUserGui

Global $NEWUserGui_Label_1

Global $NEWUserGui_Label_2

Global $NEWUserGui_Input_LastName

Global $NEWUserGui_Input_FirstName

Global $NEWUserGui_Group_5

Global $NEWUserGui_Label_6

Global $NEWUserGui_Input_Username

Global $NEWUserGui_Input_Floor

Global $NEWUserGui_Input_Building

Global $NEWUserGui_Label_10

Global $NEWUserGui_Label_11

Global $NEWUserGui_Group_12

Global $NEWUserGui_Label_14

Global $NEWUserGui_Checkbox_Blackberry

Global $NEWUserGui_Checkbox_Laptop

Global $NEWUserGui_Checkbox_Scanner

Global $NEWUserGui_Edit_OtherPh

Global $NEWUserGui_Label_18

Global $NEWUserGui_Button_Cancel

Global $NEWUserGui_Button_SaveClose

Global $Button_ConfirmAll

Global $Menu_File, $Submenu_CloseNoSave, $Submenu_SaveClose

Global $Menu_Tools, $Submenu_AppsByBU

Global $Menu_Help, $Submenu_Help

BuildingList()

;=====================================================================

;------------------------------------------------------START OF SCRIPT

;=====================================================================

$MainGui = GuiCreate("Data Verification Tool", 696, 580,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Menu_File = GUICtrlCreateMenu("File")

$Submenu_CloseNoSave = GUICtrlCreateMenuItem("Close Without Saving",$Menu_File)

$Submenu_SaveClose = GUICtrlCreateMenuItem("Save and Close",$Menu_File)

;$Menu_Tools = GUICtrlCreateMenu("Tools")

;$Submenu_AppsByBU = GUICtrlCreateMenuItem("Applications by BU",$Menu_Tools)

$Menu_Help = GUICtrlCreateMenu("Help")

$Submenu_Help = GUICtrlCreateMenuItem("HELP (F1)",$Menu_Help)

$Label_STEP1 = GuiCtrlCreateLabel("Step 1: Select Parent Business Unit", 10, 10, 400, 20)

$Label_STEP2 = GuiCtrlCreateLabel("Step 2: Select Child Business Unit", 280, 10, 400, 20)

$Combo_BUbyAlphabet = GuiCtrlCreateCombo("Choose", 10, 30, 270, 120)

GUICtrlSetData(-1,$SearchByLs)

$Combo_Businessunit = GuiCtrlCreateCombo("Business unit", 280, 30, 400, 120)

GUICtrlSetData(-1,$BUnitL)

$mainList = GUICtrlCreateListView("Confirmed Information|Name|Login Name|Building|Location|Blackberry|Laptop user|Scanner|Other Peripherals",10,60,670,430,$LVS_SINGLESEL,BitOr($LVS_EX_FULLROWSELECT,$LVS_EDITLABELS,$LVS_EX_CHECKBOXES,$LVS_EX_GRIDLINES))

$Button_Close = GuiCtrlCreateButton("Save and Close", 10, 530, 90, 20)

$Button_AMEND = GuiCtrlCreateButton("AMEND SELECTED USER", 280, 500, 140, 20)

$Button_NEW = GuiCtrlCreateButton("NEW USER", 420, 500, 120, 20)

$Button_DELETE = GuiCtrlCreateButton("DELETE SELECTED USER", 540, 500, 140, 20)

$Button_ConfirmAll = GuiCtrlCreateButton("CONFIRM ALL", 10, 500, 90, 20)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $Button_Close

SaveAndClose()

Case $msg = $GUI_EVENT_CLOSE

CloseNoSave()

Case $msg = $Combo_BUbyAlphabet

$CURTXT = GUICtrlRead($Combo_BUbyAlphabet) &".txt"

FetchData($CURTXT)

Case $msg = $Submenu_CloseNoSave

CloseNoSave()

Case $msg = $Submenu_SaveClose

SaveAndClose()

Case $msg = $Submenu_Help

STARTHELP()

Case $msg = $Button_AMEND

AMENDUser()

Case $msg = $Button_ConfirmAll

Confirmall()

Case $msg = $Button_DELETE

DELETEUser()

Case $msg = $Button_NEW

NEWUser()

Case $msg = $Combo_Businessunit

Poplist(GUICtrlRead($Combo_Businessunit))

Case Else

;;;

EndSelect

WEnd

Exit

;=====================================================================

;------------------------------------------------------------FUNCTIONS

;=====================================================================

Func CloseNoSave()

$ask1 = MsgBox(1,"WARNING","You are about to close the program without saving. Do you want to continue.")

If $ask1 = 1 Then Exit

EndFunc

Func STARTHELP()

_IECreate("file://\\server\share\Help.htm")

EndFunc

Func SaveAndClose()

$tcnt1 = 0

for $TC = 0 to (_GUICtrlListViewGetItemCount($mainList) - 1) Step 1

Local $is_Checked = _GUICtrlListViewGetCheckedState ($mainList, $TC)

If ($is_Checked <> $LV_ERR) Then

If ($is_Checked) Then

$TI = GUICtrlRead($Combo_Businessunit) &"|" &_GUICtrlListViewGetItemText($mainList,$TC,1) &"|" &_GUICtrlListViewGetItemText($mainList,$TC,2) &"|" &_GUICtrlListViewGetItemText($mainList,$TC,3) &"|"

While 1

$tcnt1 = $tcnt1 + 1

$lineRead = FileReadLine($DataPath &$CURTXT,$tcnt1)

If @error Then ExitLoop

If StringRight($lineRead,3) = "YES" Then ExitLoop

If StringInStr($lineRead,$TI) Then

If StringUpper(@UserName) = StringUpper(_GUICtrlListViewGetItemText($mainList,$TC,2)) Then

$str4 = @LogonDomain

Else

$str4 = StringTrimLeft($lineRead,StringInStr($lineRead,"|",0,5)) &".|"

$str4 = StringTrimRight($str4,(StringLen($str4) - StringInStr($str4,"|") + 1)) &"|"

EndIf

$TI2 = $TI &_GUICtrlListViewGetItemText($mainList,$TC,4) &"|" &$str4 &_GUICtrlListViewGetItemText($mainList,$TC,5) &"|" &_GUICtrlListViewGetItemText($mainList,$TC,6) &"|"

$TI2 = $TI2 &_GUICtrlListViewGetItemText($mainList,$TC,7) &"|" &_GUICtrlListViewGetItemText($mainList,$TC,8) &"|" &@UserName &"|" &"YES"

_FileWriteToLine($DataPath &$CURTXT,$tcnt1,$TI2,1)

ExitLoop

EndIf

WEnd

EndIf

EndIf

Next

Exit

EndFunc

;----------------------------------------------------------Confirm all

Func Confirmall()

If GUICtrlRead($Combo_Businessunit) <> "" Then

_GUICtrlListViewSetCheckState($mainList, -1, 1)

Else

MsgBox(0,"Information","Please select a business first")

EndIf

EndFunc

;---------------------------------------------------------BuildingList

Func BuildingList()

$TC = 0

$BuildingList = ""

While 1

$TC = $TC + 1

$lineRead = FileReadLine($DataPath &"data.dat",$TC)

If @error Then ExitLoop

$BuildingList = $BuildingList & $lineRead &"|"

WEnd

$BuildingList = StringTrimRight($BuildingList,1)

EndFunc

;------------------------------------------------------------TXTList

Func TXTList()

$search = FileFindFirstFile($DataPath &"*.txt")

Local $txtcount = 0

$TXTFileList[0] = 0

While 1

$Txtname = FileFindNextFile($search)

If @error Then ExitLoop

$txtcount = $txtcount + 1

$LCount = _FileCountLines($DataPath &$Txtname)

If $LCount > $LineCount Then $LineCount = $LCount

$TXTFileList[$txtcount] = StringTrimRight($Txtname,4)

$TXTFileList[0] = $TXTFileList[0] + 1

WEnd

For $TC = 1 to $TXTFileList[0] Step 1

$SearchByLs = $SearchByLs &$TXTFileList[$TC] &"|"

Next

EndFunc

;------------------------------------------------------------FUNCTIONS

Func AMENDUser()

$listCnt = _GUICtrlListViewGetSelectedCount($mainList)

If $listCnt = 0 Then

MsgBox(0,"Information","Please select a user to amend.")

Return

EndIf

$AmendGui = GuiCreate("Amend Details for ", 394, 395,-1, -1); , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$listNumber = _GUICtrlListViewGetCurSel ($mainList)

$ListInfo = _GUICtrlListViewGetItemTextArray($mainList,$listNumber)

;_ArrayDisplay($ListInfo)

$Label_1 = GuiCtrlCreateLabel("First Name:", 200, 30, 60, 20)

$Label_2 = GuiCtrlCreateLabel("Last Name:", 20, 30, 60, 20)

$Input_LastName = GuiCtrlCreateInput("", 80, 30, 110, 20)

$Input_FirstName = GuiCtrlCreateInput("", 260, 30, 110, 20)

If StringInStr($ListInfo[2],",") Then

GUICtrlSetData($Input_LastName,StringLeft($ListInfo[2],(StringInStr($ListInfo[2],",") -1)))

GUICtrlSetData($Input_FirstName,StringRight($ListInfo[2],(StringLen($ListInfo[2]) - (StringInStr($ListInfo[2],",") +1))))

Else

GUICtrlSetData($Input_LastName,$ListInfo[2])

EndIf

$Group_5 = GuiCtrlCreateGroup("User Details", 10, 0, 370, 150)

$Label_6 = GuiCtrlCreateLabel("Username:", 20, 60, 50, 20)

$Input_AMUsername = GuiCtrlCreateInput("", 80, 60, 110, 20)

GUICtrlSetData(-1,$ListInfo[3])

$Input_AMFloor = GuiCtrlCreateInput("", 100, 100, 110, 20)

GUICtrlSetData(-1,$ListInfo[5])

$Input_AMBuilding = GUICtrlCreateCombo("", 100, 120, 110, 120)

GUICtrlSetData(-1,$BuildingList,$ListInfo[4])

$Label_10 = GuiCtrlCreateLabel("Floor Location:", 20, 100, 70, 20)

$Label_11 = GuiCtrlCreateLabel("Building Name:", 20, 120, 80, 20)

$Group_12 = GuiCtrlCreateGroup("Device Details", 10, 160, 370, 190)

$Label_14 = GuiCtrlCreateLabel("Please select if any of the following devices are currently used by the user.", 20, 180, 350, 20)

$Checkbox_Blackberry = GuiCtrlCreateCheckbox("Blackberry", 30, 200, 90, 20)

$Checkbox_Laptop = GuiCtrlCreateCheckbox("Laptop", 150, 200, 100, 20)

$Checkbox_Scanner = GuiCtrlCreateCheckbox("Scanner", 270, 200, 90, 20)

$Edit_OtherPh = GuiCtrlCreateEdit("", 30, 260, 320, 80)

GUICtrlSetData(-1,$ListInfo[9])

$Label_18 = GuiCtrlCreateLabel($OtherPerfMessage, 30, 230, 320, 30)

$Button_AMCancel = GuiCtrlCreateButton("Cancel", 30, 360, 100, 20)

$Button_AMSaveClose = GuiCtrlCreateButton("Amend and Close", 260, 360, 90, 20)

GuiSetState()

If StringInStr(StringUpper($ListInfo[6]),"YES") Then GUICtrlSetState($Checkbox_Blackberry,$GUI_CHECKED)

If StringInStr(StringUpper($ListInfo[7]),"YES") Then GUICtrlSetState($Checkbox_Laptop,$GUI_CHECKED)

If StringInStr(StringUpper($ListInfo[8]),"YES") Then GUICtrlSetState($Checkbox_Scanner,$GUI_CHECKED)

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_AMSaveClose

AMupdate()

ExitLoop

Case $msg = $Button_AMCancel

ExitLoop

Case Else

;;;

EndSelect

WEnd

GUIDelete($AmendGui)

EndFunc

;-------------------------------------------------------------------------|

Func AMupdate()

$TI2 = GUICtrlRead($Combo_Businessunit) &"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 1) &"|"

$TI2 = $TI2 &_GUICtrlListViewGetItemText($mainList,$listNumber, 2) &"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 3) &"|"

$TI2 = $TI2 &_GUICtrlListViewGetItemText($mainList,$listNumber, 4) &"|"

If GUICtrlRead($Input_FirstName) <> "" And GUICtrlRead($Input_FirstName) <> "." Then

_GUICtrlListViewSetItemText ($mainList, $listNumber, 1, GUICtrlRead($Input_LastName) &", " &GUICtrlRead($Input_FirstName))

Else

_GUICtrlListViewSetItemText ($mainList, $listNumber, 1, GUICtrlRead($Input_LastName))

EndIf

_GUICtrlListViewSetCheckState($mainList, $listNumber, 0)

_GUICtrlListViewSetItemText ($mainList, $listNumber, 2, GUICtrlRead($Input_AMUsername))

_GUICtrlListViewSetItemText ($mainList, $listNumber, 4, GUICtrlRead($Input_AMFloor))

_GUICtrlListViewSetItemText ($mainList, $listNumber, 3, GUICtrlRead($Input_AMBuilding))

_GUICtrlListViewSetItemText ($mainList, $listNumber, 5, "NO")

_GUICtrlListViewSetItemText ($mainList, $listNumber, 6, "NO")

_GUICtrlListViewSetItemText ($mainList, $listNumber, 7, "NO")

If GUICtrlRead($Checkbox_Blackberry) = $GUI_CHECKED Then _GUICtrlListViewSetItemText ($mainList, $listNumber, 5, "YES")

If GUICtrlRead($Checkbox_Laptop) = $GUI_CHECKED Then _GUICtrlListViewSetItemText ($mainList, $listNumber, 6, "YES")

If GUICtrlRead($Checkbox_Scanner) = $GUI_CHECKED Then _GUICtrlListViewSetItemText ($mainList, $listNumber, 7, "YES")

If GUICtrlRead($Edit_OtherPh) <> $ListInfo[9] Then

$str2 = StringReplace(GUICtrlRead($Edit_OtherPh),"|"," ",0,0)

$str2 = StringReplace($str2,Chr(10)," ",0,0)

$str2 = StringReplace($str2,Chr(13)," ",0,0)

If $STR2 = "" Then $STR2 = "."

_GUICtrlListViewSetItemText ($mainList, $listNumber, 8, $STR2)

EndIf

$tcnt1 = 0

$str1 = _GUICtrlListViewGetItemText($mainList,$listNumber, 1)

$TI = GUICtrlRead($Combo_Businessunit) &"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 1) &"|"

$TI = $TI &_GUICtrlListViewGetItemText($mainList,$listNumber, 2) &"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 3) &"|"

$TI = $TI &_GUICtrlListViewGetItemText($mainList,$listNumber, 4) &"|"

While 1

$tcnt1 = $tcnt1 + 1

$lineRead = FileReadLine($DataPath &$CURTXT,$tcnt1)

if @error Then ExitLoop

If StringInStr($lineRead,$TI2) Then

$str3 = $TI &".|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 5)&"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 6)&"|"

$str3 = $str3 &_GUICtrlListViewGetItemText($mainList,$listNumber, 7)&"|" &_GUICtrlListViewGetItemText($mainList,$listNumber, 8)&"|" &@UserName &"|NO"

_FileWriteToLine($DataPath &$CURTXT,$tcnt1,$str3,1)

ExitLoop

EndIf

WEnd

EndFunc

;-------------------------------------------------------------------------|

Func DELETEUser()

$listCnt = _GUICtrlListViewGetSelectedCount($mainList)

If $listCnt = 0 Then

MsgBox(0,"Information","Please select a user to delete.")

Return

EndIf

$ask1 = MsgBox(1,"INFORMATION","ARE YOU SURE YOU WANT TO REMOVE THIS USER?")

$listCnt = _GUICtrlListViewGetCurSel($mainList)

If $ask1 = 1 Then

$tcnt1 = 0

$str1 = _GUICtrlListViewGetItemText($mainList,$listCnt, 1)

$TI = GUICtrlRead($Combo_Businessunit) &"|" &_GUICtrlListViewGetItemText($mainList,$listCnt, 1) &"|"

$TI = $TI &_GUICtrlListViewGetItemText($mainList,$listCnt, 2) &"|" &_GUICtrlListViewGetItemText($mainList,$listCnt, 3) &"|" &_GUICtrlListViewGetItemText($mainList,$listCnt, 4) &"|"

While 1

$tcnt1 = $tcnt1 + 1

$lineRead = FileReadLine($DataPath &$CURTXT,$tcnt1)

if @error Then ExitLoop

If StringInStr($lineRead,$TI) Then

FileWrite($DataPath &"zzzDeleted.dat",$lineRead &"| DELETED by " &@UserName &@CRLF)

_FileWriteToLine($DataPath &$CURTXT,$tcnt1,"",1)

ExitLoop

EndIf

WEnd

_GUICtrlListViewDeleteItem($mainList,$listCnt)

MsgBox(0,"Information","Selected User '"&$str1 &"' has been deleted")

EndIf

EndFunc

;-------------------------------------------------------------------------|

;-------------------------------------------------------------------------|

Func NEWUser()

If GUICtrlRead($Combo_Businessunit) = "" Then

MsgBox(0,"Information","Please select a Business Unit for this user first.")

Return

EndIf

;---------------------------------------------------------------------|

$NEWUserGui = GuiCreate("NEW USER CREATION", 394, 395,-1, -1); , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$NEWUserGui_Label_1 = GuiCtrlCreateLabel("First Name:", 200, 30, 60, 20)

$NEWUserGui_Label_2 = GuiCtrlCreateLabel("Last Name:", 20, 30, 60, 20)

$NEWUserGui_Input_LastName = GuiCtrlCreateInput("", 80, 30, 110, 20)

$NEWUserGui_Input_FirstName = GuiCtrlCreateInput("", 260, 30, 110, 20)

$NEWUserGui_Group_5 = GuiCtrlCreateGroup("User Details", 10, 0, 370, 150)

$NEWUserGui_Label_6 = GuiCtrlCreateLabel("Username:", 20, 60, 50, 20)

$NEWUserGui_Input_Username = GuiCtrlCreateInput("", 80, 60, 110, 20)

$NEWUserGui_Input_Floor = GuiCtrlCreateInput("", 100, 100, 110, 20)

$NEWUserGui_Input_Building = GUICtrlCreateCombo("", 100, 120, 110, 120)

$NEWUserGui_Label_10 = GuiCtrlCreateLabel("Floor Location:", 20, 100, 70, 20)

$NEWUserGui_Label_11 = GuiCtrlCreateLabel("Building Name:", 20, 120, 80, 20)

$NEWUserGui_Group_12 = GuiCtrlCreateGroup("Device Details", 10, 160, 370, 190)

$NEWUserGui_Label_14 = GuiCtrlCreateLabel("Please select if any of the following devices is currently used by the user.", 20, 180, 350, 20)

$NEWUserGui_Checkbox_Blackberry = GuiCtrlCreateCheckbox("Blackberry", 30, 200, 90, 20)

$NEWUserGui_Checkbox_Laptop = GuiCtrlCreateCheckbox("Laptop", 150, 200, 100, 20)

$NEWUserGui_Checkbox_Scanner = GuiCtrlCreateCheckbox("Scanner", 270, 200, 90, 20)

$NEWUserGui_Edit_OtherPh = GuiCtrlCreateEdit("", 30, 260, 320, 80)

$NEWUserGui_Label_18 = GuiCtrlCreateLabel($OtherPerfMessage, 30, 230, 320, 30)

$NEWUserGui_Button_Cancel = GuiCtrlCreateButton("Cancel", 30, 360, 100, 20)

$NEWUserGui_Button_SaveClose = GuiCtrlCreateButton("Create New User", 260, 360, 90, 20)

GUICtrlSetData($NEWUserGui_Input_Building, $BuildingList,"30 Milbank")

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $NEWUserGui_Button_SaveClose

NewUserGuiSave()

ExitLoop

Case $msg = $NEWUserGui_Button_Cancel

ExitLoop

Case Else

;;;

EndSelect

WEnd

GUIDelete($NEWUserGui)

;---------------------------------------------------------------------|

EndFunc

;-------------------------------------------------------------------------|

Func NewUserGuiSave()

DotEmpty()

$TI = GUICtrlRead($Combo_Businessunit) &"|" &GUICtrlRead($NEWUserGui_Input_LastName) &", " &GUICtrlRead($NEWUserGui_Input_FirstName) &"|"

$TI = $TI &GUICtrlRead($NEWUserGui_Input_Username) &"|" &GUICtrlRead($NEWUserGui_Input_Building) &"|" &GUICtrlRead($NEWUserGui_Input_Floor) &"|.|"

If GUICtrlRead($NEWUserGui_Checkbox_Blackberry) = 1 Then

$TI = $TI &"YES|"

Else

$TI = $TI &"NO|"

EndIf

If GUICtrlRead($NEWUserGui_Checkbox_Laptop) = 1 Then

$TI = $TI &"YES|"

Else

$TI = $TI &"NO|"

EndIf

If GUICtrlRead($NEWUserGui_Checkbox_Scanner) = 1 Then

$TI = $TI &"YES|"

Else

$TI = $TI &"NO|"

EndIf

$TI = $TI &GUICtrlRead($NEWUserGui_Edit_OtherPh) &"|" &@UserName &"|NO"

FileWrite($DataPath &$CURTXT,$TI& @CRLF)

$str1 = StringTrimLeft($TI,StringInStr($TI,"|"))

$str1 = StringTrimRight($str1,(StringLen($str1) - StringInStr($str1,"|",0,9) + 1))

$str2 = StringTrimRight($str1,(StringLen($str1) - StringInStr($str1,"|",0,4) + 1))

$str2 = $str2 &"|" &StringTrimLeft($str1,StringInStr($str1,"|",0,5))

GUICtrlCreateListViewItem("CONFIRM USER -> |"& $str2,$mainList)

EndFunc

Func DotEmpty()

If GUICtrlRead($NEWUserGui_Input_LastName) = "" Then GUICtrlSetData($NEWUserGui_Input_LastName,".")

If GUICtrlRead($NEWUserGui_Input_FirstName) = "" Then GUICtrlSetData($NEWUserGui_Input_FirstName,".")

If GUICtrlRead($NEWUserGui_Input_Username) = "" Then GUICtrlSetData($NEWUserGui_Input_Username,".")

If GUICtrlRead($NEWUserGui_Input_Floor) = "" Then GUICtrlSetData($NEWUserGui_Input_Floor,".")

If GUICtrlRead($NEWUserGui_Input_Building) = "" Then GUICtrlSetData($NEWUserGui_Input_Building,".")

If GUICtrlRead($NEWUserGui_Checkbox_Blackberry) = "" Then GUICtrlSetData($NEWUserGui_Checkbox_Blackberry,".")

If GUICtrlRead($NEWUserGui_Checkbox_Laptop) = "" Then GUICtrlSetData($NEWUserGui_Checkbox_Laptop,".")

If GUICtrlRead($NEWUserGui_Checkbox_Scanner) = "" Then GUICtrlSetData($NEWUserGui_Checkbox_Scanner,".")

If GUICtrlRead($NEWUserGui_Edit_OtherPh) = "" Then

GUICtrlSetData($NEWUserGui_Edit_OtherPh,".")

Else

$str3 = GUICtrlRead($NEWUserGui_Edit_OtherPh)

$str3 = StringReplace($str3,"|"," ",0,0)

$str3 = StringReplace($str3,Chr(10)," ",0,0)

$str3 = StringReplace($str3,Chr(13)," ",0,0)

If $str3 = "" Then $str3 = "."

GUICtrlSetData($NEWUserGui_Edit_OtherPh,$str3)

EndIf

EndFunc

Func FetchData($filename)

Global $count = 0

Global $BUnitL = ""

While 1

$Count = $Count + 1

$info = FileReadLine($DataPath &$filename,$Count)

if @error then ExitLoop

For $Count2 = 1 to $maxlines Step 1

$MainArray[$Count][($Count2 - 1)] = StringMid($info,(1 + StringInStr($info,"|",0,$Count2 -1)),(StringInStr($info,"|",0,$Count2) - StringInStr($info,"|",0,$Count2 -1)) -1)

Next

If not StringInStr($BUnitL,$MainArray[$Count][0]) Then

$BUnitL = $BUnitL &"|" &$MainArray[$Count][0]

EndIf

WEnd

;_ArrayDisplay($MainArray)

_GUICtrlListViewDeleteAllItems ($mainList)

_GUICtrlComboResetContent($Combo_Businessunit)

GUICtrlSetData($Combo_Businessunit,$BUnitL)

EndFunc

;-------------------------------------------------------------------------|

Func Poplist($SearchBY)

_GUICtrlListViewDeleteAllItems ($mainList)

Global $listdata = ""

$TC = 0

for $Count = 0 to ($MaxUser -1) Step 1

$one = StringLeft(StringUpper($MainArray[$count][0]),10)

$two = StringLeft(StringUpper($SearchBY),10)

If $one = $two Then

$listdata = "CONFIRM USER -> |"&$MainArray[$count][1] &"|" &$MainArray[$count][2] &"|" &$MainArray[$count][3] &"|" &$MainArray[$count][4] &"|"

$listdata = $listdata &$MainArray[$count][6] &"|" &$MainArray[$count][7] &"|" &$MainArray[$count][8] &"|" &$MainArray[$count][9]

GUICtrlCreateListViewItem($listdata,$mainList)

If $MainArray[$count][11] = "YES" Then _GUICtrlListViewSetCheckState($mainList, $TC, 1)

$TC = $TC + 1

EndIf

Next

EndFunc

;-------------------------------------------------------------------------|

Any suggestions would be much appreciated.

;)

Edited by DemonAngel
Posted

Just a couple of little things

Func SaveAndClose()
    $tcnt1 = 0
    For $TC = 0 To (_GUICtrlListViewGetItemCount($mainList) - 1) Step 1
        Local $is_Checked = _GUICtrlListViewGetCheckedState($mainList, $TC)
        If ($is_Checked <> $LV_ERR) Then
            If ($is_Checked) Then
                


; Could Be more efficient

Func SaveAndClose()
    $tcnt1 = 0
    Local $LVcount = (_GUICtrlListViewGetItemCount($mainList) - 1) ; only do this once
    For $TC = 0 To $LVcount Step 1
        Local $is_Checked = _GUICtrlListViewGetCheckedState($mainList, $TC)
        If ($is_Checked) And ($is_Checked <> $LV_ERR) Then ; 
            ; remove a secondary checking for the same thing and an uneedeed endif

8)

NEWHeader1.png

Posted (edited)

Well spotted Valuater, thanx for that. :) I have made the change.

Do you think there is anything I can change to the dropdown menu sections to speed them up?

Edited by DemonAngel

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...