Jump to content

function example needed


Recommended Posts

was hoping for a link to an example where that kind of situation could exist..

<{POST_SNAPBACK}>

what about this?

dim $params[5]

$params[0] = 4
$params[1] = "Joe"
$params[2] = 4
$params[3] = 3.1415
$params[4] = true

mycode($params)

func mycode(byref $paramarray)
   local $n

   for $n=1 to $paramarray[0]
       msgbox(0,"INFO", "Param #" & $n & ": " & $paramarray[$n])
   next

endfunc

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

In case you use _ArrayAdd in your script and N is always unknown cos it changes as the program runs then instead of using this"

For $n=1 To $paramarray[0]

use this

For #n=1 to UBound($paramarray) -1

So that you dont care about how many really the parameters are....

Link to comment
Share on other sites

and don't need the byref unless you plan on being able to change the array in the function.

<{POST_SNAPBACK}>

I used the byref, because it's faster.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

In case you use _ArrayAdd in your script and N is always unknown cos it changes as the program runs then instead of using this"

For $n=1 To $paramarray[0]

use this

For #n=1 to UBound($paramarray) -1

So that you dont care about how many really the parameters are....

<{POST_SNAPBACK}>

If you set $paramarray[0] to contain the size of the array, then Ubound() is not necessary.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

I'm not sure he was talking about an array guys. It looked more like he was asking about a function that would need an indefinite amount of parameters, which is not possible in the case of AutoIt.

One such example for code like this could be the following (Note, this will NOT work):

Func _ArrayCreate()
  Local $i
  If @NumParams > 0 Then
    Local $av_Array[@NumParams]
    For $i = 0 to @NumParams
      $av_Array[$i] = FuncGetParam($i); <-- this is a made up function. here it would get the function's parameters based on their index
    Next
    Return $av_Array
  Else
    Return 0
  EndIf
EndFunc

$a_Fruits = _ArrayCreate('apple', 'orange', 'banana', 'peach')
Link to comment
Share on other sites

I'm not sure he was talking about an array guys. It looked more like he was asking about a function that would need an indefinite amount of parameters, which is not possible in the case of AutoIt.

One such example for code like this could be the following (Note, this will NOT work):

Func _ArrayCreate()
  Local $i
  If @NumParams > 0 Then
    Local $av_Array[@NumParams]
    For $i = 0 to @NumParams
      $av_Array[$i] = FuncGetParam($i); <-- this is a made up function. here it would get the function's parameters based on their index
    Next
    Return $av_Array
  Else
    Return 0
  EndIf
EndFunc

$a_Fruits = _ArrayCreate('apple', 'orange', 'banana', 'peach')

<{POST_SNAPBACK}>

I knew what he meant, I't can be done in vb, and like you said, currently not in AutoIt, therefore I suggested an array

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If you set $paramarray[0]to contain the size of the array, then Ubound() is not necessary.

Cheers

Kurt

This is valid if you set the values manualy.But if you use a growing array with _ArrayAdd for instance,then if you save the [0] element for the dimension of the array then everytime he runs _arrayadd he should run in the next line $params[0]=UBound($params) -1 to update the [0] element... So again UBound is needed....It's just one of the ways you can do this...
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...