Jump to content
Sign in to follow this  
Scriptmaster

The Editor

Recommended Posts

Scriptmaster

Here is my latest project,

It is a simple code editor that supports all text formats.

It will execute batch directly and will also execute maths.

It also has the simple feature of shellexecute (POINTLESS!)

1 error I found was that I dont know how to tell if the script* has been saved so it has to ask the user

I need to know that for executing batch where the file (if saved/opened) is executed using 'Run($location)'

GOTO bottom for latest version

Edit*:----the script made in the program. not the code for the program.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
$saveyn = MsgBox(4, "", "Have you saved?")
If $saveyn = 6 Then
  Run($location)
Else
  MsgBox(48, "Warning", "Save before executing batch!")
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)

Please report errors but do not edit!

Edited by Scriptmaster

shutdown(1)

Share this post


Link to post
Share on other sites
martin

I dont know how to tell if the script has been saved

Maybe you mean you don't know if the script has been changed.

Search the forums for examples of $EN_CHANGE. You can set a flag to indicate a change was made every time the EN_CHANGE notification fires, and reset the flag whenever the script is saved.


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
Scriptmaster

Could I just find out if a variable has been declared with a dimple 1-0 return value?

I know I am in the wrong forum but I just wondered if that was poss

Edited by Scriptmaster

shutdown(1)

Share this post


Link to post
Share on other sites
martin

You mean could you find out if a variable is declared, with something like an IsDeclared function? Well you never know your luck..


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
Scriptmaster
Just what I need Edited by Scriptmaster

shutdown(1)

Share this post


Link to post
Share on other sites
Scriptmaster

Problem cured and V2.01 released

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
If Not IsDeclared("location") Then
  MsgBox(48, "Warning", "Save before executing batch!")
Else
  Run($location)
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;*au3;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;*au3;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)
Edited by Scriptmaster

shutdown(1)

Share this post


Link to post
Share on other sites
Scriptmaster

V2.53

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Script", 600, 400)
GUISetState(@SW_SHOW)
HotKeySet("{F5}", "execute1")
HotKeySet("{F6}", "htmlshow1")
HotKeySet("{F4}", "shellexecute1")
HotKeySet("{F3}", "Executebatch1")
GUICtrlCreateLabel("F3 Execute Batch, F4 ShellExecute, F5 Execute Math, F6 Show HTML", 10, 10)
$edit = GUICtrlCreateEdit("", 4, 54, 594, 343)
$save = GUICtrlCreateButton("Save", 74, 30, 70, 20)
$new = GUICtrlCreateButton("New", 144, 30, 70, 20)
$stop = GUICtrlCreateButton("Exit", 4, 30, 70, 20)
$open = GUICtrlCreateButton("Open", 214, 30, 70, 20)
$help = GUICtrlCreateButton("Info", 284, 30, 70, 20)
$progress = GUICtrlCreateProgress(370, 29, 220, 22)
Func execute1()
$executeans = Execute(GUICtrlRead($edit))
MsgBox("", "", $executeans)
EndFunc   ;==>execute1
Func htmlshow1()
Filewrite("C:/tmp/editorhtml.html", GUIctrlread($edit))
shellexecute("C:/tmp/editorhtml.html")
Filedelete("C:/tmp/editorhtml.html")
endfunc
Func shellexecute1()
ShellExecute(GUICtrlRead($edit))
EndFunc   ;==>shellexecute1
Func Executebatch1()
If Not IsDeclared("location") Then
  MsgBox(48, "Warning", "Save before executing batch!")
Else
  Run($location)
