Jump to content
Sign in to follow this  
vi6ora

Annoyin Problem

Recommended Posts

vi6ora

Hi. I am learning with a text editor i found here. I tryied to put something mine in it but i am getting annoying error.

Here Is the code

#include <GUIConstants.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
#include <String.au3>
#include <ModernMenu.au3>

Local $WIDTH, $HEIGHT, $WS_OVERLAPPEDWINDOW , $WS_VISIBLE , $WS_CLIPSIBLINGS, $WS_EX_ACCEPTFILES
$OpenedFilePath = "no file"
$OpenedFile = "no file"


$TextEditor = GUICreate("Simple Text Editor", 800, 600, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$EditControl = GUICtrlCreateEdit("", 0, 0, 800, 600, -1, $WS_EX_ACCEPTFILES)
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
$FileMenu       = GUICtrlCreateMenu("&File")
$nSideItem1     = _CreateSideMenu($FileMenu)
_SetSideMenuText($nSideItem1, "UTE Menu")
_SetSideMenuColor($nSideItem1, 0xAAFFAA) ; default color - white
_SetSideMenuBkColor($nSideItem1, 0x921801) ; bottom start color - dark blue
_SetSideMenuBkGradColor($nSideItem1, 0xFBCE92) ; top end color - light blue
$NEW        = _GUICtrlCreateODMenuItem("&Print" & @Tab & "Ctrl+S", $FileMenu, "shell32.dll", -55)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -55)
_GUICtrlCreateODMenuItem("", $FileMenu)
$OpenFile       = _GUICtrlCreateODMenuItem("&Open..." & @Tab & "Ctrl+O", $FileMenu)
_GUICtrlODMenuItemSetIcon(-1, "shell32.dll", -4)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -5)
$SaveFile       = _GUICtrlCreateODMenuItem("&Save" & @Tab & "Ctrl+S", $FileMenu, "shell32.dll", -7)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -79)
_GUICtrlCreateODMenuItem("", $FileMenu)
$PrintFile      = _GUICtrlCreateODMenuItem("&Print" & @Tab & "Ctrl+S", $FileMenu, "shell32.dll", -17)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -164)
_GUICtrlCreateODMenuItem("", $FileMenu)
$ExitFile       = _GUICtrlCreateODMenuItem("E&xit", $FileMenu, "shell32.dll", -28)
_SetMenuBkColor(0xAAFFAA)
_SetMenuIconBkColor(0x66BB66)
_SetMenuSelectBkColor(0xBBCC88)
_SetMenuSelectRectColor(0x222277)
_SetMenuSelectTextColor(0x770000)
_SetMenuTextColor(0x000000)



While 1
    $msg = GUIGetMsg()
Switch $msg
        Case $GUI_EVENT_CLOSE
            If $OpenedFilePath <> "no file" Then
                If GUICtrlRead($EditControl) <> FileRead($OpenedFile) Then
                    $SaveChangesBox = MsgBox(3, "Save File?", "Would you like to save the changes you made?")
                    If $SaveChangesBox = 6 Then
                        FileDelete($OpenedFilePath)
                        $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                        FileWrite($OpenedFile, GUICtrlRead($EditControl))
                        Exit
                    ElseIf $SaveChangesBox = 7 Then
                        Exit
                    EndIf
                Else
                    Exit
                EndIf
            Else
                Exit
            EndIf
      Case $PrintFile
            $PrintFileFunction = _FilePrint($OpenedFilePath)
            If $PrintFileFunction Then
                MsgBox(0, "Print", "The file was printed.")
            Else
                MsgBox(0, "Print Error", "The file was not printed.")
            EndIf
        Case $OpenFile
            $OpenFileDialog = FileOpenDialog("Load Text File", "", "Text Files (*.txt)")
            If FileExists($OpenFileDialog) Then
                $OpenedFilePath = $OpenFileDialog
                $PreviousFileRead = FileRead($OpenedFilePath)
                FileDelete($OpenedFilePath)
                GUICtrlSetData($EditControl, $PreviousFileRead)
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFile, $PreviousFileRead)
            EndIf
        Case $ExitFile
            Terminate()
        Case $SaveFile
            If $OpenedFilePath = "no file" Then
                $NewDialog = FileSaveDialog("New File", "", "Text Files (*.txt)")
                If $NewDialog <> "" Then
                    $OpenedFilePath = $NewDialog & ".txt"
                    $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                    FileWrite($OpenedFile, GUICtrlRead($EditControl))
                EndIf
            Else
                FileDelete($OpenedFilePath)
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFilePath, GUICtrlRead($EditControl))
            EndIf
        Case $MSG = $NEW
            If GUICtrlRead($EditControl)  <> "" Then
                $SaveChangesBox = MsgBox(3, "Save?", "Would you like to save?")
                If $SaveChangesBox = 6 Then
                    SaveFile()
                EndIf
            If $SaveChangesBox = 7 Then
                    FileDelete($OpenFile)
                    FileWrite($OpenFile, GUICtrlRead($EditControl))
                EndIf
                If $SaveChangesBox = 7 Then GUICtrlSetData($EditControl, "")
            Wend
        EndSwitch





