TC_Event fails to return Event$

In writing a short program to calculate confidence intervals and criterion values for correlations, I encountered a problem that is extremely unusual and deeply mysterious: TC_Event returns the null string for Event$: none of the controls can work.

The program shell was generated by TBilt, then modified; but "commenting out" the interface code doesn't affect the problem. The program misbehaves under 5.32 as well as 5.5, on my desktop as well as my laptop, and under Wine as well as Windows XP. Copying the interface code as a block into another working shell produced the same problem; but copying it a few lines at a time produced a working program (see http://www.tru.ca/faculty/wlroberts/r_confidence_interval.exe). All very strange.

No doubt it is arising out of some simple, obvious mistake of mine, or some peculiarity in my hardware. But I thought that I would show it to you. The code is below. I have inserted "Print event$" in the main loop (line 93). Let me know if it works for you or not.

best regards,

Bill Roberts

PS. It would be convenient to be able to attach files....

! TC_Event returns the null string, as reported at line 93

LIBRARY "C:\Program Files\TB Gold\tblibs\truectrl.trc", "C:\Program Files\TB Gold\tblibs\truedial.trc"
LIBRARY "\tbasic\library\stat1lib.trc"

PUBLIC stextid_4b, stextid_5b, stextid_7a, stextid_7c, stextid_9a, stextid_9b ,stextid_9c, stextid_9d

CALL TC_SetUnitsToPixels ! Temporary...
! CALL TC_Show (0) ! So we have something to see

! SECTION 1 *** CREATE WINDOW HERE ***

CALL TC_Win_Create (winid_1, "TITLE|CLOSE", 77, 860, 620, 125)
CALL TC_Show (winid_1)
CALL TC_Win_SetTitle (winid_1, "Confidence interval and critical values for r")

! SECTION 2 *** INSERT MENU CREATION CODE HERE ***

! SECTION 3 *** CREATE INTERFACE COMPONENTS HERE ***

!CALL TC_SText_Create (stextid_4b, "", 610, 650, 190, 160)
!CALL TC_SText_Create (stextid_4a, "df =", 560, 600, 190, 170)
!
!
!CALL TC_SText_Create (stextid_5b, "", 610, 650, 230, 200)
!CALL TC_SText_Create (stextid_5a, "p =", 560, 600, 230, 200)
!CALL TC_Groupbox_Create (grbid_4, "Significance of r", 500, 700, 235, 150)
!
!
!CALL TC_PushBtn_Create (pbid_1, "Calculate", 334, 436, 230, 191)
!
!CALL TC_PushBtn_Create (pbid_2, "Exit", 335, 437, 383, 344)
!
!
!CALL TC_SText_Create (stextid_2, "Sample size =", 100, 200, 256, 230)
!CALL TC_Edit_Create (editid_2, "", 205, 287, 256, 230)
!
!
!CALL TC_SText_Create (stextid_1, " r =", 170, 200, 184, 159)
!CALL TC_Edit_Create (editid_1, "", 205, 287, 184, 159)
!
!CALL TC_SText_Create (stextid_5, "Enter the correlation and sample size (N)", 260, 600, 100, 67)
!
!LET b = 275
!LET t = 255
!LET l = 550
!LET r = l + 40
!LET l2 = r + 10
!LET r2 = l2 + 15
!LET l3 = r2 + 5
!LET r3 = l3 + 40
!CALL TC_SText_Create (stextid_7a, "lower", l,r, b, t)
!CALL TC_SText_Create (stextid_7b, "to", l2, r2, b, t)
!CALL TC_SText_Create (stextid_7c, "upper", l3,r3, b, t)
!CALL TC_Groupbox_Create (grbid_7, "95% confidence interval", 500, 700, 280, 235)
!
!LET b1 = 320
!LET t1 = 340
!LET b2 = b1 + 40
!LET t2 = t1 + 40
!LET b3 = b1 + 2 * 40
!LET t3 = t1 + 2 * 40
!LET b4 = b1 + 3 * 40
!LET t4 = t1 + 3 * 40
!
!LET lcv = 560
!CALL TC_SText_Create (stextid_8a, ".10 =", 520, lcv, b1, t1)
!CALL TC_SText_Create (stextid_8b, ".05 =", 520, lcv, b2, t2)
!CALL TC_SText_Create (stextid_8c, ".01 =", 520, lcv, b3, t3)
!CALL TC_SText_Create (stextid_8d, ".001 =", 515, lcv, b4, t4)
!
!CALL TC_SText_Create (stextid_9a, ".out", 570, 595, b1, t1)
!CALL TC_SText_Create (stextid_9b, ".out", 570, 595, b2, t2)
!CALL TC_SText_Create (stextid_9c, ".out", 570, 595, b3, t3)
!CALL TC_SText_Create (stextid_9d, ".out", 570, 595, b4, t4)
!
!
!CALL TC_Groupbox_Create (grbid_8, "Critical values", 500, 700, 490, 290)
!
!CALL TC_Groupbox_Create (grbid_2, "Output", 460, 760, 500, 110)
!
!CALL TC_Groupbox_Create (grbid_1, "Input", 25, 309, 390, 110)
!
!CALL TC_Groupbox_Create (grbid_3, "Significance and confidence interval for r", 155, 623, 110, 40)

! SECTION 4 *** OTHER INITIALIZATION ***