EndIf
EndFunc   ;==>Executebatch1
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Select
  Case $msg = $help
   MsgBox(64, "Editor", "By James B")
  Case $msg = $open
   $openfile = FileOpenDialog("open", "", "Text documents (*.bat;*.txt;*.vbs;*.au3;*.html;)")
   $netopen = FileOpen($openfile)
   $read_file = FileRead($netopen)
   GUICtrlSetData($progress, 100)
   Sleep(300)
   GUICtrlSetData($edit, $read_file)
   Sleep(300)
   GUICtrlSetData($progress, 0)
  Case $msg = $new
   GUICtrlSetData($edit, "")
  Case $msg = $stop
   ExitLoop
  Case $msg = $save
   $ynsave = MsgBox(1, "Editor", "Save?")
   If $ynsave = 1 Then
    $location = FileSaveDialog("Save", @MyDocumentsDir, "Text documents (*.bat;*.txt;*.vbs;*au3;*.html;)", 2)
    GUICtrlSetData($progress, 100)
    Sleep(300)
    $exists = FileExists($location)
    If $exists = 1 Then
     FileDelete($location)
    EndIf
    FileWrite($location, GUICtrlRead($edit))
    Sleep(300)
    GUICtrlSetData($progress, 0)
   EndIf
EndSelect
WEnd
FileClose($openfile)
FileClose($location)

shutdown(1)

Share this post


Link to post
Share on other sites
Scriptmaster

Will Be updated soon so stay tuned.


shutdown(1)

Share this post


Link to post
Share on other sites
Scriptmaster

Soon it will support autoit and coloured text!


