Sign in to follow this  
Followers 0
JustinReno

Refresh Problem

3 posts in this topic

#1 ·  Posted (edited)

I have this script that I have been working on, called Network Emailer. The program is a network emailer that can send messages within a network. The only problem I have with it is when you click refresh to get new messages. If I get a new message by clicking refresh, click on the message, it sometimes only fills in the From field. Sorry if this is an unclear explanation, if so, I think it would be clearer to look over the code.

I think I have the problem pinpointed but you need the whole (138 line) code to see. And I tried to make a reproducer for this but, this is as small as it gets.

Here is the script:

#Include <String.au3>

Global $User, $List, $MessageNames, $ReadFrom, $ReadSubject, $ReadMessage, $From, $Subject, $Message

$GUI = GUICreate("Network Emailer", 147, 118, -1, -1, -1, 0x00000080)
GUICtrlCreateLabel("Username:", 0, 0, 55, 17)
$Username = GUICtrlCreateInput(@UserName, 0, 16, 146, 21)
GUICtrlCreateLabel("Password:", 0, 48, 53, 17)
$Password = GUICtrlCreateInput("", 0, 64, 146, 21, 0x0020)
$Login = GUICtrlCreateButton("Login", 0, 92, 146, 25, 0x0001)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case - 3
            Exit
        Case $Login
            If Not FileExists(@ScriptDir & "\" & GUICtrlRead($Username) & "") Then
                $AsktoCreate = MsgBox(68, "Network Emailer", "Username does not exist. Do you want to register?")
                If $AsktoCreate = 6 Then
                    DirCreate(@ScriptDir & "\" & GUICtrlRead($Username) & "")
                    IniWrite(@ScriptDir & "\" & GUICtrlRead($Username) & "\Settings.ini", "Settings", "Password", _StringEncrypt(1, GUICtrlRead($Password), "Network Emailer"))
                EndIf
            EndIf
            If FileExists(@ScriptDir & "\" & GUICtrlRead($Username) & "") Then
                $User = GUICtrlRead($Username)
                If GUICtrlRead($Password) == _StringEncrypt(0, IniRead(@ScriptDir & "\" & GUICtrlRead($Username) & "\Settings.ini", "Settings", "Password", ""), "Network Emailer") Then
                    GUIDelete($GUI)
                    _Main()
                EndIf
            EndIf
    EndSwitch
WEnd

Func _Main()
    $GUI = GUICreate("Network Emailer - " & $User & "", 347, 274)
    $List = GUICtrlCreateList("", 0, 16, 121, 227)
    GUICtrlCreateLabel("Messages:", 0, 0, 55, 17)
    GUICtrlCreateLabel("Selected Message:", 128, 0, 95, 17)
    GUICtrlCreateLabel("From:", 136, 24, 27, 17)
    $From = GUICtrlCreateInput("", 136, 40, 121, 21)
    GUICtrlCreateLabel("Subject:", 136, 72, 43, 17)
    $Subject = GUICtrlCreateInput("", 136, 88, 121, 21)
    GUICtrlCreateLabel("Message:", 136, 120, 50, 17)
    $Message = GUICtrlCreateEdit("", 136, 136, 209, 105)
    $New = GUICtrlCreateButton("New", 0, 248, 75, 25, 0)
    $Delete = GUICtrlCreateButton("Delete", 80, 248, 75, 25, 0)
    $Refresh = GUICtrlCreateButton("Refresh", 160, 248, 75, 25, 0)
    $ChangePassword = GUICtrlCreateButton("Change Password", 240, 248, 106, 25, 0)
    _CheckForMessages()
    GUISetState(@SW_SHOW)
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case - 3
                Exit
            Case $List
                For $A = 1 To $MessageNames[0]
                    If GUICtrlRead($List) = $MessageNames[$A] Then ExitLoop
                Next
                $ReadMessageFrom = IniRead(@ScriptDir & "\" & $User & "\Messages.ini", $MessageNames[$A], "From", "")
                $ReadMessageSubject = IniRead(@ScriptDir & "\" & $User & "\Messages.ini", $MessageNames[$A], "Subject", "")
                $ReadMessageMessage = IniRead(@ScriptDir & "\" & $User & "\Messages.ini", $MessageNames[$A], "Message", "")
                GUICtrlSetData($From, $ReadMessageFrom)
                GUICtrlSetData($Subject, $ReadMessageSubject)
                GUICtrlSetData($Message, $ReadMessageMessage)
            Case $New
                _New()
            Case $Delete
                For $B = 1 To $MessageNames[0]
                    If GUICtrlRead($List) = $MessageNames[$B] Then
                        IniDelete(@ScriptDir & "\" & $User & "\Messages.ini", $MessageNames[$B])
                        _CheckForMessages()
                        ExitLoop
                    EndIf
                Next
            Case $Refresh
                _CheckForMessages()
                ;If @Compiled = 1 Then Run(FileGetShortName(@ScriptFullPath))
                ;If @Compiled = 0 Then Run(@AutoItExe & " /AutoIt3ExecuteScript " & FileGetShortName(@ScriptFullPath))
                ;Exit
            Case $ChangePassword
                $AskOldPassword = InputBox("Network Emailer", "Please enter old password:", "", "*")
                If $AskOldPassword == _StringEncrypt(0, IniRead(@ScriptDir & "\" & $User & "\Settings.ini", "Settings", "Password", ""), "Network Emailer") Then
                    $AskNewPassword = InputBox("Network Emailer", "Please enter a new password:", "", "*")
                    If Not @error Then IniWrite(@ScriptDir & "\" & $User & "\Settings.ini", "Settings", "Password", _StringEncrypt(1, $AskNewPassword, "Network Emailer"))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _New()
    $GUI = GUICreate("Network Emailer", 186, 166)
    GUICtrlCreateLabel("Contact Name:", 0, 0, 75, 17)
    $ContactName = GUICtrlCreateInput("", 0, 16, 121, 21)
    GUICtrlCreateLabel("Subject:", 0, 48, 43, 17)
    $Subject = GUICtrlCreateInput("", 0, 64, 121, 21)
    GUICtrlCreateLabel("Message:", 0, 96, 50, 17)
    $Message = GUICtrlCreateInput("", 0, 112, 121, 21)
    $Send = GUICtrlCreateButton("Send", 0, 140, 75, 25, 0x0001)
    GUISetState(@SW_SHOW)
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case - 3
                GUIDelete($GUI)
                ExitLoop
            Case $Send
                $ReadContactName = GUICtrlRead($ContactName)
                $ReadSubject = GUICtrlRead($Subject)
                $ReadMessage = GUICtrlRead($Message)
                If FileExists(@ScriptDir & "\" & $ReadContactName & "") Then
                    IniWrite(@ScriptDir & "\" & $ReadContactName & "\Messages.ini", $ReadSubject, "From", $User)
                    IniWrite(@ScriptDir & "\" & $ReadContactName & "\Messages.ini", $ReadSubject, "Subject", $ReadSubject)
                    IniWrite(@ScriptDir & "\" & $ReadContactName & "\Messages.ini", $ReadSubject, "Message", $ReadMessage)
                    MsgBox(64, "Network Emailer", "Done!")
                    GUIDelete($GUI)
                    ExitLoop
                Else
                    MsgBox(16, "Network Emailer", "That contact doesn't exist! "&@CRLF&"Please select another.")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>_New

Func _CheckForMessages()
    GUICtrlSetData($List, "")
    GUICtrlSetData($From, "")
    GUICtrlSetData($Subject, "")
    GUICtrlSetData($Message, "")
    If FileExists(@ScriptDir & "\" & $User & "\Messages.ini") And Not FileGetSize(@ScriptDir & "\" & $User & "\Messages.ini") = 0 Then
        $MessageNames = IniReadSectionNames(@ScriptDir & "\" & $User & "\Messages.ini")
        For $C = 1 To $MessageNames[0]
            GUICtrlSetData($List, $MessageNames[$C])
        Next
    EndIf
EndFunc   ;==>_CheckForMessagesoÝ÷ Øw«z+0«H¶§+-êk¡¹^ªÞi«­¢+Ø$$%
ÍÀÌØí1¥ÍÐ($$$%½ÈÀÌØíôÄQ¼ÀÌØí5ÍÍ9µÍlÁt($$$$%%U%
ÑɱI ÀÌØí1¥ÍФôÀÌØí5ÍÍ9µÍlÀÌØítQ¡¸á¥Ñ1½½À($$$%9áÐ($$$$ÀÌØíI5ÍÍɽ´ô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíUÍȵÀìÅÕ½ÐìÀäÈí5ÍÍ̹¥¹¤ÅÕ½Ðì°ÀÌØí5ÍÍ9µÍlÀÌØít°ÅÕ½Ðíɽ´ÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($$$$ÀÌØíI5ÍÍMÕ©Ðô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíUÍȵÀìÅÕ½ÐìÀäÈí5ÍÍ̹¥¹¤ÅÕ½Ðì°ÀÌØí5ÍÍ9µÍlÀÌØít°ÅÕ½ÐíMÕ©ÐÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($$$$ÀÌØíI5ÍÍ5ÍÍô%¹¥I¡MÉ¥ÁѥȵÀìÅÕ½ÐìÀäÈìÅÕ½ÐìµÀìÀÌØíUÍȵÀìÅÕ½ÐìÀäÈí5ÍÍ̹¥¹¤ÅÕ½Ðì°ÀÌØí5ÍÍ9µÍlÀÌØít°ÅÕ½Ðí5ÍÍÅÕ½Ðì°ÅÕ½ÐìÅÕ½Ðì¤($$$%U%
ÑɱMÑÑ ÀÌØíɽ´°ÀÌØíI5ÍÍɽ´¤($$$%U%
ÑɱMÑÑ ÀÌØíMթаÀÌØíI5ÍÍMթФ($$$%U%
ÑɱMÑÑ ÀÌØí5ÍÍ°ÀÌØíI5ÍÍ5Íͤ

Any point in direction or help would be greatly appreciated since I have been working on this bug for quite some time. :) Thanks.

Edited by JustinReno

Share this post


Link to post
Share on other sites



Anyone?

Share this post


Link to post
Share on other sites

2 different GUIs using the same variables to store control IDs.


"be smart, drink your wine"

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  
Followers 0