I would like to run a couple of similar command sequences from a menu in Lauterbach T32 (or even from the toolbar, the issue is the same).
Menu is built using something like:
menu.reprogram
(
add toolbar
(
toolitem "Say NE", "SN,r"
(
GOSUB sayNE
)
)
)
enddo
sayNE:
(
print "ne"
return
)
According to documentation, this is supposed to work. Something similar works if I remove the menu.reprogram part and only run "gosub sayNE".
But when this code is supposed from the actual menu callback, it does NOT. It prints "no such label" error message which is not really helpful.
I have even trying moving the subroutine into an included file, which is sourced in via Do ~~~~/subSayNE.cmm followed by gosub .... The Do ... command works but calling gosub afterwards brings the same "no such label" error as before.
It looks like there is a restriction on what's allowed to do but I cannot find it documented. Is there any way to use subroutines there or is there any better trick to run repeated actions with only minor modifications (parameters)?
The subroutines are only available during the time the script is executed. When script execution ends (in your case this happends with the ENDDO command), the labels/subroutines cease to exist.
A good solution for this problem is to equip the script with a calling parameter. When the script is called without parameter, the menu or toolbar is installed. If the script is called with a parameter, then the subroutine with the same name is called.
The user will install the menu/toolbar by calling the script without parametes, while the menu/toolbar item will call the script with the subroutine name as parameter.
PRIVATE ¶meter
ENTRY %LINE ¶meter
IF "¶meter"!=""
(
;if parameter specified, go to subroutine with that name
GOSUB ¶meter
ENDDO
)
ELSE
(
;set up script caller
PRIVATE &CALL
&CALL="DO """+OS.PresentPracticeFile()+""" "
; "&+" in the menu means that macro &CALL will be replaced at compile time
MENU.ReProgram
(&+
ADD
TOOLBAR
(
TOOLITEM "Say NE" "SN,r"
(
;call script with parameter SayNe
&CALL SayNe
)
)
)
ENDDO
)
;subroutines
SayNe:
(
PRINT "ne"
RETURN
)
Related
In a Google Sheet I want to compare two dates and check if either one (Plan start date, actual start date) is blank. It should show the text "not started" then. If not if(plan start date <Actual start date) show as Delay else "Inline":
=if((DAYS360(D8,C8)<0,"Delay","Inline",IF(ISBLANK(D8),"Not started")))
This didn't work. Can anyone help?
Try this
=IF(DAYS360(D8;C8)<0;"Delay";IF(ISBLANK(D8);"Not started";"Inline"))
Use semicolons in Excel, not commas. Also, the IF conditionals are written like this:
=IF(condition; value if true; value if false)
If you write more than 3 parameters it just won't work. You can put an IF inside of a value parameter so you nest two IFs (or as many as you wish)
EDIT: ok I thought it was an Excel and not a google spreadsheet. Maybe there you can use commas. The rest is the same though, you had a mistake in the IF statement. =IF(DAYS360(D8;C8)<0,"Delay",IF(ISBLANK(D8);"Not started","Inline")) should do the work.
You have a syntax error:
=if(
(
DAYS360(D8,C8)<0,
"Delay",
"Inline",
IF(
ISBLANK(D8),
"Not started"
)
)
)
Your outer IF has 4 arguments, while the proper syntax is: IF( condition, result if true, result if false) and the 3rd argument is optional.
EDIT: As far as I understand, you might want to achive something like this:
IF(
OR(ISBLANK(C8), ISBLANK(D8)),
IF(
ISBLANK(C8),
"first is blank",
"second is blank"
),
"none of them is blank"
)
And in the "none of them is blank" case you may want to place an additional IF examining DAYS360(C8, D8).
Hi I’m developing a user interface for processing AI (Adobe illustrator) files, I have grouped sets of lines, using the tag feature. I want to know which set of lines is selected on click (which tag for example), but I can't figure out how, as the function click_poligono always gets the last tag, any help on how I'm supposed to do this??
part of my code is :
def click_poligono(self,event,poligono):
self.canvas.itemconfigure('poligono%s'%poligono , fill = 'blue')
def cambio_listbox(self,*args,**kwargs):
<-------Mysql queries and processes------->
for i in range(len(matriz_start)):
print i
self.canvas.tag_bind('poligono%s'%i , '<ButtonPress-1>' , lambda event: self.click_poligono(event,'%s' % i)
for j in range(len(matriz_start[i])):
if True: #if for possible matrix condition
self.canvas.create_line(10+matriz_start[i][j]['x']*680/maximo,690-(matriz_start[i][j]['y']*680/maximo),10+matriz_end[i][j]['x']*680/maximo,690-(matriz_end[i][j]['y']*680/maximo), width = 2 ,tags ='poligono%s'%i)
So the question here is , how can I manage to select the set of lines I click with the mouse , and process it on one function , as the set of lines is variable depending on the number of figures the file (Adobe Illustrator) has..
I hope I'm clear on what I'm asking, and I'm open to new suggestions on my code.
I guess it's because of lambda.
You have
lambda event: self.click_poligono(event,'%s' % i)
where event is local variable but i is not.
Try this
lambda event, i=i: self.click_poligono(event,'%s' % i)
I have a class defined as this:
class decider(object):
def __init__(self, brain):
self.brain = brain
##stuff
## brain is an object
In a class function I have two print statements, right next to each other, like so:
def somefunction(self, someParam):
print "Something First"
print "Another something: " + self.brain.aVariable + ", " + self.brain.anotherVariable
# more stuff
# execution continues as normal
# the object called in brain exists (ive checked)
In another function (in the same class) I call this function.The first print statement is printing, the second one is not. No exceptions are raised and the code just skips that line. No crashes either. I find this pretty bizarre and had not happened to me until now. Is there a reason for why this could possibly be happening?
If it matters, I'm running python 2.7 on an embedded system with an ATOM Z530 processor.
Could be buffered? Does anything print after the second call?
Add another print after the second call to force to clear the buffer
Ok so I am working on a project and I am doing this and I get to the if statement in confirmOne and it gives me "( was not expected at this time." Please help!
Many of the stray "You got to here!" messages are from me trying to debug it. I really need this soon. Please help. I also tried deleting parts and it still doesn't seem to work. If you see any other errors please tell me as I need all the help I can get. Thank you!
:grabInput
echo Please enter the username of the user you wish to access.
REM - } End Echoing Information/Main Menu | Grab Input {
set /p result=
goto correctName
REM - } End Grab Input | Process Input {
:correctName
set /p input=%result%
goto confirmOne
:confirmOne
echo Got to confirmOne
pause
if %input%==[] (
pause
cls
echo Oops! Looks like you didn't enter anything! Try Agian!
echo.
echo ................................................................................
echo.
goto grabInput
) ELSE (
goto confirmTwo
)
:confirmTwo
echo Got to ConfirmTwo
pause
if %input%==~help (
goto helpMenu
) ELSE (
goto confirmThree
)
:confirmThree
echo Got to ConfirmThree
if %input%==~info (
goto infoMenu
) ELSE (
goto swapDrive
)
Well, if you didn't enter anything for %input%, then your if statement would look like if ==[] (.
Your if statement should look like if [%input%] == [] (
I also see a lot of unnecessary code, you should take a look over your script.
Batch ALWAYS works on strings.
with the statement if %input%==[], when %input% is set to [nothing] (which is what you're trying the detect), batch substitutes [nothing] fo %input% and gets
IF ==[] (
and is confused because '(' is not a comparison operator.
[] is not some magic mantra. It's an old method of detecting the presence of parameters such that [%1] would equal [] if the parameter was absent. It doesn't work when the variable contains spaces or some other characters.
if "%var%"=="" is better
if not defined var is better still
Note that
set /p var=
will NOT set var to [nothing] in you simply press enter, It will leave var unchanged.
Hence this
set var=something
set /p var=
will leave var set to something. You should code this as
set "var="
set /p var="Some prompt "
if not defined var echo VAR is not defined
The quotes around var= ensures that var is NOT set to [some spaces] if there are trailing spaces on the line.
Other than that, the sequence
goto somelabel
:somelabel
(REM lines are irrelevant) is superfluous.
equally, in
if somecondition (goto somewhere) else (goto somewhereelse)
:somewhereelse
the else condition is superfluous
Batch only notices :label as a DESTINATION for a GOTO or a CALL. and will otherwise simply charge straight through any :label it finds as though they were remarks statements.
I am completely new to Fortran and pretty new to programming in general. I am trying to compile a script someone else has written. This is giving me a few problems. The top half of the code is:
C
C Open direct-access output file ('JPLEPH')
C
OPEN ( UNIT = 12,
. FILE = 'JPLEPH',
. ACCESS = 'DIRECT',
. FORM = 'UNFORMATTED',
. RECL = IRECSZ,
. STATUS = 'NEW' )
C
C Read and write the ephemeris data records (GROUP 1070).
C
CALL NXTGRP ( HEADER )
IF ( HEADER .NE. 'GROUP 1070' ) CALL ERRPRT(1070,'NOT HEADER')
NROUT = 0
IN = 0
OUT = 0
1 READ(*,'(2i6)')NRW,NCOEFF
if(NRW .EQ. 0) GO TO 1
READ (*,'(3D26.18)',IOSTAT =IN) (DB(K),K=1,NCOEFF)
DO WHILE ( ( IN .EQ. 0 )
. .AND. ( DB(2) .LT. T2) )
IF ( 2*NCOEFF .NE. KSIZE ) THEN
CALL ERRPRT(NCOEFF,' 2*NCOEFF not equal to KSIZE')
ENDIF
C
C Skip this data block if the end of the interval is less
C than the specified start time or if the it does not begin
C where the previous block ended.
C
IF ( (DB(2) .GE. T1) .AND. (DB(1) .GE. DB2Z) ) THEN
IF ( FIRST ) THEN
C
C Don't worry about the intervals overlapping
C or abutting if this is the first applicable
C interval.
C
DB2Z = DB(1)
FIRST = .FALSE.
ENDIF
IF (DB(1) .NE. DB2Z ) THEN
C
C Beginning of current interval is past the end
C of the previous one.
CALL ERRPRT (NRW, 'Records do not overlap or abut')
ENDIF
DB2Z = DB(2)
NROUT = NROUT + 1
print*,'Out =', OUT
WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)
print*,'Out2 =', OUT
IF ( OUT .NE. 0 ) THEN
CALL ERRPRT (NROUT,
. 'th record not written because of error')
ENDIF
So, when I print "Out" and "Out2" to the screen I find that Out=0 and Out2=110. As it is not longer equal to zero, the program gives me an error. Therefore I am basically wondering about what is happening here:
WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)
I assume that 12 refers to the file I have opened (and created), and want to write to. What does the rest of the first brackets do? And what is the point of the second? Does that gives me the information I want to put in my file? In case, where does DB get filled with that?
Generally I am wondering what is going wrong? Why does OUT change value? (I need t
NCOEFF is defined as an Integer in the beginning of the programme, and DB: as DOUBLE PRECISION DB(3000), DB2Z/0.d0/ , so I assume DB is an array of some sort.
In this program, OUT is telling if the write statement was successful or not. (the IOSTAT parameter to the write statement means "I/O status", or input/output status). It returns 0 if the I/O operation was a success, or the number of the error code otherwise. You can find what the error codes mean here.
I'm not familiar with the REC parameter, but a starting place to investigate yourself can be found here.
To quote the handbook REC indicates the record number to be read or written. As advised, see the documentation which accompanies your compiler for further explanation.
(DB(K),K=1,NCOEFF) means 'all the elements in DB from 1 to NCOEFF. You are looking at an io-implied-do statement.
The statement
WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K),K=1,NCOEFF)
is, if memory serves me, called an "implied DO-loop". As written, it will write NCOEFF values from array DB, starting at DB(1).
It is called an implied DO-loop because the explicit form would be (in FORTRAN IV, for the ancients: I know it a lot better than the more modern variations) something along the lines of:
DO 10 K=1,NCOEFF
WRITE (12,REC=NROUT+2,IOSTAT=OUT) DB(K)
10 CONTINUE
(Pretend that the first two lines are indented six columns.) This is a DO-loop. The implied DO-loop form lets you put the "loop" right in the input/output statement.
What makes it useful is that you can have multiple arrays, and multiple loops. For a simple example:
WRITE (12,REC=NROUT+2,IOSTAT=OUT) (DB(K), DC(K), K=1,NCOEFF)
110 is the error code thrown by the WRITE call. You need to check your FORTRAN RTL (run-time library) reference. It should list the possible error codes. I think 110 means that you're trying to convert a double-precision value to an integer, but the value is bigger than you can store in an integer. Maybe dump the values in DB and see.