AutoHotkey Community

It is currently May 27th, 2012, 12:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: January 7th, 2010, 4:56 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
tank wrote:
return %log% would return whatever value log has as a variable name

Actually(unless you meant something else)...

Known limitation: For backward compatibility and ease-of-use, the following two examples are functionally identical:
Code:
return MyVar
return %MyVar%

Code:
MsgBox % Add(3,5) "`n" AddAlt(4,4)

Add(x,y) {
   res:=x+y
   return res
}
AddAlt(x,y) {
   res:=x+y
   return %res%
}


So while it doesn't have to be enclosed in percent signs, it will work.

Marty -

As tank pointed out, why are you trying to retrieve your known input to the function as output from the function? Look at this:
Code:
MsgBox % updateLog("Start`n")

updateLog(log) {
   global LogHwnd
   ControlSend,,{end},ahk_id %LogHwnd%
   Control,EditPaste,%log%,,ahk_id %LogHwnd%
   ControlSend,,{end},ahk_id %LogHwnd%
   Return log
}


The message box is going to return 'Start`n', the same thing you just passed to the function to begin with. It would've been easier to do this to begin with:
Code:
MsgBox, Start`n


Can you now see why some of us would be scratching our heads at your request?

By the way this:
Code:
Var := updateLog(log)


Is not going to return anything unless you have a variable named log that contains the data to be returned.
Code:
log=this works
Var := updateLog(log)
;Var := updateLog("this works")

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2010, 5:13 pm 
Again thanks to all for helping me get through this :)

sinkfaze - I understand what your saying about
Code:
UpdateLog("Start`n")
etc...

BUT what is confusing me is the updateLog function is updating the debug GUI window.

So when this script is run in full, the data the script generates as it logs in and passes values to the server is shown in the debug window. NOT just
Quote:
Start`n


How the heck to I capture that data to allow me to work with it ?

I know I've not grasped this.. but once I can see it working I think it will make sense :lol:

It my birthday next week.. may be it's time to give up ! :(

Thank you all again.

Marty


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2010, 7:30 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
The dump function saves the logged line in e_txt. You could add all logs up, as:
Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}


An other option is to use ControlGet to get the current value of the log control.

The main issue is, perhaps, that the data from the socket is retrived asynchronically (call back) through the function specied when requesting data:
Code:
WS2_AsyncSelect(socket,"dump")

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2010, 8:42 pm 
Thank you tonne

I added a msg box to the dump function as:
Code:
msgbox % txt

This returned the log data fine.

But how would I make the available out side of the dump function.
I've read back on the previous replies, but it just doesn't want to work !
(I blame on snow blindness :) )

Can some one help and put me out of my misery.
(put you out of my misery :roll: )

Thanks again for all the support.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 9:06 am 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Using this:
Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}

All vars are global, i.e., You can ses e_socket (the last socket logged), e_txt (the last txt logged) and e_alltxt (all the txt logged) from everywhere in your script. Naturally these variables are only with value after the first call to dump.

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 9:50 am 
tonne wrote:
Using this:
Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}

All vars are global, i.e., You can ses e_socket (the last socket logged), e_txt (the last txt logged) and e_alltxt (all the txt logged) from everywhere in your script. Naturally these variables are only with value after the first call to dump.


Thank You Tonne
How do I call those variables ??


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 10:40 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Marty wrote:
How do I call those variables ??
Are you serious? I strongly suggest you start with reading the tutorial. It looks like you want to run before you can walk. :?:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 2:53 pm 
Come on Hugov we all have to learn some time.
Code:
dump(Socket,Txt) {
   Global e_txt
   e_socket := socket, e_txt := txt
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
   Return e_alltxt
}
msgbox % e_alltxt


I appreciate the support, advice and help being offered and I do understand that I've not grasped this bit.

Please help me resolve this.

:(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 3:57 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Why did you alter tonne's code? It was designed to do what you wanted it to do.

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 9:49 pm 
Quote:
Why did you alter tonne's code? It was designed to do what you wanted it to do.


Hi
I was showing what I'd tried. !

I'm still struggling to get e_txt and e_alltxt from this function.
Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}


Reading back through the thread it was suggested to use :
Code:
updateLog(log) { ; log is the variable passed to this function
   global LogHwnd
   ControlSend,,{end},ahk_id %LogHwnd%
   Control,EditPaste,%log%,,ahk_id %LogHwnd%
   ControlSend,,{end},ahk_id %LogHwnd%
   Return, log
}
; msgbox % log ; incorrect if you are trying to display the value returned from the function
msgbox, % updateLog(log) ; this displays the value returned from the function


So I tried to duplicate that in the code from tonne.
But I couldn't get it to work !! ( no surprise :roll: )

Thanks yet again.. If you can help I will be eternally gratefull

Regards Martin


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2010, 9:59 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
How are you struggling to get those variables from this code?

Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}


The variables are global, so you can call the variable directly to retrieve its value without anything else to do with the function:

Code:
dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}

MsgBox % e_socket "`n" e_alltxt

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2010, 10:38 am 
Thanks sinkfaze
I understand that, but it just doesn't seem to work for me !

