AutoHotkey Community

It is currently May 26th, 2012, 1:15 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: November 21st, 2008, 11:31 pm 
Offline

Joined: July 30th, 2004, 11:30 pm
Posts: 74
Location: Deutschland (sorry for my english)
Hi all
i am asking for your help:

i have an file with an few scripts in it:

Code:
IF 1 = abc Gosub abc
IF 1 = def Gosub def
IF 1 = xyz Gosub xyz


abc:
;doit
def:
;doit
xyz:
;doit



Here i got an problem if i call this script with 'def'
and the code by 'abc' is something wrong or miss an var or like this...
then i got an error message for an block of code i didn't want
to use in that moment... because i need code 'def' right yet,
Code 'abc' will work in an other situation.


Now my question:
how can i set this code blocks separately in one single ahk-file?
So if i call one block while an other block is not valid right now
i don't want to get an error message for this non-valid block.


Any hints please?

_________________
Image Stefan

This post was created with the kindly help of http://dict.leo.org/ and remember: “Allways look on the bright side of Life”


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2008, 11:54 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Try How to: Run Dynamic Script... Through a Pipe!

You could have several scripts each stored a separate variable and run them as you like.

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Last edited by HotKeyIt on November 22nd, 2008, 3:37 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2008, 12:56 am 
Offline

Joined: July 30th, 2004, 11:30 pm
Posts: 74
Location: Deutschland (sorry for my english)
Thank you

i found the thread you mention under this URL:
http://www.autohotkey.com/forum/viewtopic.php?t=25867

but i don't see how this could help me.

_________________
Image Stefan

This post was created with the kindly help of http://dict.leo.org/ and remember: “Allways look on the bright side of Life”


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2008, 4:04 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
In this case please explain your problem.

With dynamic scripting you can run several scripts from one file, each can be executed separately or even together.
E.g.:
Code:
Script1 =
(
   a = FIRST
   MsgBox This is the `%a`% Script
   
)
Script2 =
(
   MsgBox This is the SECOND Script``nContent of a = `%a`%
   
)
SetTimer, ChangeButtons, -50
MsgBox, 262147, Select script, Witch script would you like to run?
IfMsgBox Yes
{
   #__RUN_TEMP_SCRIPT(script1, "Your first script")
}
else IfMsgBox No
{
   #__RUN_TEMP_SCRIPT(script2, "Your second script")
}
else IfMsgBox Cancel
{
   #__RUN_TEMP_SCRIPT(script1 . script2, "Both Scripts in one")
}
ExitApp

ChangeButtons:
WinWait, Select script AHK_class #32770
ControlSetText, Button1, Script1, Select script AHK_class #32770
ControlSetText, Button2, Script2, Select script AHK_class #32770
ControlSetText, Button3, Run Both, Select script AHK_class #32770
WinActivate, Select script AHK_class #32770
Return

#__RUN_TEMP_SCRIPT(script, scriptname="")
{
   If scriptname =
      #__PIPE_NAME_ := A_TickCount
   else
      #__PIPE_NAME_ := scriptname
   #__PIPE_GA_ := CreateNamedPipe(#__PIPE_NAME_, 2)
   #__PIPE_    := CreateNamedPipe(#__PIPE_NAME_, 2)
   if (#__PIPE_=-1 or #__PIPE_GA_=-1) {
      MsgBox CreateNamedPipe failed.
      Return
   }
   Run, %A_AhkPath% "\\.\pipe\%#__PIPE_NAME_%"
   DllCall("ConnectNamedPipe","uint",#__PIPE_GA_,"uint",0)
   DllCall("CloseHandle","uint",#__PIPE_GA_)
   DllCall("ConnectNamedPipe","uint",#__PIPE_,"uint",0)
   script := chr(239) . chr(187) . chr(191) . script
   if !DllCall("WriteFile","uint",#__PIPE_,"str",script,"uint",StrLen(script)+1,"uint*",0,"uint",0)
      MsgBox WriteFile failed: %ErrorLevel%/%A_LastError%
   DllCall("CloseHandle","uint",#__PIPE_)
   Return #__PIPE_NAME_
}
CreateNamedPipe(Name, OpenMode=3, PipeMode=0, MaxInstances=255) {
   return DllCall("CreateNamedPipe","str","\\.\pipe\" Name,"uint",OpenMode
      ,"uint",PipeMode,"uint",MaxInstances,"uint",0,"uint",0,"uint",0,"uint",0)
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Amandaville, Cerberus, Exabot [Bot], patgenn123, poserpro and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group