shutdown(1)

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  

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
    • Reziskonh
      By Reziskonh
      Hi, everybody
      I look for GUI whose behavior similar to the message of an email client or antivirus
      In other words:
          Any PC screen able to calculate the size
          To consider the Task bar size
          To find the lower corner on the right/below and to nestle on it

      Notes:
      In GUI the GUICtrlCreateEdit field (as option) - that can be received and displayed through variable information
      Thanks a lot
      PS
      I use the translator, excuse if something is not clear
       

    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I found this function in the Internet
      It is to play audio files from  the compiled script
      I did not understand just one thing on this function
      func play($name, $wait = 0) local Const $SND_RESOURCE = 0x00040004 local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds if $wait = 0 then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) endIf return 1 endFunc What I did not understand was this variable
      local Const $SND_RESOURCE = 0x00040004 I know that this variable is contains the resource name
      But what if I want to change the name of the resource what i'll do?
      can i do that?
      Thanks in advance
       
    • VollachR
      By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
    • VollachR
      By VollachR
      I'm quite new to AutoIT and I have a very big batch file that I'm trying to completely re-write in Autoit, so far it's been going well but I got stuck with a certain part, hope someone can help.
      Here's the part of the batch script I'm currently stuck re-creating in AutoIT:
          :BeginLangMenu     if "%OptNum%" gtr "0" goto ShowLangMenu          ::Next Section code based on code supplied by Aacini from stackoverflow.com     :DefineLangMenu     for /L %%D in (1,1,99) do (        if exist Common\Settings\Data%%D.ini for /F "eol=# tokens=1,2 delims==" %%a in (Common\Settings\Data%%D.ini) do (                set line=%%a           if "!line:~2,5!" neq "clude" (              REM Define "normal" variables, i.e. Compressor, Method, etc.              set %%a=           ) else if "!line:~7!" neq "" (                   REM Define the base array elements, i.e. D1IncludeAR=%%b, D1ExcludeAR=%%b, ...              set D%%D%%a=%%b                   REM Set Show?? array elements with value equal 1, i.e. ShowAR=1, ...              REM when anyone of DiInclude?? or DiExclude?? corresponding elements was given              if defined D%%D%%a set Show!line:~7!=1                )        )     )          REM Define a list of language abbreviations, i.e. "langs=AR CZ DE ..."     REM and the corresponding language names array, i.e. lang[AR]=Arabic, ...     REM At same time, calculate original OptNum          for %%a in ("AR=Arabic" "CZ=Czech" "DE=German" "EN=English" "ES=Spanish" "ESMX=Spanish(Mexico)"                 "FR=French" "HU=Hungarian" "IT=Italian" "JP=Japanese" "KR=Korean" "PL=Polish"                 "PR=Portuguese" "PRBR=Portuguese(Brazil)" "RU=Russian" "ZH=Chinese") do (        for /F "tokens=1,2 delims==" %%b in (%%a) do (           set "langs=!langs! %%b"           set "lang[%%b]=%%c"           set /A "OptNum+=Show%%b"             )     )          ::NEXT 2 SECTIONS DISPLAYS THE LANGUAGE SELECTION MENU IF APPLICABLE     :ShowLangMenu     set /a step=%step%+1     :LangMenu     if "%OptNum%"=="0" Goto checksplit     echo %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% - Showing Language Selection Menu >> "%workdir%Conversion.log"     REM Show the language menu     set #=0     for %%a in (%langs%) do (        if defined Show%%a (           set /A #+=1     rem       echo [!#!] !lang[%%a]!           echo !lang[%%a]! >> %b2eincfilepath%\Lang.txt           set "option[!#!]=%%a"         )     )               %MYFILES1%\DROPDOWNBOX.exe /F:"%b2eincfilepath%\Lang.txt" "Choose Which Language to Compress" "STEP %step%: Language Selection"  /W:280 /RI /C:13 >nul > %b2eincfilepath%\LangAnswer.txt     if %ERRORLEVEL% EQU 0 del %b2eincfilepath%\LangAnswer.txt     if exist %b2eincfilepath%\LangAnswer.txt set /p "SelectLang="<%b2eincfilepath%\LangAnswer.txt     if not defined SelectLang goto LangError     if %SelectLang%==Arabic Set LangOpt=AR     if %SelectLang%==Czech set LangOpt=CZ     if %SelectLang%==German set LangOpt=DE     if %SelectLang%==English set LangOpt=EN     if %SelectLang%==Spanish set LangOpt=ES     if %SelectLang%==Spanish(Mexico) set LangOpt=ESMX     if %SelectLang%==French set LangOpt=FR     if %SelectLang%==Hungarian set LangOpt=HU     if %SelectLang%==Italian set LangOpt=IT     if %SelectLang%==Japanese set LangOpt=JP     if %SelectLang%==Korean set LangOpt=KR     if %SelectLang%==Polish set LangOpt=PL     if %SelectLang%==Portuguese set LangOpt=PR     if %SelectLang%==Portuguese(Brazil) set LangOpt=PRBR     if %SelectLang%==Russian set LangOpt=RU     if %SelectLang%==Chinese set LangOpt=ZH     if defined SelectLang Goto LangSet          ::SETS THE LANGUAGE SELECTION ACCORDING TO USER INPUT IN LANGUAGE MENU     :LangSet     set "LangIs=%LangOpt%"  
      Basically, here's what I need to do:
       Read from specific section of INI file but ONLY the Keys that have a Value. OR: A way to remove the keys without the values from the Array created by IniReadSection. A way to then take these stored values, and create a list of Languages based last 2-4 characters of the Key names. At this point, that said list is shown to user in DropDown box, after user make selection I need a way to move the Value of the Key related to the selected Language to a Variable, and ONLY the value for that specific Language. That's it basically, the rest is more or less Variable manipulation which isn't a problem.
      A little Example:
      My INI file have a Section like this:
      [LangInclude] IncludeAR=a IncludeCZ= IncludeDE=b IncludeEN= IncludeES=c IncludeESMX= IncludeFR= IncludeHU=d IncludeIT= IncludeJP= IncludeKR=e IncludePL= IncludePR= IncludePRBR= IncludeRU= IncludeZH= I need to get Only the keys that are set, in this case: IncludeAR, IncludeDE, IncludeES, IncludeHU & IncludeKR.
      I then need to convert these to a list of languages, in this example it will be (Arabic, German, Spanish, Hungarian, Korean).
      That list will be turned to DropDown selection, that I can do easily once I get the list correctly.
      After the user Selected, let us say for the example purpose Spanish, I need the Value of IncludeES to be moved into a Variable, like this: $Var=c
      I hope somebody can help me because I'm stuck after Importing the INI section with IniReadSection, everything I tried so far failed, the best I managed to do is Sort the array to have all the keys with values either at the first rows or last rows.
      I need some ideas.
      Help appreciated.
      Thanks
       
×