Here is the code. I get the debug window will all the data, but never a message box with anything in that !

That's why I totally confused with this..
Code:
OnExit, CleanUp
Server := "route-server.ip.att.net:23"
log := ""

;~ Debugwindow
Gui,Add,Edit,ReadOnly w800 h400 hwndLogHwnd
Gui,Show,,debug

UpdateLog("Start`n")

   Gosub, Ws2_Init

   res := expect(socket,"Username:")
   
   if (res>0) {
      send(socket,"rviews")
   } else if (res<0) {
      MsgBox Abortet by force
      ExitApp
   } else {
      MsgBox Fail!
      ExitApp
   }

   res := expect(socket,"route-server>")
   if (res>0) {
      send(socket,"ping 4.2.2.2")
   } else if (res<0) {
      MsgBox Abortet by force
      ExitApp
   } else {
      MsgBox Fail!
      ExitApp
   }


   
; Skipped, since this will do when GUI is removed :)
;~ Gosub, WS2_CleanUp
return

; Abort with escape
esc::
   e_timeout := -1
return

GuiClose:
CleanUp:
   Gosub, WS2_CleanUp
   ExitApp

WS2_CleanUp:
   WS2_CleanUp()
return

ws2_init:
   socket := WS2_Connect(Server)
   
   if ((socket<=0) || (StrLen(__WSA_ErrMsg)) || (StrLen(socket)=0)) {
      MsgBox,16,%A_ScriptName%: Sock-Error,% __WSA_ErrMsg
      Gosub, WS2_CleanUp
   }
   
   res    := WS2_AsyncSelect(socket,"dump")
   if ((Res!=0) || (StrLen(__WSA_ErrMsg))) {
      MsgBox,16,%A_ScriptName%: Async-Select-Error,% __WSA_ErrMsg
      Gosub, WS2_CleanUp
   }
Return

expect(socket,txt,timeout=5000) { ; default timeout 5000 msecs / 0 infinite wait
   global e_socket, e_txt,   e_timeout := 0
   n := 0
   Loop,
      if ((e_socket=socket) && (RegExMatch(e_txt,txt)) && (n*100<=timeout)) {
         e_socket := e_txt := ""
         return, 1
      } else if (n*100>timeout) {
         return, 0
      } else {
         if (timeout)
            n++
         sleep, 100
         if (e_timeout=-1) {
            break
         }
      }
   return -1
}

send(socket,senddata,commit="`r`n") {
   if ((StrLen(SendData)>0) && (socket!=0))
      WS2_SendData(Socket,SendData Commit)
}

dump(Socket,Txt) {
   Global
   e_socket := socket, e_txt := txt
   e_alltxt .= txt . "`n" ; append txt and newline
   ;UpdateLog("<<< (" socket ") " txt)
   UpdateLog(txt)
}

MsgBox % e_socket "`n" e_alltxt


updateLog(log) {
   global LogHwnd
   ControlSend,,{end},ahk_id %LogHwnd%
   Control,EditPaste,%log%,,ahk_id %LogHwnd%
   ControlSend,,{end},ahk_id %LogHwnd%
}


; Get it from here:
; http://www.autohotkey.com/forum/viewtopic.php?t=35575
#include WinSock2.ahk


I've just run this code as is, and the 'debug' window is fine lots of data passing by.. But I expected to get a message box with that data in it and nothing happened..

Thanks again for your continued help..:)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2010, 10:52 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Not the scripts fault but user error, the MsgBox is in the wrong location, it never executes move it just above the
Code:
; Skipped, since this will do when GUI is removed :)
line e.g. above the return and it should work by the looks of it.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2010, 1:59 pm 
Thanks for everyone's patience, help and support.

This is now working :D


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 29 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], chaosad, jrav, Yahoo [Bot] 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