April 26, 2024, 10:42:26 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Program Control Question

Started by tbohon, December 11, 2013, 08:44:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tbohon

I KNOW I'm going to be embarrassed when I learn the answer here ...  ;D

Haven't worked with CBasic for almost a year - have been forced to the 'Dark Side' (.Net) - and want to get back up to speed.  A test program I'm writing simply puts a form on the screen with an 'Exit' button and when either the 'X' in the corner or the 'Exit' button are pressed the program is supposed to close.  Unfortunately, as it's listed below, the program executes and paints the window and then closes immediately ... becoming merely a flash in my fading eyesight.

What am I doing wrong?  What is in the wrong place?  Why do I continue to torture myself with computer 'stuff' after 48 years?

Thanks in advance ... and don't hold back, I can take it (disregard the occasional whimper)


DEF win:window

WINDOW win,0,0,785,525,0x80CA0080,0,"My Test Program",main
setwindowcolor win, rgb(176,196,222)

.
.
.

CONTROL win,"BS,Exit,340,422,55,25,0x50000000,14"

.
.
.

run = 1

waituntil run = 0

closewindow win

end

;-----------------------------

sub main
Select @CLASS
case @IDCLOSEWINDOW
run=0
case @IDCREATE
CenterWindow win
case @IDCONTROL
select @CONTROLID
case 14
run = 0
endselect

EndSelect
Return


Note that if I comment out the 'run=0' in the select case 14 event the window paints just fine and sits waiting patiently for me.

"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

LarryMc

taking the code exactly as you posted above will not run.
After removing the lines  that have only the "." on the line the program runs fine.

That would make me think that there is more to the program than you are showing  and the problem lies in that unseen code.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

tbohon

Larry, here is the full program code.  Would appreciate it if you could tell me what in the world I'm doing wrong here ...



DEF win:window

WINDOW win,0,0,785,525,0x80CA0080,0,"WinTest",main
setwindowcolor win, rgb(176,196,222)

CONTROL win,"RE,,430,7,335,435,0x50A00004,1"
CONTROL win,"BS,Item 1,25,22,100,25,0x50000000,3"
CONTROL win,"BS,Item 2,25,52,100,25,0x50000000,4"
CONTROL win,"BS,Item 3,25,82,100,25,0x50000000,5"
CONTROL win,"BS,Item 4,25,112,100,25,0x50000000,6"
CONTROL win,"BS,Item 5,25,142,100,25,0x50000000,7"
CONTROL win,"BS,Item 6,25,172,100,25,0x50000000,17"
CONTROL win,"BS,Item 7,25,202,100,25,0x50000000,18"
CONTROL win,"BS,Item 8,25,232,100,25,0x50000000,19"
CONTROL win,"BS,Item 9,25,262,100,25,0x50000000,20"
CONTROL win,"BS,Item 10,25,292,100,25,0x50000000,21"
CONTROL win,"BS,Item 11,160,22,100,25,0x50000000,22"
CONTROL win,"BS,Item 12,160,52,100,25,0x50000000,23"
CONTROL win,"BS,Item 13,160,82,100,25,0x50000000,24"
CONTROL win,"BS,Item 14,160,112,100,25,0x50000000,25"
CONTROL win,"BS,Item 15,160,142,100,25,0x50000000,26"
CONTROL win,"BS,Item 16,160,172,100,25,0x50000000,27"
CONTROL win,"BS,Item 17,160,202,100,25,0x50000000,28"
CONTROL win,"BS,Item 18,160,232,100,25,0x50000000,29"
CONTROL win,"BS,Item 19,160,262,100,25,0x50000000,30"
CONTROL win,"BS,Item 20,160,292,100,25,0x50000000,31"
CONTROL win,"BS,Item 21,295,22,100,25,0x50000000,32"
CONTROL win,"BS,Item 22,295,52,100,25,0x50000000,33"
CONTROL win,"BS,Item 23,295,82,100,25,0x50000000,34"
CONTROL win,"BS,Item 24,295,112,100,25,0x50000000,35"
CONTROL win,"BS,Item 25,295,142,100,25,0x50000000,36"
CONTROL win,"BS,Item 26,295,172,100,25,0x50000000,37"
CONTROL win,"BS,Item 27,295,202,100,25,0x50000000,38"
CONTROL win,"BS,Item 28,295,232,100,25,0x50000000,39"
CONTROL win,"BS,Item 29,295,262,100,25,0x50000000,40"
CONTROL win,"BS,Item 30,295,292,100,25,0x50000000,41"
CONTROL win,"BS,Apply CREDIT,25,357,105,25,0x50000000,9"
CONTROL win,"BS,Apply COUPON,25,407,105,25,0x50000000,10"
CONTROL win,"BS,TOTAL,295,357,100,25,0x50000000,11"
CONTROL win,"BS,Print Receipt,240,387,155,25,0x50000000,12"
CONTROL win,"BS,CLEAR,240,422,55,25,0x50000000,13"
CONTROL win,"BS,Exit,340,422,55,25,0x50000000,14"
CONTROL win,"T,Sub-Total,600,452,99,20,0x5000010B,15"
setcontrolcolor win, 15, rgb(0,0,0) ,rgb(176,196,222)

