AutoHotkey Community

It is currently May 24th, 2012, 6:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: January 21st, 2007, 5:32 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi,

I'm trying to use the Internet Connection Test (http://www.autohotkey.com/forum/viewtopic.php?p=60892#60892). It works fine as long as I use just one function, but when I put in a second function and try to reload, I get the "Functions cannot contain functions" error. I've checked for missing braces (http://www.autohotkey.com/forum/topic8939.html), but they seem to be there. Here is the script:
Code:
^!.::
{
loopcount:=4
delay:=4000
URL := "http://www.yahoo.com"

loop, %loopcount%
   {
      FormatTime, nowtime, , h:mm:ss tt
      If ConnectedToInternet()
         status:="Online"
      else
         status:="Offline"
      FileAppend, CTI`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt

      If InternetCheckConnection(URL)
         status:="Online"
      else
         status:="Offline"
      FileAppend, ICC`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
      sleep, %delay%
   }
   
  ConnectedToInternet(flag=0x40) {
  Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
  }
 
  InternetCheckConnection(Url="",FIFC=1) {
  Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
  }
Return    
}


What am I doing wrong?

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2007, 5:37 pm 
Offline

Joined: December 11th, 2006, 4:11 pm
Posts: 242
Location: Orlando, FL
I edited your script just a bit:
Code:
^!.::
loopcount:=4
delay:=4000
URL := "http://www.yahoo.com"

loop, %loopcount%
   {
      FormatTime, nowtime, , h:mm:ss tt
      If ConnectedToInternet()
         status:="Online"
      else
         status:="Offline"
      FileAppend, CTI`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt

      If InternetCheckConnection(URL)
         status:="Online"
      else
         status:="Offline"
      FileAppend, ICC`t%A_MM%/%A_DD%/%A_YYYY%`t%nowtime%`t%status% `n, c:\temp\Internet.txt
      sleep, %delay%
   }
RETURN
   
  ConnectedToInternet(flag=0x40) {
  Return DllCall("Wininet.dll\InternetGetConnectedState", "Str", flag,"Int",0)
  }
 
  InternetCheckConnection(Url="",FIFC=1) {
  Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
  }

I just removed the outer brackets and moved the return up to the appropriate position. It does not give me the error code anymore.


Hope this helps :)

Note: Woot! 100th post :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2007, 6:20 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Helps!

I see - functions seem to be global to the script, and can't be restricted in a hotkey block.

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 13th, 2007, 7:38 pm 
I get the same type of error as John B. when reloading the script, but when removing the brackets as Jaytech suggested, then the scripts re-loads fine, but it does not loop, it just runs once and thats it.. How can I solve this?

Thanks,

Code:
!c::

Loop, 2
{
Random, rand1, 10000, 99999   
Random, rand2, 1000, 9999   
Random, rand3, 1, 9      
Random, rand4, 1900, 2100   
Random, rand5, 10, 59      
Random, rand6, 10, 28      
Random, rand7, 10, 18      

var1=1
Add1(x,y)
{
 return x + y
}
var5 := Add1(var1,rand5)

var2=1
Add2(x,y)
{
 return x + y
}
var7 :=Add2(var2,rand7)

Send BEGIN:VCALENDAR`n
Send VERSION:1.0`n
Send BEGIN:VEVENT`n

Send UID:57a%rand1%-18fd-%rand2%-835b-bdbfecdc0e0c`n

Send SUMMARY:Quantum Physics Of Nature`n
Send DESCRIPTION:NATO ADVANCED STUDY INSTITUTE CARBON NANOTUBES: FROM`n
Send   BASIC RESEARCH TO NANOTECHNOLOGY`n

Send DTSTART:%rand4%0%rand3%%rand6%T%rand7%%rand5%00Z`n

Send DTEND:%rand4%0%rand3%%rand6%T%var7%%var5%00Z`n

Send X-EPOCAGENDAENTRYTYPE:APPOINTMENT`n
Send CLASS:PUBLIC`n
Send LOCATION:Tejas 106A`n
Send SEQUENCE:0`n
Send X-METHOD:NONE`n
Send LAST-MODIFIED:20060612T125310Z`n
Send PRIORITY:0`n
Send STATUS:CONFIRMED`n
Send X-SYMBIAN-LUID:2`n
Send END:VEVENT`n
Send END:VCALENDAR`n
}
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2007, 10:24 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Why the functions?
Quote:
Add1(x,y)
{
return x + y
}
var5 := Add1(var1,rand5)


What's the benefit over:
Code:
var5 := var1 + rand5

If you really need the function one declaration should be enough and it can be placed before or after the loop.

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 1:00 pm 
Thanks a bunch Tonne :D ! The reason why is close aligned with my programming skills, which are not far from zero. That was the solution I found when I tried, use one random number and then add 1 into another stored value. I guess there is minit to get hooked on AHK and a lifetime to master....


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, engunneer, Google Feedfetcher, rbrtryn, Xx7, Yahoo [Bot] and 74 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