Jump to content
Sign in to follow this  
Gaboury

Anything!

Recommended Posts

Gaboury

Hi guys.

I am very new to AutoIt and I would like to make any little program that could be useful... I started a little MP3 Player script but it is frikin hard and I don't know all the commands I need to. I know some of you guys must be kings in that domain but I am very new so if you give explanations please be precise. I don't want you to tell me what to write, I want to tell you what I should write and WHY. Because I want to learn.

So up to now, I've made the "Notepad" tutorial and I've made it also a bit changed... I also made a two-programs launcher :dance: Pretty bad but still, it practices me. I have a lot of problems with the functions, and some other things...

Here what my main problems are:

I don't know how to set a variable WITHOUT having it executed... it could be useful to define a variable that I would like to use in a function but without that one executing itself before that function is called...

I would like to have some advices about the "GUI" part because I really have many problems creating a nice GUI "Layout"... I read the tutorial included (the Help...:dance:) and it helped me a bit but there are some things that I don't understand because I usually speak French and some words in English used in the Help File are a bit complicated...

I would also like to be able to put a nice background or anything on my layout.

So if you have any advices about the GUI, the variables or anything, I will try to understand all what you guys can tell me to help because I really suck... I don't know if it can help but I know how to script for Counter-Strike so I have a LITTLE basic about scripting and everything but I really need help!

Thanks :whistle:

- Gaboury.

Note: Don't forget to explain why to do something, because just "copy-paste" doesn't raise me to another lvl of coding. If you are gonna make fun of me or tell me to do something without any explanations, I'd prefer you say nothing, cause it'll lead me nowhere. Thanks a lot.

Here are some of the basic programs I made (not all fully-working...):

2 Programs Launcher...

#include <GUIConstants.au3>
GUICreate("Gaboury's First Program", 150, 150)
Opt("GUIOnEventMode",1)
GUISetState(@SW_SHOW)
$notebutton = GUICtrlCreateButton ("Open Notepad", -1, -1)
GUICtrlSetOnEvent($notebutton,"notepad")
$firebutton = GUICtrlCreateButton ("Open FireFox", -1, 25)
GUICtrlSetOnEvent($firebutton,"firefox")

Func notepad()
    Run("Notepad.exe")
EndFunc

Func firefox()
    Run("C:\Program Files\Mozilla Firefox\firefox.exe")
EndFunc


While 1
    $exitstuff = GUIGetMsg()
    If $exitstuff = $GUI_EVENT_CLOSE Then ExitLoop Then Exit
Wend

Notepad Tutorial... With autosave and changing save directory...also asking for deletion of the file... :P  Only for me as it doesn't check for the path of the file, I just entered it and it deletes it if it's there..if it's not there it won't search for it so...