CONTROL win,"E,Edit1,670,447,75,25,0x50800000,16"

centerwindow win

run = 1
waituntil run = 0
closewindow win
end

;-----------------------------

sub main
select @CLASS
case @IDCONTROL
select @CONTROLID
case 9
run = 0
endselect

case @IDCLOSEWINDOW
run = 0

endselect

return




Thanks in advance for your help.
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

GWS

Hi,

It works pretty well here, except your exit button is ID 14

CONTROL win,"BS,Exit,340,422,55,25,0x50000000,14"

Can't remember what control type BS is .. you may be using a later version of CB than me.
I'd just use 'B'.

and your message block refers to ID 9 for the Exit.

So just change your message block to ..


select @CLASS
case @IDCONTROL
select @CONTROLID
case 14
run = 0
endselect


and it should be OK

Best wishes, :)

Graham
Tomorrow may be too late ..

tbohon

Made that change (not sure why it was set to '9' anyway) and it still didn't work.  I went back into the source and changed the 'BS' type to 'B' as you mentioned and it started working properly.  Version of CB I have is 1.153 ... will have to figure out what 'BS' stands for (in this case, I know and deal with the generally accepted definition on a daily basis ... :) )

Out of curiosity I created a simple form in CB's form designer, generated the code and get the following:



DIALOG d1,0,0,295,199,0x80C80080,0,"Caption",Handler
CONTROL d1,"BS,Exit,112,89,70,20,0x50000000,1"



That's how I started the original program, taking this and converting it from DIALOG to WINDOW ... so maybe 'BS' means something special to a DIALOG ... ?

Interesting ...

Thanks again for the help, greatly appreciate it!!!
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

tbohon

If I would just learn to read the help file ...  BS is a special button and appears to be the default in the code generator for some reason.

From the Help file:

Quote

Defining a Control

Controls such as an edit box or check box can be created in either a window or a dialog. The control is defined after the window or dialog is opened and dynamically added. Controls are automatically removed when the window or dialog is closed. The syntax of the CONTROL statement is:

CONTROL window|dialog, definition {, definition…}

Each definition is a string literal or variable containing the type of control, title text, dimensions, flags and an ID for your message subroutine. The control definition has the format of:

"Type, title, L, T, W, H, flags, ID"

Type is the type of control to be created. The possible values for type are:

B creates a button that can have a colored background
BS creates a standard system button that supports themes
E creates an edit box
S creates a scrollbar
R creates a radio button
C creates a check box
L creates a list box
M creates a combo box
T creates a static text control
LV creates a List View control
RE creates a Rich Edit control
SW creates a status window
TA creates a tab control


Why it's the default in my installation and why it doesn't behave well in the sandbox with the rest is still under investigation.
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

GWS

Ah .. that reminds me .. you're using one of the new-fangled versions ..  ;D

I'm still using version 1.0 - the fully tried and tested version.  The problem with later versions is that they were never fully tested, and some problems might still pop up.  I think version 1.1 is still available for free to registered users. That might be more reliable - the only difference being it saved the samples on the C: drive if I remember correctly.  That's OK, 'cos you can easily copy them to wherever you install CBasic.

Some folks fancied themed buttons - I never bothered with that since I'm using XP in it's Windows Classic mode. :)

Best wishes, :)

Graham
Tomorrow may be too late ..