[Gambas-user] Syntax error confusion
Gerry Armstrong
gerrya at ...67...
Fri May 4 04:47:28 CEST 2007
Guys,I am new to Gambas but have been impressed with its ease of use... although it has frustrated me due to my lack of knowledge of the language itself. I am having a problem with appending data to a file, I adjusted an example program to suite my needs but for some reason I am getting a syntax error in the line near the end of the code "hFile = OPEN "/home/gerry/smdr.txt" FOR WRITE APPEND" and I can't understand why. Please see the full code below. The object here is simply to append the data captured from the stream to a text file as well as to display it on the screen. Any advise as to why i get this error or even a better way of doing this is welcome!PRIVATE CurProtocol AS IntegerPUBLIC SUB Form_Open() CurProtocol=0ENDPUBLIC SUB MySock_Ready() '*********************************** ' When connection process has finished ' successfully, "Connected" event will raise '*********************************** Timer1.Enabled=FALSE Label3.Text="Connected to remote host " & MySock.Path Label3.Text=Label3.Text & " - Using local address : " & MySock.LocalHost & ":" & MySock.LocalPort ME.Enabled=TRUE Set_Interface(TRUE)ENDPUBLIC SUB MySock_Closed() '******************************************** ' this event will raise when foreing host ' closes the socket by any reason '******************************************** Label3.Caption="Connection Closed by forieng host." ME.Enabled=TRUE Set_Interface (FALSE) ENDPUBLIC SUB MySock_Found() '******************************************** ' this event will raise when forieng host ' name has been translated to IP '******************************************** Label3.Caption="Host Found. Connecting..." ENDPUBLIC SUB MySock_Read() '**************************************** ' When some data arrives from the remote ' part of the socket, "DataAvailable" event ' is raised '**************************************** DIM S AS String IF MySock.Status=Net.Connected THEN READ #MySock,S,Lof(MySock) TextArea1.Text=TextArea1.Text & S Save_Data(S) END IF ENDPUBLIC SUB MySock_Error() '********************************** ' this is the function to ' handle Errors when trying ' to read or write to the socket '********************************** SELECT CASE MySock.Status CASE Net.CannotCreateSocket label3.Text="The system does not allow to create a socket" CASE Net.HostNotFound label3.Text="Host not Found" CASE Net.ConnectionRefused label3.Text="Unable to Connect. Connection Refused" CASE Net.CannotRead label3.Text="Error Reading Data" CASE Net.CannotWrite label3.Text="Error Writing Data" END SELECT Set_Interface (FALSE)ENDPRIVATE SUB Set_Interface(bState AS Boolean) '**************************************** ' An auxiliar method to enable/disable ' controls in the formulary , when ' connection is stablished or closed '**************************************** Button1.Enabled=NOT bState TextBox1.Enabled=NOT bState TextBox2.Enabled=NOT bState 'CmbProtocol.Enabled=NOT bState 'Label5.Enabled=NOT bState Button2.Enabled=bState Timer1.Enabled=bState 'TextArea1.Enabled=bState 'Button3.Enabled=bState 'TextArea2.Enabled=bState IF bState=TRUE THEN TextArea1.Text="" ENDPUBLIC SUB Button1_Click() '****************************************** ' To connect to remote host we call to ' connectsocket method, passing Host Name ' and port as arguments '****************************************** DIM RetVal AS Integer Button1.Enabled=FALSE ' Stablishing a TCP connection. ' Here we use Host and ' Port properties, we could also ' do directly MySock.Connect(TextBox1.Text,VAL(TextBox2.Text)) MySock.Host=TextBox1.Text MySock.Port=Val(TextBox2.Text) MySock.Connect()ENDPUBLIC SUB Timer1_Timer() '*************************** ' timeout trying to connect '*************************** ME.Enabled=TRUE Timer1.Enabled=FALSE IF MySock.Status<>Net.Connected THEN CLOSE MySock Set_Interface (FALSE) Label3.Text="Timeout trying to stablish connection" END IFENDPUBLIC SUB Button2_Click() '********************************** ' Here we close the connection ' to remote host '********************************** CLOSE MySock Set_Interface(FALSE) Label3.Text="Connection closed by user"ENDPUBLIC SUB Form_Close() '********************* ' Close possible Stablished connections '********************* IF MySock.Status>0 THEN CLOSE #MySockENDPUBLIC SUB Save_Data(S AS String) DIM hFile AS File hFile = OPEN "/home/gerry/smdr.txt" FOR WRITE APPEND WRITE #hFile, SENDGerry
Life is for LIVING!
_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE
More information about the User
mailing list