Sign in to follow this  
Followers 0
Ritzky

Adding Code To Button

56 posts in this topic

I have one more question. Is there a way (Like in VB) where you just double click a button in koda, and add Autoit script to it.

I hate having to link my autoit script with the gui manually. i cant understand how to do it.

Share this post


Link to post
Share on other sites



You have to link the button to the code you want to run, when it's pressed, in your script. This isn't VB, and Koda isn't Visual Studio.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

why do you want to do that??? that is not implemented on autoit... AutoIt is making to do scripts, not multi - module proyects or solutions...

On AutoIt to register an event you have to use a function in a loop to write a variable... then you check the variable.. and write your cases...

BTW what event do you want to check??

you can read from help about GUIGetMsg()function and GUIGetCursorInfo()

Edited by monoscout999

Share this post


Link to post
Share on other sites

ok i already built my script in auto it. it all works fine. no errors. now i created my gui, but the updown button doesn't show up when i launch the gui. and i don't know how to link the button with my code. like whenever i get the updown button to show up, i want to press the down button and it will lower a value in my script. like when i press the updown button down it will take a number "600" to "599"

Share this post


Link to post
Share on other sites

ok i want my button to do this:

Run(@WindowsDir & "\Notepad.exe", "", @SW_MAXIMIZE)

when i click on it. the button name is "save"

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ok i already built my script in auto it. it all works fine. no errors. now i created my gui, but the updown button doesn't show up when i launch the gui. and i don't know how to link the button with my code. like whenever i get the updown button to show up, i want to press the down button and it will lower a value in my script. like when i press the updown button down it will take a number "600" to "599"

put the code here.. to watch it.. i can make it an example but is better to all if you putit

If you make the GUI with Koda you should have a lines like this...

#Region ### START Koda GUI section ### Form=
;your GUI!
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

between shitch and endswhitch you have to add the button case maybe this...

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $mybutton
                        Run(@WindowsDir & "\Notepad.exe", "", @SW_MAXIMIZE)
    EndSwitch
WEnd

show us your script and we be able to help you :unsure:

Edited by monoscout999

Share this post


Link to post
Share on other sites

To decrease/increase value you can use this

#include <GuiConstantsEx.au3>
#include <Misc.au3>

$dll = DllOpen("user32.dll")

$number = 500
$GUI = GUICreate("Decrease/Increase Value", 200, 150)
$edit = GUICtrlCreateLabel($number,10, 70, 100, 20)
$up = GUICtrlCreateButton("Up", 80, 40, 50, 20)
$down = GUICtrlCreateButton("Down", 80, 65, 50, 20)

GUISetState()

While 1

    If _IsPressed("26", $dll) Then ; If UP pressed
        sleep(100)
        GUICtrlSetData($edit, $number + 1)
        $number += 1
    ElseIf _IsPressed("28", $dll) Then ; If Down pressed
        sleep(100)
        GUICtrlSetData($edit, $number - 1)
        $number -= 1
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
            DllClose($dll)
        Case $up
            GUICtrlSetData($edit, $number + 1)
            $number += 1
        Case $down
            GUICtrlSetData($edit, $number - 1)
            $number -= 1
    EndSwitch

WEnd

Share this post


Link to post
Share on other sites

thanks!

ok i got the updown buttons to work, now when i click the up button, the number goes up by 1. but it just goes up by one, it's not changing any actual code, its only changing the GUI.

im trying to get it, then when I press my "save" button, it will save the current numbers from the updown button, and then perform "Func StartMainScript( )"

the gui is completely done, i have it just like i want it to like.

the script is completely done, it does what it is supposed to do, but when i press a button on my gui it doesn't do nothing. i know u guys are ttrying to help, but i just dont understand what to do . :unsure:

So in simple form:

GUI =Done

Background Script = Done

I want the background script to link with the GUI, so that when I click a button on my GUI, it will launch a script: Func StartMainScript( )

maybe i just dont know where to put you guys code? i tried it but when i press a button nothing still pops up.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

maybe i just dont know where to put you guys code? i tried it but when i press a button nothing still pops up.

i already answer you.. look 3 post above . -.-

Edited by monoscout999

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@ Ritzky : You better post your full code. Without it we can't really know where's your problem..

Edit : Typnig!

Edited by Jayson

Share this post


Link to post
Share on other sites

whooa i got it working! thanks everyone, i just now realized what you guys are saying lol.

how to donate?

Share this post


Link to post
Share on other sites

ok i have just one more question, and i should be good to go. how to create a save button? lets say the time is 9:30, i want to change the time in the gui through the updown buttons (thanks for getting that to work), and change it to 9:45 and then save it.

Share this post


Link to post
Share on other sites

ever since i added the button:

While 2

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Help

ShellExecute("http://www.google.com)

EndSwitch

WEnd

it won't let me press the "x" button to close the application. i press it, and it dont do nothing.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Add this to close the window

Case $GUI_EVENT_CLOSE
            Exit
Edited by Jayson

Share this post


Link to post
Share on other sites

ok when i added that code, my help button didn't work no more.

sorry for my bad language, am not english.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Replace

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Help
ShellExecute("http://www.google.com")

EndSwitch
WEnd

by this :

While 1
    
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Help
            ShellExecute("http://www.google.com")
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Edit ; What do you mean by "change my box" ? Show some code if you want to get some help Posted Image

Edited by Jayson

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

You can save variables to an .ini like this

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

Global $Data = "Info.ini"
Global $iniRead = IniRead($Data, "Info", "Times", "7:40") ; this make 7:40 default value in case the key doesn't exists

$GUI = GUICreate("Saving data", 150, 50)
$input = GUICtrlCreateInput($iniread, 5, 5, 50, 20)
$save = GUICtrlCreateButton("Save", 60, 5, 50, 22)
GUISetState()

If GUICtrlRead($input) <> "7:30" Then
    MsgBox(64, "Error !", "Your script won't start with this value !")
Else
    StartMainScript()
EndIf

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $save
            IniWrite ($data, "Info", "Times", GUICtrlRead($input))
    EndSwitch

WEnd

Func StartMainScript()
    ConsoleWrite("Your script is running")
EndFunc

Then you can check if the value the user entenred is right and you can start your script.

And the Info.ini look like this

[Info]
Times=7:40
Edited by Jayson

Share this post


Link to post
Share on other sites

ok thanks that code works, but only with one button. it only reads the last button of my gui, and saves it to the INI. but it doesn't read all 4 of them? thank you for helping me.

Share this post


Link to post
Share on other sites

As people told you in other thread.. post your code.. If you do not show us the code you are having problems with, we cannot offer any sensible help..

Share this post


Link to post
Share on other sites

ok there is code ^^

now i want to set the time from the updown menu, and then i want to press "save" where it will save the code to the ini. and then i want a "load" button that will load the INI file, and after it loads i want to press a hotkey "f1" that will take those loaded times and then activate a script using those times.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0