Func Terminate()
    Exit
EndFunc

Func SaveFile()
            If $OpenedFilePath = "no file" Then
                $NewDialog = FileSaveDialog("New File", "", "Text Files (*.txt)")
                If $NewDialog <> "" Then
                    $OpenedFilePath = $NewDialog & ".txt"
                    $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                    FileWrite($OpenedFile, GUICtrlRead($EditControl))
                EndIf
                        Else
                FileDelete($OpenedFilePath)
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFilePath, GUICtrlRead($EditControl))
EndFunc

The error is saying: Error line 112

Error: "Wend statement with no matching "While" Statement"

Help me please.

Share this post


Link to post
Share on other sites
Melba23

vi6ora,

If you were to try running the code through Tidy (Ctrl-T in SciTE) you would soon see that you are missing the EndIf for the If on line 102.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Valuater

According to what I see... it's a mess for sure

here is the wend

If $SaveChangesBox = 7 Then GUICtrlSetData($EditControl, "")

Wend

EndSwitch

In the lower window pane of SciTE, click on the RED line

The upper window will go directly to the problem

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
vi6ora

Thanks i fixed it now. But i have one more problem [ hope its the last one ]. When i type somthing the save msg box popsup how can i fix it? I want to pop only if i pressed New or save or close, not only when i type something. Thanks in advance.

#include <GUIConstants.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
#include <String.au3>
#include <ModernMenu.au3>

Local $WIDTH, $HEIGHT, $WS_OVERLAPPEDWINDOW, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_EX_ACCEPTFILES
$OpenedFilePath = "no file"
$OpenedFile = "no file"


$TextEditor = GUICreate("Simple Text Editor", 800, 600, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$EditControl = GUICtrlCreateEdit("", 0, 0, 800, 600, -1, $WS_EX_ACCEPTFILES)
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
$FileMenu = GUICtrlCreateMenu("&File")
$nSideItem1 = _CreateSideMenu($FileMenu)
_SetSideMenuText($nSideItem1, "UTE Menu")
_SetSideMenuColor($nSideItem1, 0xAAFFAA) ; default color - white
_SetSideMenuBkColor($nSideItem1, 0x921801) ; bottom start color - dark blue
_SetSideMenuBkGradColor($nSideItem1, 0xFBCE92) ; top end color - light blue
$NEW = _GUICtrlCreateODMenuItem("&Print" & @TAB & "Ctrl+S", $FileMenu, "shell32.dll", -55)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -55)
_GUICtrlCreateODMenuItem("", $FileMenu)
$OpenFile = _GUICtrlCreateODMenuItem("&Open..." & @TAB & "Ctrl+O", $FileMenu)
_GUICtrlODMenuItemSetIcon(-1, "shell32.dll", -4)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -5)
$SaveFile = _GUICtrlCreateODMenuItem("&Save" & @TAB & "Ctrl+S", $FileMenu, "shell32.dll", -7)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -79)
_GUICtrlCreateODMenuItem("", $FileMenu)
$PrintFile = _GUICtrlCreateODMenuItem("&Print" & @TAB & "Ctrl+S", $FileMenu, "shell32.dll", -17)
_GUICtrlODMenuItemSetSelIcon(-1, "shell32.dll", -164)
_GUICtrlCreateODMenuItem("", $FileMenu)
$ExitFile = _GUICtrlCreateODMenuItem("E&xit", $FileMenu, "shell32.dll", -28)
_SetMenuBkColor(0xAAFFAA)
_SetMenuIconBkColor(0x66BB66)
_SetMenuSelectBkColor(0xBBCC88)
_SetMenuSelectRectColor(0x222277)
_SetMenuSelectTextColor(0x770000)
_SetMenuTextColor(0x000000)