Run("Notepad.exe")
    WinWaitActive("Sans titre - Bloc-notes")
    Send("Bonjour.  Ceci est un test.  Suis-je capable d'écrire en dessous?")
    Send("{ENTER}")
    Send("Mais mon dieu, ca marche.")
    Send("{ENTER}")
    Send("Essayons de le sauvegarder maintenant.")
    Send("^s")
    WinWaitActive("Enregistrer sous", "&Nom du fichier :")
    Send("c:\documents and settings\Jaimie\bureau\")
    Send("{ENTER}")
    Send("Test.txt")
    WinWaitActive("Enregistrer sous", "&Enregistrer")
    Send("{ENTER}")
    WinClose ("Test.txt - Bloc-notes")

$deletebox = msgbox(4, "Delete File", "Veux tu supprimer le fichier qui vient d'être créé?")


If $deletebox = 6 Then
    FileDelete("C:\Documents and Settings\Jaimie\bureau\test.txt")
    msgbox(0, "Deleted", "File Deleted")

ElseIf $deletebox = 7 Then
    msgbox(0, "", "File didn't get deleted.")

EndIf

$mybox = msgbox(4, "Feedback", "Alors mon programme, tu l'aimes?")
If $mybox = 6 then
    msgbox(0, "You Rock!", "You rock buddy!")

elseif $mybox = 7 Then
    msgbox (0, "Crap", "You are an idiot!")
endif
Exit
Winclose("Notepad1.exe")

That's my quarter working MP3 player :P  One song added to the list, and not even working... :/

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
GUICreate("MP3 Player", 250, 250)
GUISetState(@SW_SHOW)
$roboto = GUICtrlCreateButton ("Mr. Roboto - 80's Styx", -1, -1)
GUICtrlSetOnEvent($roboto, "robsure")
GUIGetMsg ()


Func robsure()
    GUICreate("Are you sure?", 200, 100)
    GUICtrlCreateLabel("Are you sure you want to listen the song Mr. roboto?", -1, -1)
    $ok = GUICtrlCreateButton ("Yes", -1, 20)
    $no = GUICtrlCreateButton ("No", -1, 50)
If $ok = 1 then
    SoundPlay ( "C:\Documents and Settings\Jaimie\Bureau\Playlists iTunes\80's Styx\Album inconnu\Mr. Roboto.mp3")
ElseIf $no = 1 then

Endif

Endfunc


While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ProcessClose("AutoIt3.exe") Then ExitLoop
Wend

GUIDelete()
Edited by Gaboury

Share this post


Link to post
Share on other sites
B3TA_SCR1PT3R

$var = 'insert variable value here'

read the help file

get Scite it has a guibuilder that you can use to make nice gui's


[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Share this post


Link to post
Share on other sites
Gaboury

I know how to set variables... but how do I set them so they DONT get executed?!?

if you write:

$msgbox001 = msgbox(0,"1234","12345")

it will put "$msgbox001" as the alias but it will also make the msgbox...

Thanks anyway for the help, but I want to CODE the GUI, I don't want it to make itself alone...I wanna become (maybe) a programmer in the future and I'd like to learn now rather than later :whistle:

- Gaboury.

Share this post


Link to post
Share on other sites
Valuater

Thanks anyway for the help, but I want to CODE the GUI, I don't want it to make itself alone...I wanna become (maybe) a programmer in the future and I'd like to learn now rather than later :whistle:

<{POST_SNAPBACK}>

If that is what you want... really to learn how to script a GUI...then

I STRONGLY Suggest you look at this again

read the help file

get Scite it has a guibuilder that you can use to make nice gui's

<{POST_SNAPBACK}>

B3TA is absolutely CORRECT,

you can completely design the GUI.... then paste it to the SciTE program and REVIEW all of the scripting to help teach you how to do it... better than any question you could ask and

the answer you got from B3TA was the best answer you are going to get from your question and especially after your response to him

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Sokko

I know how to set variables... but how do I set them so they DONT get executed?!?

if you write:

$msgbox001 = msgbox(0,"1234","12345")

it will put "$msgbox001" as the alias but it will also make the msgbox...

Why would you ever want to not show the MsgBox in this case? There would be no point. The variable is set to the value that is returned from the button the user clicked. If the message box didn't show, the user wouldn't be able to click a button, the MsgBox wouldn't return a value, and you wouldn't have anything at all in your variable. Perhaps I'm just not understanding exactly what you want to do here.

Share this post


Link to post
Share on other sites
Gaboury

As I explained, I usually speak French. Some words from the Help File completely mix me up, and then I have some problems getting into it again.

I didn't tell him that in a mean way. I always say things directly and I know that sometimes offend people, but I didn't want to hurt you or anyone. I was just saying that I needed help and if there was anyway to code the gui entirely in AutoIt I would enjoy that because I would like to create a program entirely my self. I don't want anything that will code for myself or anything, I wanna get into, understand all the commands and be able to build a good program without needing any third party program...

I wasn't understanding what was the real role pf "Scite" into that, I just thought that I would make a layout and it would automatically add it to my script, without me doing anything else than designing it. That's what I didn't want. I didn't think enough before answering and I didn't want that. I am very sorry.

Thanks for claryfing. I am sorry B3TA. Thanks for your answer. Althought, anyone answered me about the possibility of setting a variable without it being executed. It would help me a lot, or either if someone could show me how make it so:

When I launch the script, and I click on a button (example: test), then it pop-ups a msgbox asking a question (anything..yes or no as an example)... and then depending on what the person answered, it would do something else... But I need to put a variable on the msgbox to know what the person chose, but I can't bind a command onto the variable because it would make the msgbox right away, not when the user clicks the button...

Thanks for all of your help.

- Gaboury.

Note: Is there anyway of making (example) a layout into photoshop and then importing it into AutoIt so it can be my program layout or anything, or an I just add like a little pic somewhere... Thanks for answering :whistle:

Share this post


Link to post
Share on other sites
quick_sliver007

Heres is a link to SciTe

It is an editor that makes reading code not as hard. It has a tool named that GUIbuilder in the tools menu item. That tool will help you make gui's, just the sizing and placement. You add the code later that makes the gui do stuff.

As for the question about variables not executing the function. Just don't set the variable to function until you are ready for it to perform the function. Like this.

Dim $msgbox001
; do other code until you need the varaible to do the function. then.....
;;;;;;;;;;;;
;;;;;;;;;
;;;;;;;
MsgBox(0,"","this is before the variabe")

$msgbox001 = MsgBox(0,"","this is with the variable $msgbox001")

.

Share this post


Link to post
Share on other sites
Sokko

When I launch the script, and I click on a button (example: test), then it pop-ups a msgbox asking a question (anything..yes or no as an example)... and then depending on what the person answered, it would do something else... But I need to put a variable on the msgbox to know what the person chose, but I can't bind a command onto the variable because it would make the msgbox right away, not when the user clicks the button...

In your own words, you "bind the variable" at the moment that you display the MsgBox. You do not need to create the MsgBox before you use it, and you do not need to assign the variable before you create the MsgBox. For an example, you can put the following lines anywhere in your script:

$variable = MsgBox(4,"Message Box","Please click a button.")
If $variable = 6 Then MsgBox(0,"Result","You clicked the Yes button!")
If $variable = 7 Then MsgBox(0,"Result","You clicked the No button!")

In your example, that code would come after the part that tells whether the user clicked the "test" button.

EDIT: Whoops, quick_sliver posted while I was typing.

Edited by Sokko

Share this post


Link to post
Share on other sites
AutoChris

Here is some good advice for you Gaboury:

Post easily-digestible questions into the Support forum. Listing your code for 3 programs and a half-dozen paragraphs basically saying you want to be a programmer are a little hard to digest and probably will be overlooked due to the sheer size of your post.

You could have just asked, "How do I add backgrounds to a GUI?" And "If I want to know what button someone clicked on a message box, how would I do that?" Those questions are quickly and easily answered and once you have that down and run into something else, feel free to post your next question.

Share this post


Link to post
Share on other sites
therks

I wasn't understanding what was the real role pf "Scite" into that, I just thought that I would make a layout and it would automatically add it to my script, without me doing anything else than designing it.  That's what I didn't want.  I didn't think enough before answering and I didn't want that.  I am very sorry.

<{POST_SNAPBACK}>

Actually, Scite is, to explain simply, a colour coded text editor that has support for AutoIt's code and functions. What the others are talking about is the GUIBuilder, which comes with Scite, and it will do exactly what you mentioned. You are given a window which you can place controls on, move them around, and then it will auto-generate the code for you. I know that's not what you're asking for, but what it WILL do for you, is give you a working example of how to create a GUI.

I suggest, use the GUIBuilder, and create something really simple. Like a window with just one button on it. Okay? Let it write that code for you. Now look at the code, and play around with it, change some of the numbers, some of the text. And everytime you make a change, even very little ones, run your code, and examine to see what has in the GUI.

For example, you may get this line in your code (this would be one line in many lines of code, this example will not work by itself):

GuiCtrlCreateButton('Button1', 10, 20, 100, 30)
  • First, run the code before you change it. Take a good look at the window, and try to remember what it looks like.
  • Second, try changing the first number (10) to something else (like 30), run the code again, and see what has happened to the button.
    • Did it move?
    • Did it change size?
    Noticing what has happened will tell you what that number in the function does.
  • Now just try playing with other parts of the code.
They key to my learning ability has been to take existing examples (like the code the GUIBuilder will give you) make little changes, and run the code again and again. Sometimes you will make a change and the script will not work, maybe it will give an error message. Try and figure out what caused the error, then undo the improper changes that you made.

It only took me a little while to figure out how to do the GUIBuilding, but I think that my background in webdesign may have helped with that. I already had experience placing objects/controls into specific places, so it came more naturally to me.

Share this post


Link to post
Share on other sites
Gaboury

SerialKiller... Thanks for that...very useful...But I still think that more information is always better than less... I posted those programs for the ones who had time to check and for them to know my level, so they would see I am a real nub...

Note: Don't forget to explain why to do something, because just "copy-paste" doesn't raise me to another lvl of coding. If you are gonna make fun of me or tell me to do something without any explanations, I'd prefer you say nothing, cause it'll lead me nowhere. Thanks a lot.

Next time, just don't answer. Thanks.

---------------------------------------------------------------------------------------

Okay for the others. Thanks a lot you guys. Only one thing, you guys didn't understood what I meant for the Function and variable thingy...

Here's what I mean:

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
GUICreate("MP3 Player", 250, 250)
GUISetState(@SW_SHOW)
$roboto = GUICtrlCreateButton ("Mr. Roboto - 80's Styx", -1, -1)
GUICtrlSetOnEvent($roboto, "robsure")
GUIGetMsg ()

[IMPORTANT PART, THATS HE MAIN IDEA ABOUT WHAT I AM ASKING]
Func robsure()
    $msgbox1 = msgbox(4,"Are you sure?", "Are you sure you want to listen to Mr. Roboto from 80's Styx?")
EndFunc
If $msgbox1 = 6 then
    SoundPlay ( "C:\Documents and Settings\Jaimie\Bureau\Playlists iTunes\80's Styx\Album inconnu\Mr. Roboto.mp3")
ElseIf $msbox1 = 7 then

Endif


While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ProcessClose("AutoIt3.exe") Then ExitLoop
Wend

GUIDelete()

Do you understand now with the code what I mean? Because like that, when I exec the script it will tell there is an error, $msgbox1 isn't defined...but if I define it, then it pops the window at the beginning... :/ ANy ideas?

Share this post


Link to post
Share on other sites
LxP

How about this? --

func myMsgBox()
    return msgBox(0x24, "Question", "123?")
endFunc

; ...some code...
$variable = myMsgBox()
if ($variable = 6) then ...

Share this post


Link to post
Share on other sites
Sokko

Do you understand now with the code what I mean? Because like that, when I exec the script it will tell there is an error, $msgbox1 isn't defined...but if I define it, then it pops the window at the beginning... :/ ANy ideas?

The problem is that you are combining GUIOnEventMode with GUIGetMsg. These are two completely different ways of programming a GUI, and you cannot use both of them at the same time.

The following two pieces of code do exactly the same thing, but they each use a different mode. The cause of the error message is that you've mishmashed both of these modes together. You can only use one or the other, not both. Look in the "GUI Reference" section of the help file for more information on these two modes.

This one uses Message Loop mode:

#include <GUIConstants.au3>
GUICreate("MP3 Player", 250, 250)
GUISetState(@SW_SHOW)
$roboto = GUICtrlCreateButton ("Mr. Roboto - 80's Styx", -1, -1)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $roboto Then
        If msgbox(4,"Are you sure?", "Are you sure you want to listen to Mr. Roboto from 80's Styx?") = 6 Then
            SoundPlay("C:\Documents and Settings\Jaimie\Bureau\Playlists iTunes\80's Styx\Album inconnu\Mr. Roboto.mp3")
        EndIf
    EndIf
Wend

GUIDelete()

And this one uses Event mode:

#include <GUIConstants.au3>
Opt("GUIOnEventMode",1)
GUICreate("MP3 Player", 250, 250)
GUISetState(@SW_SHOW)
$roboto = GUICtrlCreateButton ("Mr. Roboto - 80's Styx", -1, -1)
GUICtrlSetOnEvent($roboto, "robsure")
GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "close")

Func robsure()
    If msgbox(4,"Are you sure?", "Are you sure you want to listen to Mr. Roboto from 80's Styx?") = 6 Then
        SoundPlay("C:\Documents and Settings\Jaimie\Bureau\Playlists iTunes\80's Styx\Album inconnu\Mr. Roboto.mp3")
    EndIf
EndFunc

Func close()
    Exit
EndFunc

While 1
    Sleep(2000)
Wend

I am happy to answer any questions you might have about either of those scripts.

Edited by Sokko

Share this post


Link to post
Share on other sites
Gaboury

For "if"s you don't need it to be a variable? I was sure yes, that was why I needed them to be defined...now it whould work good :whistle:

Thanks for all of your answers, if I have any other problems I will ask you guys again :dance:.

Thanks :dance:

- Gaboury.

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  

×