Jump to content
Sign in to follow this  
rabothole

Need to optimize script

Recommended Posts

rabothole

need some advise please,

I'm building a small program to check a couple of this for me, now with that said i don't know if the section of code is appropriate for the function to check one of the things. The function _loadUsersListbox() needs to check every 2 seconds if one of the fields in the database has changed is there an easier way of doing this?

connect_support_db()
_Query($sql, "update sup_ischange set Cha_Value = 1")
While 1
    _loadUsersListbox()
    $nMsg_rsync = GUIGetMsg()
    Switch $nMsg_rsync
;~  #####some code here#####
        
    EndSwitch
WEnd

_MySQLEnd($sql)
Func _loadUsersListbox()
        _GUICtrlListView_DeleteAllItems($ListView1)
        $var = _Query($sql, "SELECT * FROM sup_users")
        With $var
            While Not .EOF
                $SQL_USR = .Fields("User_Name" ).value
                $SQL_EXT = .Fields("User_Ext" ).value
                $SQL_STA = .Fields("User_Status" ).value
                $SQL_NUM = .Fields("User_Number" ).value
                $listbox_sql_update = $SQL_USR & "|" & $SQL_EXT & "|" & $SQL_STA
                $item1 = GUICtrlCreateListViewItem($listbox_sql_update, $ListView1)
                If $SQL_STA = "LINE BUSY" Then
                    GUICtrlSetBkColor($item1, $iListofflineColor)
                ElseIf $SQL_STA = "AVAILABLE" Then
                    GUICtrlSetBkColor($item1, $iListreadyColor)
                EndIf
                .MoveNext
            WEnd
        EndWith
EndFunc  ;==>_loadUsersListbox

Func connect_support_db()

    Global $ssUsername = "username"
    Global $ssPassword = "password"
    Global $ssDatabase = "DBname"
    Global $ssServer = "MYSQLserver"
    Global $sDriver = "{MySQL ODBC 3.51 Driver}"
    Global $iPort = 3306
    Global $sql = _MySQLConnect($ssUsername, $ssPassword, $ssDatabase, $ssServer, $sDriver, $iPort)
    If @error Then
        ProgressOff()
        MsgBox(0, "", "error connecting to database")
        Exit
    EndIf
    
EndFunc  ;==>connect_support_db

Share this post


Link to post
Share on other sites
martin

need some advise please,

I'm building a small program to check a couple of this for me, now with that said i don't know if the section of code is appropriate for the function to check one of the things. The function _loadUsersListbox() needs to check every 2 seconds if one of the fields in the database has changed is there an easier way of doing this?

connect_support_db()
_Query($sql, "update sup_ischange set Cha_Value = 1")
While 1
    _loadUsersListbox()
    $nMsg_rsync = GUIGetMsg()
    Switch $nMsg_rsync
;~  #####some code here#####
        
    EndSwitch
WEnd

_MySQLEnd($sql)
Func _loadUsersListbox()
        _GUICtrlListView_DeleteAllItems($ListView1)
        $var = _Query($sql, "SELECT * FROM sup_users")
        With $var
            While Not .EOF
                $SQL_USR = .Fields("User_Name" ).value
                $SQL_EXT = .Fields("User_Ext" ).value
                $SQL_STA = .Fields("User_Status" ).value
                $SQL_NUM = .Fields("User_Number" ).value
                $listbox_sql_update = $SQL_USR & "|" & $SQL_EXT & "|" & $SQL_STA
                $item1 = GUICtrlCreateListViewItem($listbox_sql_update, $ListView1)
                If $SQL_STA = "LINE BUSY" Then
                    GUICtrlSetBkColor($item1, $iListofflineColor)
                ElseIf $SQL_STA = "AVAILABLE" Then
                    GUICtrlSetBkColor($item1, $iListreadyColor)
                EndIf
                .MoveNext
            WEnd
        EndWith
EndFunc ;==>_loadUsersListbox

Func connect_support_db()

    Global $ssUsername = "username"
    Global $ssPassword = "password"
    Global $ssDatabase = "DBname"
    Global $ssServer = "MYSQLserver"
    Global $sDriver = "{MySQL ODBC 3.51 Driver}"
    Global $iPort = 3306
    Global $sql = _MySQLConnect($ssUsername, $ssPassword, $ssDatabase, $ssServer, $sDriver, $iPort)
    If @error Then
        ProgressOff()
        MsgBox(0, "", "error connecting to database")
        Exit
    EndIf
    
EndFunc ;==>connect_support_db
I can't offer any advise with much of your script, but putting the function _loadUsersListbox() inside the main while loop means that it is likely to be called much more frequently than every 2 seconds. Of course I don't know how long it takes to execute and it could take longer than 2 seconds.

I would do it like this

connect_support_db()
_Query($sql, "update sup_ischange set Cha_Value = 1")
AdlibEnable("_loadUsersListbox",2000)

While 1
;_loadUsersListbox()
    $nMsg_rsync = GUIGetMsg()
    Switch $nMsg_rsync
;~  #####some code here#####
        
    EndSwitch
WEnd
.
.
.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
rabothole

I can't offer any advise with much of your script, but putting the function _loadUsersListbox() inside the main while loop means that it is likely to be called much more frequently than every 2 seconds. Of course I don't know how long it takes to execute and it could take longer than 2 seconds.

I would do it like this

Thanks a million that made the difference i was looking for.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.