How to send command to terminal ?

Questions regarding syntax

Re: How to send command to terminal ?

Postby berndnoetscher » Mon Nov 29, 2010 1:45 pm

Hello,

dollyknot wrote:
What I am very unclear about is, how does one control what a button does on the form and then have it set a variable in the source code.


Just create a commandbutton on the form and make a double click on it -> the code module of the form will be opened with some code for an event function.

Code: Select all
Sub CommandButton1_OnEvent()
End Sub


make it to


Code: Select all
Sub CommandButton1_OnEvent()
  MsgBox("Hello")
End Sub





and try your program.
berndnoetscher
Site Admin
 
Posts: 1059
Joined: Tue Sep 25, 2007 9:37 am

Re: How to send command to terminal ?

Postby dollyknot » Mon Nov 29, 2010 3:34 pm

Sorry if I appear a bit dense but I am 61 and I doubt many 61 year old people are learning a new computer language.

I got what you suggested to work, now all I need to do is get the syntax correct to select '-xponder' with the command button.

I've tried

Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String
Dim PonderCode as String
PonderCode = ("ponder")
TimeCode = Inputbox ("Time limit ")
? TimeCode

ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & & Pondercode & " -scp crafty", TRUE)
End Sub

Private Sub CommandButton1_OnEvent()
PonderCode = ("-xponder")
End Sub

And it comes back syntax error missing )
I have tried many different combinations.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Henning » Mon Nov 29, 2010 3:51 pm

You have declared PonderCode variable in Sub Form_OnOpen(), that means it is local to that Sub. This means in Sub CommandButton1_OnEvent(), there is no declared variable PonderCode in the scope.

If you need to access variables Form-wise, declare them at the beginning of the code. To be sure they are accessible all-over declare them as Public.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: How to send command to terminal ?

Postby dollyknot » Mon Nov 29, 2010 4:44 pm

I now have it working without syntax errors with this code.

Dim PonderCode as String
rem PonderCode = ("xponder")

Private Sub CommandButton1_OnEvent()
PonderCode = ("-xponder")
End Sub


Private Sub Form_OnOpen()
Dim ReturnCode as Integer
Dim TimeCode as String

TimeCode = Inputbox ("Time limit ")
? TimeCode

ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty", TRUE)
End Sub

The problem now is, it does not give me access to the command button on the form, it asks me what time limit, then invokes crafty, I want to set PonderCode to either -xponder or -ponder before crafty runs.

Thanks both for helping me.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Henning » Mon Nov 29, 2010 7:48 pm

Add a new CommandButton, label it ie Start.

Move the code in Sub Form_OnOpen() to the new Private Sub Start_OnEvent(). As it is now, shell is run before you have a chance to change the behavior with CommandButton1.

/Henning
Henning
 
Posts: 262
Joined: Mon Feb 09, 2009 12:03 am
Location: Sweden

Re: How to send command to terminal ?

Postby dollyknot » Sun Dec 05, 2010 1:27 am

Gawd help me, but how do I change the text on a command button, I am sorry I am so thick.

BTW the rest of this wonderful program works perfectly Henning, except from the loveliness of two buttons both with the text on them commandbutton and me with little idea how to change them because I do not understand the English of the help files. They seem to be written in some other language.
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby tseyfarth » Sun Dec 05, 2010 3:31 am

Dollyknot,

No, you are not thick. Learning a new IDE and/or language, which no matter what you do or which you try, is never the same as what you are used to - trust me. I know!

As for changing the text (also called a "caption" depending on the object) is done through the property window. However, you can also do this programatically by naming the object then either ".text" or ".caption" = "whatever name"

Hope this helps!

Tim
tseyfarth
 
Posts: 101
Joined: Mon Aug 02, 2010 10:11 am

Re: How to send command to terminal ?

Postby Slowdown » Sun Dec 05, 2010 8:13 am

@Peter
Is it possible to post your code here ?
So we can look at it, i like to know what is the input from the inputbox ?
for example SomeString = inputbox("your input ") receives a String with spaces into it you can't sent it directly to
the command line.
If for example SomeString is param1 param2 param3 you have to do the following,
SomeString = chr(34) & SomeString & chr(34).
SomeString is in that way presented to the command line as "param1 param2 param3" (watch the double quotes (") )
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

Re: How to send command to terminal ?

Postby dollyknot » Sun Dec 05, 2010 11:27 am

Dim PonderCode as String
rem PonderCode = ("-ponder")

Private Sub Start_OnEvent()
PonderCode = ("-xponder")
End Sub

Private Sub CommandButton2_OnEvent()

Label1.caption = "Start"

Dim ReturnCode as Integer
Dim TimeCode as String

TimeCode = Inputbox ("Time limit ")
? TimeCode

ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty", FALSE)


End Sub

It works ok, but one would have thought the code would have been the hard bit and the gui the easy bit, but I can't seem to get my head around it.

Like I have my form with two buttons on it, I click one button and it turns ponder mode off, the default being 'ponder' on, so crafty calculates what I might do, whilst I analyse the position.

I click the other button and it lets me select how much time crafty will spend on the game.

I looked at some of the code examples and thought that 'Label1.caption = "Start"' would label the button that selects the time and fires up xboard with crafty as its engine. Everything works ok and it does not complain about 'Label1.caption = "Start"' but the button remains with the caption 'Commandbutton' Perhaps the caption is set on the form somehow?
Regards,

Peter.

http://dollyknot.com
dollyknot
 
Posts: 17
Joined: Thu Nov 25, 2010 1:39 pm

Re: How to send command to terminal ?

Postby Slowdown » Sun Dec 05, 2010 1:43 pm

Hi Peter,

Have something put together hope it will help you,
Code: Select all
Public PonderCode as String
Public TimeCode as String

Private Sub StartWithPounder_OnEvent()
  Dim ReturnCode as Integer
 
  PonderCode = (" +ponder")
  TimeCode = SetMyTime
'  ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty", FALSE)
  Print ReturnCode & "  Shell " & "/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty" 
End Sub

Private Sub StartwithoutPounder_OnEvent()
  Dim ReturnCode as Integer
 
  PonderCode = (" -ponder")
  TimeCode = SetMyTime
'  ReturnCode = shell("/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty", FALSE)
  Print ReturnCode & "  Shell " & "/usr/games/xboard -fcp crafty -tc " & TimeCode & Pondercode & " -scp crafty"
End Sub

Private Function SetMyTime () as Integer
  Return Inputbox ("Time limit ")
End Function 

Have commented the shell command, so you must remove the comment sign (')

Complete project,
Attachments
dollyknot.zip
(1.25 KiB) Downloaded 131 times
Regards
Slowdown for now i'm back
Slowdown
 
Posts: 347
Joined: Sat May 02, 2009 6:48 pm
Location: Netherlands

PreviousNext

Return to Coding Questions

cron