PcExpert Posted May 29, 2007 Posted May 29, 2007 Hi all, I get an ERROR when trying to run a script: Line 122 (File "G:\PROGRAMMING\Chat\Working\3.4\service_old1.au3"): Func SocketToIP($SHOCKET) Error: "If" statement has no matching "EndIf" statement. The Code: expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> $read4 = IniRead("settings.ini", "General", "showmsg", "") $read1 = IniRead("settings.ini", "General", "sound", "") If $read1 = "JA" Then $playsound = SoundPlay(@WindowsDir & "\media\notify.wav",0) Else $playsound = ";" $read2 = IniRead("settings.ini", "General", "icon", "") If $read2 = "JA" Then $flashicon = "TraySetState(5)" Else $flashicon = ";" $read3 = IniRead("settings.ini", "General", "msg", "") If $read3 = "traytip" Then $msgmethod = "TrayTip("Bericht van " & $szIP_Accepted, $recv, $read4, 1)" Else $msgmethod = "MsgBox(64, "Bericht van " & $szIP_Accepted, $recv, $read4)" EndIf ; Set Some reusable info ; Set your Public IP address (@IPAddress1) here. Dim $szIPADDRESS = @IPAddress1 Dim $nPORT = 33891 ; Start The TCP Services ;============================================== TCPStartUp() ; Create a Listening "SOCKET". ; Using your IP Address and Port 33891. ;============================================== $MainSocket = TCPListen($szIPADDRESS, $nPORT) ; If the Socket creation fails, exit. If $MainSocket = -1 Then Exit ; Create a GUI for messages ;============================================== ;Dim $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")",300,200) ;Dim $edit = GUICtrlCreateEdit("",10,10,280,180) ;GUISetState() ; Initialize a variable to represent a connection ;============================================== Dim $ConnectedSocket = -1 ;Wait for and Accept a connection ;============================================== Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 ; Get IP of client connecting Dim $szIP_Accepted = SocketToIP($ConnectedSocket) Dim $msg, $recv ; GUI Message Loop ;============================================== While 1 ; $msg = GUIGetMsg() ; GUI Closed ;-------------------- ; If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; Try to receive (up to) 2048 bytes ;---------------------------------------------------------------- $recv = TCPRecv( $ConnectedSocket, 2048 ) ; If the receive failed with @error then the socket has disconnected ;---------------------------------------------------------------- If @error Then ExitLoop ; Update the edit control with what we have received ;---------------------------------------------------------------- Select Case $recv = "ENDING_BYE" TCPCloseSocket($ConnectedSocket) TCPCloseSocket($MainSocket) Listen() Case $recv = "#shutdown" shutdown(1) Case $recv = "#reboot" shutdown(2) Case $recv = "#blocky" BlockInput(1) Case $recv = "#blockn" BlockInput(0) Case $recv <> "" $flashicon = TraySetState(5) If $szIP_Accepted = "192.168.0.102" Then $szIP_Accepted = "HP" ElseIf $szIP_Accepted = "192.168.0.101" Then $szIP_Accepted = "AOPEN" ElseIf $szIP_Accepted = "192.168.0.100" Then $szIP_Accepted = "SERVER" ElseIf $szIP_Accepted = "192.168.0.103" Then $szIP_Accepted = "ACER" EndIf $playsound = SoundPlay(@WindowsDir & "\media\notify.wav",0) $msgmethod = TrayTip("Bericht van " & $szIP_Accepted, $recv, "", 1) Sleep(7000) TraySetState(10) EndSelect WEnd If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket ) TCPShutDown() ; Function to return IP Address from a connected socket. ;---------------------------------------------------------------------- Func SocketToIP($SHOCKET) Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]") Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _ "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc Func Listen() ; Create a Listening "SOCKET". ; Using your IP Address and Port 33891. ;============================================== $MainSocket = TCPListen($szIPADDRESS, $nPORT) ; If the Socket creation fails, exit. If $MainSocket = -1 Then Exit ;Wait for and Accept a connection ;============================================== Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 ; Get IP of client connecting Dim $szIP_Accepted = SocketToIP($ConnectedSocket) EndFunc At line 127 is the If statement and at line 132 is the endif statement. I even tried two endif's (because there's a if statement at line 127 and 129) but that didn't work either. What can solve the problem? Thanks!
tannerli Posted May 29, 2007 Posted May 29, 2007 What about trying to make multiline-If's? couldn't test it but I think that will do: If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] EndIf Else $aRet = 0 EndIf greetings tannerli
smashly Posted May 29, 2007 Posted May 29, 2007 (edited) Change If Not @error Then $aRet = $aRet[0]oÝ÷ Ù:ºÚ"µÍYÝÜ[ ÌÍØT]H ÌÍØT]ÌB[Y But I still think you other syntax errors on line 16 and on line 18 as well. Cheers Edited May 29, 2007 by smashly
Developers Jos Posted May 29, 2007 Developers Posted May 29, 2007 (edited) RUn your script through Tidy and see if you understand then ... Edited May 29, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 (edited) Same ERROR By the way, Why isn't my res hack working. It worked, but now I reinstalled my PC and I didn't know where I had put it. AU3WRAPPER says running res hack. But I don't see the GUI from res hack to change details. I ran Tidy, but still the same ERROR Edited May 29, 2007 by PcExpert
Developers Jos Posted May 29, 2007 Developers Posted May 29, 2007 Same ERRORBy the way, Why isn't my res hack working. It worked, but now I reinstalled my PC and I didn't know where I had put it. AU3WRAPPER says running res hack. But I don't see the GUI from res hack to change details.What is it telling you in the SciTE ouput pane ? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 (edited) When I select compile with AU3WRAPPER then normally the res hack GUI would show up, but it didn't. I did it by right clicking on the au3 file and then select compile with au3wrapper. Edited May 29, 2007 by PcExpert
tannerli Posted May 29, 2007 Posted May 29, 2007 (edited) #NoTrayIcon #include <GUIConstants.au3> $read4 = IniRead("settings.ini", "General", "showmsg", "") $read1 = IniRead("settings.ini", "General", "sound", "") If $read1 = "JA" Then $playsound = SoundPlay(@WindowsDir & "\media\notify.wav",0) Else $playsound = ";" $read2 = IniRead("settings.ini", "General", "icon", "") EndIf If $read2 = "JA" Then $flashicon = "TraySetState(5)" Else $flashicon = ";" $read3 = IniRead("settings.ini", "General", "msg", "") EndIf ;<== this one missed If $read3 = "traytip" Then $msgmethod = "TrayTip("Bericht van " & $szIP_Accepted, $recv, $read4, 1)" Else $msgmethod = "MsgBox(64, "Bericht van " & $szIP_Accepted, $recv, $read4)" EndIf ; Set Some reusable info ; Set your Public IP address (@IPAddress1) here. Dim $szIPADDRESS = @IPAddress1 Dim $nPORT = 33891 you missed another EndIf there, maybe you should work with using tabulators to get a structure in your code which editor do you use? if it's notepad i would reccommend you to switch to SciTe (http://www.autoitscipt.com - somewhere in downloads section) greetings tannerli Edited May 29, 2007 by tannerli
Developers Jos Posted May 29, 2007 Developers Posted May 29, 2007 (edited) When I select compile with AU3WRAPPER then normally the res hack GUI would show up, but it didn't.Have you read the Update History?5/22/2007*** Updated AutoIt3Wrapper v1.9.0.0 (JdeB) - *** Removed GUI to set compiler options. ****. This is replaced by the #AutoIt3Wrapper_ directives in the source itself. Existing scriptname.au3.ini settings are still used as defaults which will be overridden by the Directives when specified. - Renamed the Explorer Right-Mouse-Click option from "Compile with Options" to "Compile with AutoIt3Wrapper" - Renamed ALL Directives from #Compiler_???? to #AutoIt3Wrapper_???? and also updated them in SciTE. The Old Directive names are supported for backwards compatibility. - Changed the Reshacker step. It will now update the output EXE generated by AUT2EXE. - Added an UPX step when UPX is requested. UPX is always switched off for AUT2EXE to allow ResHacker to update the resources. - Added check for UTF16 (Unicode) encoded files whioch will show the following warning: ! *************************************************************************************************** ! * Input file is UTF16 encoded, Au3Check/Tidy/Obfuscator do no support UNICODE and will be skipped.* ! ***************************************************************************************************EDIT: there is a test version available that will convert the INI file to Directives for you: http://www.autoitscript.com/forum/index.ph...st&p=348831 Edited May 29, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 Scite comes with autoit, so I'm using scite. But the scite version I use was downloaded from the AutoIT download page.
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 still get the same error, but now on line 123
Developers Jos Posted May 29, 2007 Developers Posted May 29, 2007 Scite comes with autoit, so I'm using scite. But the scite version I use was downloaded from the AutoIT download page.Point being ?The SciTE that comes with AutoIt3 doesnot have AutoIt3Wrapper, you will have to download the full SciTE4AutoIt3 installer and ResHacker to make that work. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 @JdeB Could you please explain me how the #compiler function work? Its not documented in the autoit helpfile.
tannerli Posted May 29, 2007 Posted May 29, 2007 i changed something other on line 18: If $read3 = "traytip" Then $msgmethod = "TrayTip(""Bericht van "" & $szIP_Accepted, $recv, $read4, 1)" ;<== doubled quotes Else $msgmethod = "MsgBox(64, ""Bericht van "" & $szIP_Accepted, $recv, $read4)" ;<== doubled quotes EndIf Now if i run the Syntax-Check (Ctrl+F5) i get no more errors
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 at line 124 it now misses an endif statement according to AU3check
Developers Jos Posted May 29, 2007 Developers Posted May 29, 2007 (edited) @JdeBCould you please explain me how the #compiler function work? Its not documented in the autoit helpfile.Open the SCiTE4AutoIt3 helpfile and look for AutoIt3Wrappper to get it explained.at line 124 it now misses an endif statement according to AU3checkAs posted before ... run Tidy on your script to see where you forgot the EndIF(s) Edited May 29, 2007 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
tannerli Posted May 29, 2007 Posted May 29, 2007 im not really sure why you can't make single-line if's on your code... it's strange, mine always work perfectly but however i changend this one If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket ) oÝ÷ Ú)í¡«¢+Ø)%ÀÌØí ½¹¹ÑM½Ð±ÐìÐì´ÄQ¡¸(%Q A ±½ÍM½Ð ÀÌØí ½¹¹ÑM½Ð¤)¹%(
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 (edited) @tannerli Could you please show me your code? I thought you had the code without errors. My code has an error now at line 127. ERROR If statement with no matching endif statement. Thanks JdeB Edited May 29, 2007 by PcExpert
tannerli Posted May 29, 2007 Posted May 29, 2007 here it is: expandcollapse popup#NoTrayIcon #include <GUIConstants.au3> $read4 = IniRead("settings.ini", "General", "showmsg", "") $read1 = IniRead("settings.ini", "General", "sound", "") If $read1 = "JA" Then $playsound = SoundPlay(@WindowsDir & "\media\notify.wav",0) Else $playsound = ";" $read2 = IniRead("settings.ini", "General", "icon", "") EndIf If $read2 = "JA" Then $flashicon = "TraySetState(5)" Else $flashicon = ";" $read3 = IniRead("settings.ini", "General", "msg", "") EndIf ;<== this one missed If $read3 = "traytip" Then $msgmethod = "TrayTip(""Bericht van "" & $szIP_Accepted, $recv, $read4, 1)" ;<== doubled quotes Else $msgmethod = "MsgBox(64, ""Bericht van "" & $szIP_Accepted, $recv, $read4)" ;<== doubled quotes EndIf ; Set Some reusable info ; Set your Public IP address (@IPAddress1) here. Dim $szIPADDRESS = @IPAddress1 Dim $nPORT = 33891 ; Start The TCP Services ;============================================== TCPStartUp() ; Create a Listening "SOCKET". ; Using your IP Address and Port 33891. ;============================================== $MainSocket = TCPListen($szIPADDRESS, $nPORT) ; If the Socket creation fails, exit. If $MainSocket = -1 Then Exit ; Create a GUI for messages ;============================================== ;Dim $GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")",300,200) ;Dim $edit = GUICtrlCreateEdit("",10,10,280,180) ;GUISetState() ; Initialize a variable to represent a connection ;============================================== Dim $ConnectedSocket = -1 ;Wait for and Accept a connection ;============================================== Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 ; Get IP of client connecting Dim $szIP_Accepted = SocketToIP($ConnectedSocket) Dim $msg, $recv ; GUI Message Loop ;============================================== While 1 ; $msg = GUIGetMsg() ; GUI Closed ;-------------------- ; If $msg = $GUI_EVENT_CLOSE Then ExitLoop ; Try to receive (up to) 2048 bytes ;---------------------------------------------------------------- $recv = TCPRecv( $ConnectedSocket, 2048 ) ; If the receive failed with @error then the socket has disconnected ;---------------------------------------------------------------- If @error Then ExitLoop ; Update the edit control with what we have received ;---------------------------------------------------------------- Select Case $recv = "ENDING_BYE" TCPCloseSocket($ConnectedSocket) TCPCloseSocket($MainSocket) Listen() Case $recv = "#shutdown" shutdown(1) Case $recv = "#reboot" shutdown(2) Case $recv = "#blocky" BlockInput(1) Case $recv = "#blockn" BlockInput(0) Case $recv <> "" $flashicon = TraySetState(5) If $szIP_Accepted = "192.168.0.102" Then $szIP_Accepted = "HP" ElseIf $szIP_Accepted = "192.168.0.101" Then $szIP_Accepted = "AOPEN" ElseIf $szIP_Accepted = "192.168.0.100" Then $szIP_Accepted = "SERVER" ElseIf $szIP_Accepted = "192.168.0.103" Then $szIP_Accepted = "ACER" EndIf $playsound = SoundPlay(@WindowsDir & "\media\notify.wav",0) $msgmethod = TrayTip("Bericht van " & $szIP_Accepted, $recv, "", 1) Sleep(7000) TraySetState(10) EndSelect WEnd If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket ) EndIf TCPShutDown() ; Function to return IP Address from a connected socket. ;---------------------------------------------------------------------- Func SocketToIP($SHOCKET) Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]") Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _ "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] EndIf Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc Func Listen() ; Create a Listening "SOCKET". ; Using your IP Address and Port 33891. ;============================================== $MainSocket = TCPListen($szIPADDRESS, $nPORT) ; If the Socket creation fails, exit. If $MainSocket = -1 Then Exit ;Wait for and Accept a connection ;============================================== Do $ConnectedSocket = TCPAccept($MainSocket) Until $ConnectedSocket <> -1 ; Get IP of client connecting Dim $szIP_Accepted = SocketToIP($ConnectedSocket) EndFunc
PcExpert Posted May 29, 2007 Author Posted May 29, 2007 I think that we are getting closer. Now there's an error at line 31. ERROR Variable used without being declared
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now