Jump to content

Recommended Posts

Posted

I really want to make a GUI that when you type a text in the Input box and click a button a Notepad should pop up and the text you wrote in the GUI input box appears in the Notepad.

I've tried this for an hour now and could not figure out how to do it correctly. It seems that it's giving me errors and when I'm correcting those errors I'm getting no where.

Please help modify my code below:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 218, 123, 192, 124)

$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)

$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case ($Input1)

ControlGetText ( "Form1", "Form1", Input1 )

Case ($Button1)

Run ("Notepad.exe")

ControlSend ( "Notepad", "Untitled - Notepad", $Input1, "" )

EndSwitch

WEnd

Thank You.

Posted

I've corrected your code (see the differences?), and also added formatting for my tired eyes..

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 218, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)
$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run ("Notepad.exe")
            Sleep(250)
            ControlSend ("Notepad", "", "Edit1", GUICtrlRead($Input1))
    EndSwitch
WEnd

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Posted

Thank You very much for the script really appreciate it,

but when I tried it few more times it's now opening notepad and there's no text written on notepad.

What's seems to be the problem?

Thank You.

Posted

Okay thanks it's working

Please I have 2 more questions:

1. How do you place these signs "< >", in the GUI, instead of writing them down in the input box if you were to expand from the above code you given me.

For example:

In the GUI input box you write the word "text" and it shows something like this in the Notepad: "<text>"

2. I want to make two (2) GUI Input boxes with one (1) GUI button. The first GUI input should show <text> in the first line of Notepad and the Second GUI input should show in the second line of notepad.

For example:

In the GUI you have:

Input1 [text1 ]

Input2 [text2 ]

Button

So when the button is clicked notepad appears:

<text1> in first line

<text2> in second line

Thank You.

Posted (edited)

@monoscout999 - good call on WinWait

@edena - the & is a concatenation character, @CRLF is a carriage return/line feed macro. See what I did here? Besides adding another input control, I just added to the ControlSend string parameter. Oh, and I replaced the Sleep with WinWait. And Oh again, I replaced ControlSend with ControlSetText. They both work the same here, I don't know the difference between them..

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 218, 123, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 24, 185, 21)
$Input2 = GUICtrlCreateInput("Input2", 16, 45, 185, 21)
$Button1 = GUICtrlCreateButton("Button1", 56, 72, 107, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Run ("Notepad.exe")
            WinWait("Notepad")
            ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">" & @CRLF & "<" & GUICtrlRead($Input2) & ">")
    EndSwitch
WEnd
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Posted

Wow!! Cool!!!

I kind of learned something thanks

but when I started to run the script it does only make the notepad appear but there are no text appearing on the notepad.

Posted

I replaced ControlSend with ControlSetText. They both work the same here, I don't know the difference between them..

ControlSend will send each key after the other, like if some one were writing the text. ControlSetText will put the entire text at once into the Edit.

Posted

Can you save the file to the desktop and write the file name which is stated in Input2 also with another GUI Input3 for placing file extenstions, example: .txt or .au3?

Like you have this GUI:

Input1 (will write this on notepad like this: <Input1>)

Input2 (you will write down the file name)

Input3 (you will write the file extension option here . For example: .txt or .au3

Button

So when the button is pressed the file will appear on the desktop with the name you given from Input2 and with the file extension you given from Input3.

This is how far I've gone with the script can anyone help me with this:

#include <ButtonConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

Opt("WinTitleMatchMode", 2)

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 212, 193, 192, 124)

$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)

$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)

$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)

$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

Run ("Notepad.exe")

WinWait("Notepad")

ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")

Sleep(1000)

Send("{ALTDOWN}f{ALTUP}a")

EndSwitch

WEnd

I've also tried: "FileSaveDialog" but cannot figure this out.

Thank You.

Posted

You don't need to open Notepad to achieve all this. If you explain more what you want to achieve we can help with that.

Meanwhile try:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run("Notepad.exe")
WinWait("Notepad")
ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")
Sleep(1000)
Send("{ALTDOWN}f{ALTUP}a")
Sleep(500)
Send(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
Sleep(500)
Send("{enter}")
EndSwitch
WEnd
Posted

Thank you very much for the script I really appreciate it.

Okay,

I want to create a one page html page that is why I really want Input1 to work just for me to start writing the html script.

But the script you given me does not write down the html tags on the notepad which are this "<" and this ">" and of course text must be written between the tags.

You can see that the previous script writes the html tags with the text given by somdcomputerguy

Thank You.

Posted

Try without notepad:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("File", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Html", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<table width=350 border=0 style="border-width: medium medium medium medium; border-spacing: 1px; border-style: solid solid solid solid; border-collapse: separate;">' & @CRLF
   $try &= '<tr>' & @CRLF
   $try &= '<td width=60%>' & GUICtrlRead($Input1) & '</td>'
   FileWrite(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3), $try)
   Sleep(1000)
   ShellExecute(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
EndSwitch
WEnd
Posted

Thanks JoHanatCent

I think I've corrected the problem with the first script you given me. I've increased the Sleep to 1000 and it works fine.

Your second code is even better makes work more looking professional.

Thank You

Posted

Sorry I'm back so excited with the scripts and I forgot something important.

How do you save the file in a destination like in the Desktop or in My Documents.

Thank You

Posted

Hi! JohnOne,

This how I placed the "@DesktopDir" script in one of my lines but it still doesn't work. I'm really bad in scripts please can you or anyone help.

Send(@DesktopDir, GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))

The full script is here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("Input2", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Input3", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Run("Notepad.exe")
WinWait("Notepad")
ControlSetText("Notepad", "", "Edit1", "<" & GUICtrlRead($Input1) & ">")
Sleep(1000)
Send("{ALTDOWN}f{ALTUP}a")
Sleep(1000)
Send(@DesktopDir, GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
Sleep(1000)
Send("{enter}")
EndSwitch
WEnd

Thank You.

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...