Sign in to follow this  
Followers 0
GodForsakenSoul

ok, this make SOME sense...

6 posts in this topic

#1 ·  Posted (edited)

i'm having small trouble understanding this particular line of the TCP server made by sloppyprogrammer (or... something like that).

If $pack <> "" Then _payload($pack) ;  open them and check if they are empty. If they are NOT empty, run the payload function.

for me it looks like if $pack IS empty, then do _payload. where is the NOT part?

^UNDERSTOOD^

vANSWER THIS NOW PLEASEv

also, instead of making two topics, i couldn't find an explanation in the help file about the variable in the ().

couldn't anyone explain this?

edit: perhaps i'll understand better with some code included.

Edited by GodForsakenSoul

Share this post


Link to post
Share on other sites



If $pack <> ""

if $pack is not equal to "", that is, if its not empty then...

Share this post


Link to post
Share on other sites

You are saying..

If $pack is 'different' than "" then... do this

You can use If statements anywhere

If Not $Pack = "10" then... do something

It will not do anything if $pack = "10" otherwise, it will do something

Hope that helps

See If, Then, Else in help

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

GodForsakenSoul,

The statement 'If $pack <> "" ' Then translates as 'If $pack is not equal to an empty string'. So if $pack is not an empty string, the _payload function is run.

The variable $pack in parentheses behind the _payload function is a parameter being passed to the function. Look in the Help file under 'AutoIt -> Function Reference -> Function Notes'.

I hope that clears up any misunderstanding.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

om... thank you for the explanation about the <> part. however, i'm having trouble understanding the function notes. i mean literally. english is not my first language, so if they DO provide an explanation, it's too subtle for me to understand.

please try to explain it in your own words. preferably, as if you were explaining this to a complete idiot.

Share this post


Link to post
Share on other sites

GodForsakenSoul,

Here goes:

All the following assumes you are in GUIGetMsg mode.

Firstly, a short excursion to explain the idea of Global/Local variables.

- Any variable that is set (that is given a value: $variable = something) in the main part of the script is automatically a Global variable and available to any other function within the script.

- Any variable that is set in a function is automatically a Local variable and is lost when the function ends.

- This can be overidden by the Global/Local keywords, but ignore that for a moment.

Now we have that squared away, let us discuss variables within functions.

Good programming practise is to code in modules - that is using standard blocks of code which can be easily reused. An example would be the following:

; This is not working code!
Func _Double()
    $Input = $Input * 2
EndFunc

Now as it stands that function is pretty useless as although it doubles $Input, there is no way for it to know what value it is to double! Furthermore, the $Input variable is Local and will be lost when the function ends! We need to tell the function the initial value. We can do this in 2 ways:

1. Make a Global variable $Input which is available to the function.

2. Pass a parameter to the function when we call it.

Option 1 has some disadvantages - not least the need to use the same name for every variable we need to double! Option 2 allows you to use the same function for many different variables - all we have to do is tell the function what to double when we call it - and get the function to return the new value once it has been calculated:

$var1 = 1
$var1 = _Double($var1)
ConsoleWrite($var1 & @CRLF)

$var2 = 10
$var2 = _Double($var2)
ConsoleWrite($var2 & @CRLF)

Func _Double($Input)
    $Input = $Input * 2
    Return $Input
EndFunc

Now the function knows what it has to double and the main code gets the new value returned - and the same function doubled both variables. That is the modular bit - you can reuse the function many times in many scripts without changing it!

There are a couple of other points to remember about parameters.

1. The function can preset a default value for a parameter - this way you can have extended options for the function which you do not have to set if you only require a basic version. An simple example is the _SoundPlay function in the Sound.au3 UDF. If you look in the Help file you will see:

_SoundPlay ( $sSnd_id [, $fWait ] )

Parameters

$sSnd_id Sound ID (the 'alias') as returned by _SoundOpen or a file

$fWait [optional] This flag determines if the script should wait for the sound to finish before continuing:

1 = wait until sound has finished

0 = continue script while sound is playing (default)

If you were to look into the function itself you would see:

Func _SoundPlay($aSndID, $iWait = 0)

The function will automatically set $iWait to 0 unless that code specifically sets another value. The coder does not have to specify a value unless it is other than the default.

2. A parameter can be passed using the keyword ByRef. This means that the function can alter the variable without having to return a value;

$var1 = 1
$var3 = 100
$var1 = _Double($var1, $var3)
ConsoleWrite($var1 & @CRLF & $var3 & @CRLF)

Func _Double($Input_A, $Input_B)
    $Input_A = $Input_A * 2
    $Input_B = 200
    Return $Input_A
EndFunc

$var2 = 10
$var3 = 100
$var2 = _Triple($var2, $var3)
ConsoleWrite($var2 & @CRLF & $var3 & @CRLF)

Func _Triple($Input_A, ByRef $Input_B)
    $Input_A = $Input_A * 3
    $Input_B = 300
    Return $Input_A
EndFunc

Here we can see that in function _Double, $var3 is passed normally (technically known as By Value) and so when it is changed within the function, there is no change in the real variable - the change in value made within the function is lost when the function ends.

However, in function _Triple, $var3 is passed ByRef (short for By Reference) and its real value is altered by the function.

There you have function parameters in a nutshell. Play about with the 2 examples until you are happy with what is going on.

Good luck!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0