Jump to content

Big chunk of code into a variable?


Recommended Posts

I've got a hugh chunk of code that I need to keep copying and pasting, but is there a way I can just put it into one variable so all that code won't cramp up the page? I never want it to go away either, it needs to stay alive forever.

Link to comment
Share on other sites

I've got a hugh chunk of code that I need to keep copying and pasting, but is there a way I can just put it into one variable so all that code won't cramp up the page? I never want it to go away either, it needs to stay alive forever.

We don't know what the code is so its hard to answer your question.

Link to comment
Share on other sites

We don't know what the code is so its hard to answer your question.

Maybe variable was the wrong word perhaps? Really just a name of a piece of code so I don't have to keep copy and pasting it.

Say if I wanted this code to be put into a variable (or a shortcut name, whatever):

Do
$xchange = 29
While $xchange <= 49
$xchange = $xchange + 1
WEnd
Until 20 = 21

how would you do that?

Link to comment
Share on other sites

Turn it into a function...

Func _Code ()
Do
$xchange = 29
While $xchange <= 49
$xchange = $xchange + 1
WEnd
Until 20 = 21
EndFunc;==>_Code

Thats a ridiculous pice of script though... but you get the idea.

to use the code in the script just use "_Code ()" eg

MsgBox (48, "", _Code ())

Func _Code ()
Return 3
EndFunc;==>_Code
Edited by mdiesel
Link to comment
Share on other sites

Turn it into a function...

Func _Code ()
Do
$xchange = 29
While $xchange <= 49
$xchange = $xchange + 1
WEnd
Until 20 = 21
EndFunc;==>_Code

Thats a ridiculous pice of script though... but you get the idea.

to use the code in the script just use "_Code ()" eg

MsgBox (48, "", _Code ())

Func _Code ()
Return 3
EndFunc;==>_Code
So I just put _Code () anywhere and it'll run it, right?
Link to comment
Share on other sites

Yep! its amazing isnt it. Just make sure the actuall function is somewhere in the script. all the functions you use (like msgbox) are written in a similar way, and automatically included, you are just writing your own. (That last sentence is dramatically oversimplified...)

MsgBox (48, "", _Code ())
MsgBox (48, _Code (), "")
MsgBox (48, "", 5 * _Code ())

Func _Code ()
Return 3
EndFunc;==>_Code

etc!!

Edited by mdiesel
Link to comment
Share on other sites

Yep! its amazing isnt it.

Wow I thought that guy wanted a script that puts a part of code into your clipboard, so I hesitated to answer.

But yeah, its amazing he doesn't know what a function is. Since the scripts I was spoon feeding him had functions :)

Link to comment
Share on other sites

  • Developers

Wow I thought that guy wanted a script that puts a part of code into your clipboard, so I hesitated to answer.

But yeah, its amazing he doesn't know what a function is. Since the scripts I was spoon feeding him had functions :)

I am surprised that your are surprised about it.

The OP doesn't really care about trying to learn and research first, just wants his "problem" resolved as fast as possible.

I bet he will try any script you post as a solution to his problem without understanding it fist.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I am surprised that your are surprised about it.

The OP doesn't really care about trying to learn and research first, just wants his "problem" resolved as fast as possible.

I bet he will try any script you post as a solution to his problem without understanding it fist.

Jos

Oh well, no more mr. nice guy from me then.

He has to learn someday right ? :)

Link to comment
Share on other sites

have I missed something? Or is it just be mean to noobs day? I know it took me a while to get my head around the ins and outs of parameters and functions. I just read the helpfile though...

@FadeToGrey - Whatever you do, read the helpfile first - It knows best, and is desceptively easy to understand.

MDiesel

Link to comment
Share on other sites

  • Developers

have I missed something? Or is it just be mean to noobs day? I know it took me a while to get my head around the ins and outs of parameters and functions. I just read the helpfile though...

@FadeToGrey - Whatever you do, read the helpfile first - It knows best, and is desceptively easy to understand.

MDiesel

It is not mean to noobs day and as far as I can tell I am not being mean, just honest.

I see many newcomers lately, of which i guess most are still young and want to start making bots and they largely are being very impatient and not willing to spend anytime to learn/read/research before starting to create many threads/posts asking question that clearly show they haven't put much thought into the questions.

So, I have no issue with anybody that demonstrates the will to learn. :)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yep! its amazing isnt it. Just make sure the actuall function is somewhere in the script. all the functions you use (like msgbox) are written in a similar way, and automatically included, you are just writing your own. (That last sentence is dramatically oversimplified...)

MsgBox (48, "", _Code ())
MsgBox (48, _Code (), "")
MsgBox (48, "", 5 * _Code ())

Func _Code ()
Return 3
EndFunc;==>_Code

etc!!

Thanks, just what I needed, makes the coding easier, you know.
Link to comment
Share on other sites

no probs, thats what its supposed to do.

@Jos: Thats OK then, I thought the op had done something horribly wrong and was reposting the same thing for the 5th time, in which case I probably would have ignored it...

@FadeToGrey

have you seen some of the functions I made? check out these ones!

@Jos part 2: Don't worry Jos, it's school holidays soon, and as GeoSoft (I think) said: "and just a reminder, not long until school is out for 1/2 the world. That's when the annual crop of total idiots start to come out in strength. You know the ones, their shoe size is larger than their IQ. "

:)

Edited by mdiesel
Link to comment
Share on other sites

You can use the first... It was more of an example of the layout of a UDF (User Defined Function). These functions can be used by anyone running on autoit, and be useful to them, See what I mean?

MDiesel

The helpfile (as always) has an entire section devoted to functions! check here for an online version

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

  • Recently Browsing   0 members

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