Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Function calls


  • Please log in to reply
7 replies to this topic
Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
gui, add, text,,String
gui, add, edit, vInputString
gui, add, text,,Length
gui, add, edit, vInputLength
gui, add, button, gOk,OK
gui, add, edit, w200 r30 vMyEdit

gui, show,, The world will end tomorrow
return

So a user enters data into two edit controls, and the data is saved as InputString and InputLength. Can you use these as parameters for a function to take?

Ok:
{
   MyFunction("InputString","InputLength")
   GuiControl,,MyEdit, % output
   return
}
MyFunction(Parameter1, Parameter2)
{
   Does Stuff
   Does Stuff
   return output
}


Morpheus
  • Members
  • 475 posts
  • Last active: Today, 10:33 AM
  • Joined: 31 Jul 2008
I think that it would need to look like this:
Ok:
   output := MyFunction(InputString,InputLength)
   GuiControl,,MyEdit, % output
return
Functions expect variables, so quoted text is seen as a string. You also do not need brackets for a subroutine. You may also be able to combine a few lines and make it look like this:
Ok:
   GuiControl,,MyEdit, % MyFunction(InputString,InputLength)
return
I say 'may', because I did not test it.

Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
Thanks! I'll give both a shot.

Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
No, I'm still doing something wrong. Here's the whole code. I'm using the function that Gogo wrote in this thread: <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?f=1&t=74319">viewtopic.php?f=1&t=74319</a><!-- l --> I thought that MsgBox was a poor way to display the results since they could be quite long...and you could only change the input string by editing the script. So I tried to revise it with this:

gui, add, text,,String
gui, add, edit, vInputString
gui, add, text,,Length
gui, add, edit, vInputLength
gui, add, button, gOk,OK
gui, add, edit, w200 r30 vMyEdit

gui, show,, Hello World
return

Ok:
GuiControl,,MyEdit, % C(InputString,InputLength)
return


C(s,l,c="") {
   If l = 0 ; StrLen(s) = l
      return c . "`n"
   Loop % StrLen(s) - l + 1
      out.= C( SubStr(s, A_Index + 1), l - 1, c . SubStr(s, A_Index, 1))
   return out
}

return
GuiClose:
ExitApp

...which doesn't work.

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011

Can you use these as parameters for a function to take?

This is a very good question.
I was curious to see if the function could take both variables simultaneously.
gui add, edit, vInputString
gui add, edit, vInputLength
gui, add, button, gOk,OK
gui show
return

Ok:
GuiControlGet, str,, InputString
GuiControlGet, len,, InputLength
MyFunction( str, len )
return

MyFunction( par1, par2 ) {
  MsgBox % par1 " " par2
}
less redundant
gui add, edit, vInputString
gui add, edit, vInputLength
gui, add, button, gOk,OK
gui show
return

Ok:
Gui, Submit, NoHide
MyFunction( InputString, InputLength )
return

MyFunction( par1, par2 ) {
  MsgBox % par1 " " par2
}


0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011

No, I'm still doing something wrong.

See GUI submit above ;)
btw is this showing all possible combinations in a given length? hrrrmmm

anyway try this:
gui, add, text,,String
gui, add, edit, vInputString
gui, add, text,,Length
gui, add, edit, vInputLength
gui, add, button, gOk,OK
gui, add, edit, w200 r30 vMyEdit

gui, show,, Hello World
return

Ok:
[color=#BF0000]Gui, Submit, NoHide
GuiControl,, MyEdit, % C(InputString,InputLength)[/color]
return


C(s,l,c="") {
   If l = 0 ; StrLen(s) = l
      return c . "`n"
   Loop % StrLen(s) - l + 1
      out.= C( SubStr(s, A_Index + 1), l - 1, c . SubStr(s, A_Index, 1))
   return out
}

return
GuiClose:
ExitApp
This works

Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
Yes. Now go play Text Twist. :lol:

No, not really. I'm not doing this for Text Twist. This is the first step in what I want to eventually produce. The next step would be to take the last 35 strings produced by Gogo's function ( with C("12345678",4) ), invert the list, and match them up with the 1st 35, concatenated with "vs." So that it might look like

1234 vs 5678
1235 vs 4678
...and so on.

Tilter_of_Windmills
  • Members
  • 323 posts
  • Last active: Apr 08 2012 01:26 PM
  • Joined: 23 Mar 2012
I forgot to say "Thank you!"