! SECTION 5 *** EVENT LOOP ***

DO
CALL TC_Event (timer, event$, window, x1, x2)
PRINT event$

SELECT CASE event$

CASE "KEYPRESS"
IF x1 = 27 THEN
EXIT DO ! Exit the event loop when Escape pressed
END IF

CASE "HIDE"
IF window = 0 then
PRINT "Just closed the default output window"
PAUSE 2
EXIT DO ! Alternate exit

END IF

! Window-related events
CASE "MENU" ! x1 = menu number, x2 = menu item
CALL ProcessMenu (window, x1, x2)

! Control-related events. x2 = control id
CASE "CONTROL SINGLE"
CASE "CONTROL DOUBLE"
CASE "CONTROL SELECT"
CASE "CONTROL DESELECTED"

IF x2 = pbid_1 then
CALL CB_PushBtn_pbid_1 (x1, x2)

ELSE IF x2 = pbid_2 then ! exit
LET message$ = "Version 2.0.1, 25 November 2010. Written by W. L. Roberts."
LET message$ = message$ & "|Updates available at http://www.tru.ca/faculty/wlroberts/"
CALL TD_Message ("Now leaving...", message$, "Exit|Cancel", default, result)
IF result = 1 then EXIT DO

ELSE IF x2 = editid_2 then
CALL CB_ListEdit_editid_2 (x1, x2)

ELSE IF x2 = editid_1 then
CALL CB_ListEdit_editid_1 (x1, x2)
END IF

CASE ELSE
END SELECT

LOOP

CALL TC_Cleanup

SUB ProcessMenu (w, m, i)

PRINT "You just selected item "; i; " from menu "; m

END SUB

END

MODULE CallBack

! these routines are unfinished; but the problem occurs without their being called

! *** INSERT CALL BACK ROUTINES HERE ***

SHARE df, r
DECLARE DEF tprob

DECLARE PUBLIC stextid_4b, stextid_5b, stextid_7a, stextid_7c, stextid_9a, stextid_9b ,stextid_9c, stextid_9d

SUB CB_ListEdit_editid_2 (x1, x2)

CALL TC_GetText (x2, t$)
WHEN error in
LET N = val(t$)
LET df = N - 2
USE
LET message$ = "Error! Non-numeric value entered"
CALL TD_Message ("Error", message$, "Continue", default, result)

END WHEN

END SUB

SUB CB_ListEdit_editid_1 (x1, x2)

CALL TC_GetText (x2, t$)

WHEN error in
LET r = val(t$)

LET decimal = pos(t$, ".")
IF decimal = 0 then
LET minus$ = ""
IF t$[1:1] = "-" then
LET minus$ = "yes"
LET t$ = t$[2:20]
END IF
LET digits = len(t$) ! get number of digits
LET r = r/(10^digits) ! insert decimal point if omitted
IF minus$ = "yes" then LET r = -1 * r
PRINT r
! CALL TC_SetText (editid_1, str$(r))
END IF
USE
LET message$ = "Error! Non-numeric value entered"
CALL TD_Message ("Error", message$, "Continue", default, result)
END WHEN
END SUB

SUB CB_PushBtn_pbid_1 (x1, x2)

LET rpb2 = t^2 / (t^2 + df)
WHEN error in
LET p = (1 - Tprob (df, t)) * 2
USE
LET message$ = "Error! Unable to calculate binomial probability."
CALL TD_Message ("Error", message$, "Continue", default, result)
EXIT SUB
END WHEN

LET rpb2$ = using$(".###", rpb2)
CALL TC_SetText (stextid_4b, rpb2$)

LET p$ = using$(".###", p)
CALL TC_SetText (stextid_5b, p$)

END SUB

END MODULE

Comments

empty event$

Thanks! I had the feeling that I was overlooking something obvious. I must have accidentally deleted the TC_Init statement from the TBilt code. Sigh. (I am so embarrassed...)

TBilt doesn't supply a TC_Win_Switch statement, and the statement is missing from the version of the program that works. TC_Show seems to be sufficient. But if I have this trouble again, I will try TC_Win_Switch.

Best regards,

Bill Roberts

Empty eventS

Hi Bill,

The primary cause of your problem is that you did not initialize TrueCtrl, e.g.

PUBLIC stextid_4b, stextid_5b, stextid_7a, stextid_7c, stextid_9a, stextid_9b ,stextid_9c, stextid_9d
CALL TC_init !*********************************************
CALL TC_SetUnitsToPixels ! Temporary...
! CALL TC_Show (0) ! So we have something to see

! SECTION 1 *** CREATE WINDOW HERE ***

CALL TC_Win_Create (winid_1, "TITLE|CLOSE", 77, 860, 620, 125)
CALL TC_Show (winid_1)
CALL TC_win_switch(winid_1) !***********************************

The second problem is that you must make (winid_1) the target window otherwise you cannot see what you are printing. For this you should use TC_win_switch(winid_1)

The next problem is that PRINT event$ will print everything! TC_event generates all sorts of stuff, so I would suggest you use,

IF event$>"" then
SET COLOR 12
PRINT event$
Pause 1
END IF

You need to set the print color because the default might be the same as the background - so you won't see anything. Secondly, because event$ happen so fast I suggest you use PAUSE so that you can see the events as they happen.

Regards
Big John