Jump to content

Adding Code To Button


Ritzky
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

Link to comment
Share on other sites

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
Link to comment
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"

Link to comment
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"

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
Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...