While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            If $OpenedFilePath <> "no file" Then
                If GUICtrlRead($EditControl) <> FileRead($OpenedFile) Then
                    $SaveChangesBox = MsgBox(3, "Save File?", "Would you like to save the changes you made?")
                    If $SaveChangesBox = 6 Then
                        FileDelete($OpenedFilePath)
                        $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                        FileWrite($OpenedFile, GUICtrlRead($EditControl))
                        Exit
                    ElseIf $SaveChangesBox = 7 Then
                        Exit
                    EndIf
                Else
                    Exit
                EndIf
            Else
                Exit
            EndIf
        Case $PrintFile
            $PrintFileFunction = _FilePrint($OpenedFilePath)
            If $PrintFileFunction Then
                MsgBox(0, "Print", "The file was printed.")
            Else
                MsgBox(0, "Print Error", "The file was not printed.")
            EndIf
        Case $OpenFile
            $OpenFileDialog = FileOpenDialog("Load Text File", "", "Text Files (*.txt)")
            If FileExists($OpenFileDialog) Then
                $OpenedFilePath = $OpenFileDialog
                $PreviousFileRead = FileRead($OpenedFilePath)
                FileDelete($OpenedFilePath)
                GUICtrlSetData($EditControl, $PreviousFileRead)
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFile, $PreviousFileRead)
            EndIf
        Case $ExitFile
            Terminate()
        Case $SaveFile
            If $OpenedFilePath = "no file" Then
                $NewDialog = FileSaveDialog("New File", "", "Text Files (*.txt)")
                If $NewDialog <> "" Then
                    $OpenedFilePath = $NewDialog & ".txt"
                    $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                    FileWrite($OpenedFile, GUICtrlRead($EditControl))
                EndIf
            Else
                FileDelete($OpenedFilePath)
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFilePath, GUICtrlRead($EditControl))
            EndIf
        Case $msg = $NEW
            If GUICtrlRead($EditControl) <> "" Then
                $SaveChangesBox = MsgBox(3, "Save?", "Would you like to save?")
                If $SaveChangesBox = 6 Then
                    SaveFile()
                EndIf
                If $SaveChangesBox = 7 Then
                    FileDelete($OpenFile)
                    FileWrite($OpenFile, GUICtrlRead($EditControl))
                EndIf
                If $SaveChangesBox = 7 Then GUICtrlSetData($EditControl, "").


EndIf
    EndSwitch





WEnd
    Func Terminate()
        Exit
    EndFunc   ;==>Terminate


    Func SaveFile()
        If $OpenedFilePath = "no file" Then
            $NewDialog = FileSaveDialog("New File", "", "Text Files (*.txt)")
            If $NewDialog <> "" Then
                $OpenedFilePath = $NewDialog & ".txt"
                $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
                FileWrite($OpenedFile, GUICtrlRead($EditControl))
            EndIf
        Else
            FileDelete($OpenedFilePath)
            $OpenedFile = FileOpen($OpenedFilePath, 0 + 2)
            FileWrite($OpenedFilePath, GUICtrlRead($EditControl))
EndIf
        EndFunc   ;==>SaveFile

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  

×