Hi,
I am new here and I am new to CB. I have some concept how to program, but obviously not near enough to figure out how to program by using the EB User Guide alone and the including samples. For example I could not find any sample(s) dealing with numbers.
I already got a lot of help. Technically they wrote the code for me. I am embarrassed to ask more. I really want to do the programming myself, but I got stuck. I tried so many ways to use the suggested commands, and yet I can’t get it right. The User Guide is very good and well organized and simple to use, but need to include more samples. Like how to deal with integers.
But again, perhaps it is so obvious, just I don’t see it.
Perhaps a forum for beginners? So the experts could look over the newbie at times and newbie would not bored to death the experts in other area.
Cheers,
Hobo
I realy dont understand what is too tuff for you ???
You say dealing with numbers,how to deal with integers?
Simple if you define with DEF a:INT then a is integer type of variable.
And if you then set varible a=3 and then add command Print a you will give 3 displayed.Clear?
Second type is FLOAT in some basics called SINGLE wich is floating type,example:
DEF f:float
f=3.14
PRINT f
will display 3.14
If you want integer result you must writte this:
PRINT int(f)
will dispaly 3
Another type is DOUBLE,for example 0.3456789 etc.
If you want use number from editcontrol you must transform this string to number with VAL command.
'------------------------------------
def text:string
def a,b,result:int
a=6
'in edit control you writte number 5
text=getcontroltext(w,1) :' 1 is ID of edit control
'transform text to int
b=val(text)
result = a + b
move w,10,10
print w,result
Or if you want show result in other edit control you must use setcontroltext
; SETCONTROLTEXT window | dialog, ID, text
SETCONTROLTEXT w,2,str$(result) :' 2 is ID of second edit control
SETCONTROLTEXT w,2,"" ; erase content of this control
Is this now much clear ?
Aurel and Hobo,
Please read again the subject of this topic. Maybe you guys can move your discussion to another topic, or even to another forum.
Do you mean that i dont know wich is subject of this topic. >:(
So dont be too smart.
Man is lost and need help if you see.
I agree that this is no place for this disqusion.
So i suggest board for beginners ;)
regards
aurel
zlatko
He wasn't being smart.
He was simply saying that this topic is "Suggest more forum topics here." and not "Beginner's Tutorial".
Maybe the Moderator will create a new area as several have suggested and move this discussion there.
Larry ;D
Yes you right mr.Larry but i dont like this atitude .
Zlatko
It's remarkable that you speak more than one language. I think maybe this time something got lost in the translation and you misunderstood his "attitude".
Again, I'm sure he meant nothing with an "attitude". ;)
Larry
Keep it friendly guys .. :)
Beginner's questions and problems are always welcome - and consideration will be given to setting up a 'Beginners' section.
best wishes, :)
Graham
I removed techmail's reply here, two wrongs don't make a right. Keep it on topic and without flames guys or I will get my banning stick out. ::)
Paul.
Topic split to a new one.
Thanks mr.Paul!
Thank you very much all of you, especially Larry and Aurel, who have helped me greatly to put my feet down in CB. Just a few weeks and look what I was able to put together. You are all great guys. :)
The program below itself is useless, but teaches you to do a few things. I think that is good for beginners: creating a window, different controls, clicking on the check box the window stays front of all windows, and I now I try do do some simple mathematical calculation. More precisely add a few numbers together.
As you see I tried to use the GETCONTROLTEXT and SETCONTORLTEXT, but worked only as text string. I am going to use Aurel suggestion and see how far I get. :)
Hobo
'hobo example
'-------------------------
'Stay on Top setup
declare "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
'setid "NOMOVE",2
'setid "NOSIZE",1
'setid "TOPMOST",-1
'setid "NOTOPMOST",-2
'--------------------------
DEF win:WINDOW
DEF add2numberopen,add3numberopen:int
DEF inputa$,inputb$:string
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
Centerwindow win
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
CONTROL win,"B,Add3Num,5,30,60,20,0,2"
SETFONT win, "MS Sans Serif", 9, 400,0,2
CONTROL win,"B,Submit,70,200,60,20,0,10"
SETFONT win, "MS Sans Serif", 9, 400,0,10
showwindow win, @swhide,10
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,0,3"
showwindow win, @swhide,3
CONTROL win,"E,inputY,120,65,70,20,0,4"
showwindow win, @swhide,4
CONTROL win,"E,inputZ,120,15,70,20,0,9"
showwindow win, @swhide,9
CONTROL win,"E,output,120,115,70,20,0,7"
showwindow win, @swhide,7
CONTROL win,"T,Sum =,75,115,30,20,0,8"
showwindow win, @swhide,8
SETFONT win, "MS Sans Serif", 9, 400,0,8
SETCONTROLCOLOR win,8,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,11"
SETCONTROLCOLOR win,11,rgb(0,0,0),RGB(255,255,0)
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
IF (@controlid=1)&(add3numberopen=1)
showwindow win, @swhide,9
add3numberopen=0
ENDIF
IF (@controlid=1)&(add2numberopen=0)
add2number()
ENDIF
IF (@controlid=2)&(add3numberopen=0)
add3number()
ENDIF
'Stay on top control
IF (@CONTROLID=11)
mark = GETSTATE (win, 11)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
IF (@CONTROLID=10)
inputa$ = GETCONTROLTEXT (win,3)
inputb$ = GETCONTROLTEXT (win,4)
SETCONTROLTEXT win,7,inputa$+inputb$
ENDIF
ENDSELECT
RETURN
SUB add2number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swhide,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add2numberopen=1
RETURN
SUB add3number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swrestore,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add3numberopen=1
RETURN
I did it.
I am sure it is not the neatest code, but it works. The only thing I don’t know is how to make the answer 3 decimal places instead of 2. I think the default is 2.
'hobo example
'-------------------------
'Stay on Top setup
declare "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
'setid "NOMOVE",2
'setid "NOSIZE",1
'setid "TOPMOST",-1
'setid "NOTOPMOST",-2
'--------------------------
DEF win:WINDOW
DEF add2numberopen,add3numberopen:INT
DEF TEXT:STRING
DEF inputa,inputb,inputc,result:float
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
Centerwindow win
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
CONTROL win,"B,Add3Num,5,30,60,20,0,2"
SETFONT win, "MS Sans Serif", 9, 400,0,2
CONTROL win,"B,Submit,70,200,60,20,0,10"
SETFONT win, "MS Sans Serif", 9, 400,0,10
showwindow win, @swhide,10
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,0,3"
showwindow win, @swhide,3
CONTROL win,"E,inputY,120,65,70,20,0,4"
showwindow win, @swhide,4
CONTROL win,"E,inputZ,120,15,70,20,0,9"
showwindow win, @swhide,9
CONTROL win,"E,output,120,115,70,20,0,7"
showwindow win, @swhide,7
CONTROL win,"T,Sum =,75,115,30,20,0,8"
showwindow win, @swhide,8
SETFONT win, "MS Sans Serif", 9, 400,0,8
SETCONTROLCOLOR win,8,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,11"
SETCONTROLCOLOR win,11,rgb(0,0,0),RGB(255,255,0)
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
'clears edit boxes
IF (@controlid=1)
SETCONTROLTEXT win,9,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETCONTROLTEXT win,7,""
ENDIF
IF (@controlid=2)
SETCONTROLTEXT win,9,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETCONTROLTEXT win,7,""
ENDIF
'----------------------------------------
IF (@controlid=1)&(add3numberopen=1)
showwindow win, @swhide,9
add3numberopen=0
ENDIF
'----------------------------------------
'draw edit boxes by pressing control buttons
IF (@controlid=1)&(add2numberopen=0)
add2number()
ENDIF
IF (@controlid=2)&(add3numberopen=0)
add3number()
ENDIF
'----------------------------------------
'Stay on top control
IF (@CONTROLID=11)
mark = GETSTATE (win, 11)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
'----------------------------------------
'do mathematical operations
IF (@CONTROLID=10)&(add2numberopen=1)
text = GETCONTROLTEXT (win,3)
inputa=VAL(text)
text = GETCONTROLTEXT (win,4)
inputb=VAL(Text)
result=inputa+inputb
SETCONTROLTEXT win,7,STR$(result)
'SETCONTROLTEXT win,9,""
ENDIF
IF (@CONTROLID=10)&(add3numberopen=1)
text = GETCONTROLTEXT (win,9)
inputc=VAL(text)
text = GETCONTROLTEXT (win,3)
inputa=VAL(Text)
text = GETCONTROLTEXT (win,4)
inputb=VAL(text)
result=inputc+inputa+inputb
SETCONTROLTEXT win,7,STR$(result)
ENDIF
'---------------------------------------
ENDSELECT
RETURN
SUB add2number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swhide,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add2numberopen=1
RETURN
SUB add3number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swrestore,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add3numberopen=1
RETURN
One more thing. Is there any way to jump from one edit box to the next edit box by pressing the TAB key?
Good ;)
Yes you did it but there is simplier way or more direct way.Look:
'hobo example 1
'-------------------------
'Stay on Top setup
declare "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
'setid "NOMOVE",2
'setid "NOSIZE",1
'setid "TOPMOST",-1
'setid "NOTOPMOST",-2
'--------------------------
DEF win:WINDOW
DEF add2numberopen,add3numberopen:int
DEF inputa$,inputb$:string
DEF result:INT
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
Centerwindow win
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
CONTROL win,"B,Add3Num,5,30,60,20,0,2"
SETFONT win, "MS Sans Serif", 9, 400,0,2
CONTROL win,"B,Submit,70,200,60,20,0,10"
SETFONT win, "MS Sans Serif", 9, 400,0,10
showwindow win, @swhide,10
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,0,3"
showwindow win, @swhide,3
CONTROL win,"E,inputY,120,65,70,20,0,4"
showwindow win, @swhide,4
CONTROL win,"E,inputZ,120,15,70,20,0,9"
showwindow win, @swhide,9
CONTROL win,"E,output,120,115,70,20,0,7"
showwindow win, @swhide,7
CONTROL win,"T,Sum =,75,115,30,20,0,8"
showwindow win, @swhide,8
SETFONT win, "MS Sans Serif", 9, 400,0,8
SETCONTROLCOLOR win,8,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,11"
SETCONTROLCOLOR win,11,rgb(0,0,0),RGB(255,255,0)
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
IF (@controlid=1)&(add3numberopen=1)
showwindow win, @swhide,9
add3numberopen=0
ENDIF
IF (@controlid=1)&(add2numberopen=0)
add2number()
ENDIF
IF (@controlid=2)&(add3numberopen=0)
add3number()
ENDIF
'Stay on top control
IF (@CONTROLID=11)
mark = GETSTATE (win, 11)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
IF (@CONTROLID=10)
inputa$ = GETCONTROLTEXT (win,3)
inputb$ = GETCONTROLTEXT (win,4)
'you can use directly-clear control
SETCONTROLTEXT win,7,""
' calculate
result=val(inputa$)+val(inputb$)
'display
SETCONTROLTEXT win,7,str$(result)
ENDIF
ENDSELECT
RETURN
SUB add2number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swhide,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add2numberopen=1
RETURN
SUB add3number
LINE win,100,100,190,100
showwindow win, @swrestore,3
showwindow win, @swrestore,4
showwindow win, @swrestore,9
showwindow win, @swrestore,7
showwindow win, @swrestore,8
showwindow win, @swrestore,10
add3numberopen=1
RETURN
If you need more decimal places you must define variable result as FLOAT or DOUBLE.
And before you display result you can setprecision to 3 or more.
Yeah there is a way to jump to other edit control with TAB key but this only work in DIALOG type.
You must better read User Guide.
But maby this work also in WINDOW if you use API-s ,i realy dont know.
regards
aurel
Yes, as Aurel says, just put the statement:
Setprecision 3
somewhere early in your code, to get 3 decimal places.
Edit boxes are not very user friendly - Microsoft didn't provide them with any recognition of the Enter key - except in multi-line boxes, and that only inserts a carriage return to put you on the next line.
Of course, you can 'do-it-yourself' with a bit of code .. :)
DEF win:WINDOW
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
def left,top,width,height,textW,textH,focus as int
WINDOW win,0,0,600,400,0,0,"Test of Enter Key",mainwin
setwindowcolor win,rgb(0,20,50)
starttimer win,100,1
GETCLIENTSIZE win,left,top,width,height
' Edit Boxes ...
CONTROL win,"E,,120,50,80,25,@cteditcenter,1"
CONTROL win,"E,,400,50,80,25,@cteditcenter,4"
setcontrolcolor win,1,rgb(0,0,0),rgb(0,200,200)
setcontrolcolor win,4,rgb(0,0,0),rgb(0,200,200)
' Text Box ...
CONTROL win,"T,,(width-80)/2,150,80,25,@cteditcenter,2"
setcontrolcolor win,2,rgb(0,0,0),rgb(0,200,200)
SETFONT win,"Times New Roman",12,700,0,2
CONTROL win,"B,Exit,(width-50)/2,300,50,25,0,3"
SETFOCUS win,1
focus = 1: ' keep track of which edit box has the focus ...
SETFONT win, "Arial",10,500,0
a$ = "Enter some Text and press Enter ..."
GETTEXTSIZE win, a$, textW, textH
move win,(width- textW)/2,20
frontpen win, RGB(20,230,150)
PRINT win,a$
run = 1
WAITUNTIL run = 0
stoptimer win,1
CLOSEWINDOW win
END
SUB mainwin
SELECT @CLASS
CASE @IDCLOSEWINDOW
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
IF @NOTIFYCODE = @ensetfocus
setcontroltext win,1,""
focus = 1: ' acknowledge the focus in box 1 ...
ENDIF
CASE 3
run = 0
case 4
IF @NOTIFYCODE = @ensetfocus
setcontroltext win,4,""
focus = 4: ' acknowledge the focus in box 4 ...
ENDIF
endselect
case @idtimer
if Enter(13) <> 0
select focus
case 1
a$ = getcontroltext(win,1)
if ltrim$(a$) <> ""
setcontroltext win,1,""
setcontroltext win,2,a$
setfocus win,4
focus = 4
endif
case 4
a$ = getcontroltext(win,4)
if ltrim$(a$) <> ""
setcontroltext win,4,""
setcontroltext win,2,a$
setfocus win,1
focus = 1
endif
endselect
endif
ENDSELECT
RETURN
or just use an 'Enter' button wiht each box - a bit clumsy I know .. ::)
best wishes,
Graham
Thanks Aurel. this way is much more straightforward.
As far as the TAB key goes. The ENTER key is much better. Thank you the sample Graham.
It is very good code and many information and commands to learn. :)
Regards
Hobo
Graham,
I played around and modified your code to learn and understand. I hope you don’t mind? :)
But I can’t figure out why did you use STARTTIMER â€Ã,¦@IDTIMER? I know it is about sensing when the ENTER key pressed. Is there any other way to sense if any key pressed?
Hobo
DEF win:WINDOW
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
def focus:int
WINDOW win,0,0,600,400,0,0,"Test of Enter Key",mainwin
setwindowcolor win,rgb(0,20,50)
starttimer win,10,1
' Edit Boxes ...
CONTROL win,"E,,120,50,80,25,@cteditcenter,1"
CONTROL win,"E,,400,50,80,25,@cteditcenter,4"
setcontrolcolor win,1,rgb(0,0,0),rgb(0,200,200)
setcontrolcolor win,4,rgb(0,0,0),rgb(0,200,200)
' Text Box ...
CONTROL win,"T,,250,150,80,25,@cteditcenter,2"
setcontrolcolor win,2,rgb(0,0,0),rgb(0,200,200)
SETFONT win,"Times New Roman",12,700,0,2
CONTROL win,"B,Exit,265,300,50,25,0,3"
SETFOCUS win,1
focus = 1: ' keep track of which edit box has the focus ...
SETFONT win, "Arial",10,500,0
move win,200,20
frontpen win, RGB(20,230,150)
PRINT win,"Enter some Text and press Enter..."
run = 1
WAITUNTIL run = 0
stoptimer win,1
CLOSEWINDOW win
END
SUB mainwin
SELECT @CLASS
CASE @IDCLOSEWINDOW
run =0
CASE @IDTIMER
if Enter(13) <> 0
select focus
case 1
a$ = getcontroltext(win,1)
if (a$) <> ""
setcontroltext win,1,""
setcontroltext win,2,a$
setfocus win,4
focus = 4
endif
case 4
a$ = getcontroltext(win,4)
if (a$) <> ""
setcontroltext win,4,""
setcontroltext win,2,a$
setfocus win,1
focus = 1
endif
endselect
endif
CASE @idcontrol
IF (@CONTROLID=3)
run = 0
ENDIF
ENDSELECT
RETURN
I found a long thread about trapping the Enter key in the old Pyxia forum archive. I don't know how to grab it as a text file, so here's a long, skinny screenshot. Just zoom it up in your graphics viewer so you can read it.
Thanks. Every bit of info helps. :)
Hi guys...
I think that we forget read user guide.
I find in this big image, source code for hobo question how use button tab in window.
Simple with command ENABLETABS window|dialog,flag.
See code:
'Enter button traped for edit box in window with menu
def win:window
def run:int
def CurrentID:int
def ebox1$,ebox2$,ebox3$:string
def OK_ctr,Cancel_ctr,Close_ctr:int
'const BN_CLICKED = 0
'const BS_NOTIFY = &H4000
'const BN_SETFOCUS = 6
WINDOW win,0,0,450,250,@minbox,0,"Enter button traping",handler
SetWindowColor win,rgb(221,222,231)
Menu win,"T,&File,0,0","I,&Exit,0,1","I,&Exit2,0,2"
'1 enable tabing ,0 disable tab
Enabletabs win,1
'first edit control work only with numbers
control win,"E,,10,10,80,24,@tabstop|@cteditnumber,10"
setfont win,"MS Sans Serif",8,400,0,10
control win,"E,,110,10,80,24,@tabstop,20"
setfont win,"MS Sans Serif",8,400,0,20
control win,"E,,210,10,80,24,@tabstop,30"
setfont win,"MS Sans Serif",8,400,0,30
'if you need tabed buttons then must use constants------------------
'control win,"B,OK,23,55,70,20,@tabstop|0x50010000|BS_NOTIFY,40"
'control win,"B,Cancel,120,55,70,20,@tabstop|0x50010000|BS_NOTIFY,50"
'control win,"B,Close,70,90,70,20,@tabstop|0x50010000|BS_NOTIFY,60"
SETFOCUS win ,10
run=1
Waituntil run=0
closewindow win
end
SUB handler
Select @CLASS
case @idclosewindow
run=0
case @idcreate
centerwindow win
Endselect
return
I could swear that I have seen somewhere in the User Guide that TAB works only in Dialog and not in Window.
But anyway. Aurel's sample sure works. :)
Hobo
Quote from: Hobo on September 17, 2008, 05:48:58 PM
I could swear that I have seen somewhere in the User Guide that TAB works only in Dialog and not in Window.
I didn't look in the user's guide but that information is here: http://www.ionicwind.com/forums/index.php/topic,375.msg3191.html#msg3191
quoting:
Quote...And it is OK to have controls in a window, but you have to fight the nature of Windows to do it, such as doing your own tabbing between controls (which is why we have the EnableTabs method).
Using windows alone you can not tab between controls so Paul wrote a function (EnableTabs) to make it appear to tab the way dialog controls can.
Larry
Thanks mrainey for big picture ;D
I studded Graham’s earlier given code using ENTER and I tried to apply the same idea to my demo program and I can’t get it right.
The problem is once the ENTER key pressed it runs through the entire IF conditions. It won’t let me press the ENTER key after each EDITBOXES. My question is. Is there any way to reset the keyboard entry after each IF condition or should I use other commands instead of SETTIMEâ€Ã,¦@IDTIME?
Thanks,
Hobo
DECLARE "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
DEF win:WINDOW
DEF inputa$,inputb$,inputc$,result$:STRING
DEF focus:INT
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
SETPRECISION 3
CENTERWINDOW win
ENABLETABS win,1
STARTTIMER win,10,1
focus=2
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,@tabstop|@cteditright,2"
showwindow win, @swhide,2
CONTROL win,"E,inputY,120,65,70,20,@tabstop|@cteditright,3"
showwindow win, @swhide,3
CONTROL win,"E,output,120,115,70,20,@tabstop|@cteditright,4"
showwindow win, @swhide,4
CONTROL win,"T,Sum =,75,115,30,20,0,5"
showwindow win, @swhide,5
SETFONT win, "MS Sans Serif", 9, 400,0,5
SETCONTROLCOLOR win,5,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,6"
SETCONTROLCOLOR win,6,rgb(0,0,0),RGB(255,255,0)
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
IF @CONTROLID=1
addnumber()
ENDIF
IF (@CONTROLID=6)
mark = GETSTATE (win, 6)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
'This is the problem I don't understand. After pressing ENTER
'it runs through all the IF conditions.
CASE @IDTIMER
IF (Enter(13) <> 0) & (focus=2)
inputa$ = GETCONTROLTEXT (win,2)
SETFOCUS win,3
focus=3
sw1=0
ENDIF
IF (Enter(13) <> 0) & (focus=3)
inputb$ = GETCONTROLTEXT (win,3)
focus=4
ENDIF
IF (Enter(13) <> 0) & (focus=4)
result=VAL(inputa$)+VAL(inputb$)
SETCONTROLTEXT win,4,STR$(result)
ENDIF
ENDSELECT
RETURN
SUB addnumber
LINE win,100,100,190,100
showwindow win, @swrestore,2
showwindow win, @swrestore,3
showwindow win, @swrestore,4
SETCONTROLTEXT win,2,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETFOCUS win,2
focus=2
RETURN
Hobo,
Here's a program I wrote with IBasic Standard back in my beginner days (I'm now an "advanced beginner"). It uses a timer to trap the Enter key and works with multiple edit boxes. It doesn't use the Tab key. Maybe you can get some ideas from it.
Mike
It's doing what you are telling it to do.
Let's examine your code step by step:1 CASE @IDTIMER
2IF (Enter(13) <> 0) & (focus=2)
3 inputa$ = GETCONTROLTEXT (win,2)
4 SETFOCUS win,3
5 focus=3
6 sw1=0
7ENDIF
8IF (Enter(13) <> 0) & (focus=3)
9 inputb$ = GETCONTROLTEXT (win,3)
10 focus=4
11ENDIF
12IF (Enter(13) <> 0) & (focus=4)
13 result=VAL(inputa$)+VAL(inputb$)
14 SETCONTROLTEXT win,4,STR$(result)
15ENDIF
Each time the timer fires the handler is entered at step 1.
You have already set focus=2 and let's assume Enter(13)<> 0 is TRUE
At step 5 focus is set to 3.
So, when the if at step 8 is evaluated it is a true statement; Enter(13) <> 0 & focus=4
Step 10 sets focus=4
when the if at step 12 is evaluated it is a true statement; Enter(13) <> 0 & focus=4
so steps 13 and 14 are executed.
Like I said, it is doing exactly what you are telling it to do.
Larry
substitute this for what's in the timer portion: CASE @IDTIMER
IF (Enter(13) <> 0)
'clear the buffer
do:until Enter(13) = 0
select focus
case 2
inputa$ = GETCONTROLTEXT (win,2)
SETFOCUS win,3
focus=3
sw1=0
case 3
inputb$ = GETCONTROLTEXT (win,3)
focus=4
'case 4
result=VAL(inputa$)+VAL(inputb$)
SETCONTROLTEXT win,4,STR$(result)
endselect
ENDIF
This will fix the "fall through" problem.
But you've got a ways to go in order to be able to correct an entry without having to start over from scratch.
Larry
I play with my example and find solution with TAB key .Without starttimer.
I try with ENTER key but without success.
See code:
'TAB button traped for edit box in window with menu
def win:window
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
def run:int
def CurrentID:int
def ebox1$,ebox2$,ebox3$:string
def OK_ctr,Cancel_ctr,Close_ctr:int
const BN_CLICKED = 0
const BS_NOTIFY = &H4000
const BN_SETFOCUS = 6
WINDOW win,0,0,450,250,@minbox,0,"Enter button traping",handler
SetWindowColor win,rgb(221,222,231)
Menu win,"T,&File,0,0","I,&Exit,0,1","I,&Exit2,0,2"
'1 enable tabing ,0 disable tab
Enabletabs win,1
'starttimer win,100,1
control win,"E,,10,10,80,24,@tabstop,10"
setfont win,"MS Sans Serif",8,400,0,10
control win,"E,,110,10,80,24,@tabstop,20"
setfont win,"MS Sans Serif",8,400,0,20
control win,"E,,210,10,80,24,@tabstop,30"
setfont win,"MS Sans Serif",8,400,0,30
'if you need tabed buttons then must use constants------------------
control win,"B,OK,23,55,70,20,@tabstop|0x50010000|BS_NOTIFY,40"
control win,"B,Cancel,120,55,70,20,@tabstop|0x50010000|BS_NOTIFY,50"
control win,"B,Close,70,90,70,20,@tabstop|0x50010000|BS_NOTIFY,60"
SETFOCUS win ,10
run=1
Waituntil run=0
closewindow win
end
SUB handler
Select @CLASS
case @idclosewindow
run=0
case @idcreate
centerwindow win
case @idcontrol
select @controlid
case 10
if Enter(9) <> 0
if (@notifycode=@ensetfocus) then currentID=10
if (@notifycode=@enkillfocus)& (run=1) then lostfocus10()
endif
case 20
if Enter(9) <> 0
if (@notifycode=@ensetfocus) then currentID=20
if (@notifycode=@enkillfocus)& (run=1) then lostfocus20()
endif
endselect
' case @idchar
' if @code=0x0D
' messagebox win,"Enter pressed","No entry"
' endif
Endselect
RETURN
'-------------------------------------------------------------------
SUB lostfocus10
ebox1$=getcontroltext(win,10)
move win,220,55
print win," "
IF ebox1$ <> ""
move win,220,55
print win,"Ebox1: ",ebox1$
ELSE
messagebox win,"Edit box 1 is empty","No entry"
Endif
Return
'-------------------------------------------------------------------
SUB lostfocus20
ebox2$=getcontroltext(win,20)
move win,220,85
print win," "
IF ebox2$ <> ""
move win,220,85
print win,"Ebox2: ",ebox2$
ELSE
messagebox win,"Edit box 2 is empty","No entry"
Endif
Return
Mike, as a beginner you did very well. Nice piece of work. ;)
I found the timer part, but your program is so complex I am pretty much lost in it, but never the less I will study it. It helps that you used long and meaningful words for coding. Thanks to share it.
Also thank Larry for the tutoring and for the simple solution to fix my code.
I know it is not elegant code, but it is a start.
Hobo
Mike is not beginner ,he just joke :D
Are you try my example?
I think that next example work without starttimer.
You can enter numbers in edit1 then move caret with tab key.
Caret will be in edit2 and enter number in edit2 then press tab key again.
After this press enter and you give result in edit3.
If edit3 is not empty you can press tab key to next control wich is button.
Maby this example is not the best but work.
'TAB button traped for edit box in window with menu
def win:window
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
def run:int
def CurrentID:int
def ebox1$,ebox2$,ebox3$:string
def result:float
def OK_ctr,Cancel_ctr,Close_ctr:int
const BN_CLICKED = 0
const BS_NOTIFY = &H4000
const BN_SETFOCUS = 6
WINDOW win,0,0,450,250,@minbox,0,"Enter button traping",handler
SetWindowColor win,rgb(221,222,231)
Menu win,"T,&File,0,0","I,&Exit,0,1","I,&Exit2,0,2"
'1 enable tabing ,0 disable tab
Enabletabs win,1
'starttimer win,100,1
control win,"E,,10,10,80,24,@tabstop,10"
setfont win,"MS Sans Serif",8,400,0,10
control win,"E,,110,10,80,24,@tabstop,20"
setfont win,"MS Sans Serif",8,400,0,20
control win,"E,,210,10,80,24,@tabstop,30"
setfont win,"MS Sans Serif",8,400,0,30
'if you need tabed buttons then must use constants------------------
control win,"B,OK,23,55,70,20,@tabstop|0x50010000|BS_NOTIFY,40"
control win,"B,Cancel,120,55,70,20,@tabstop|0x50010000|BS_NOTIFY,50"
control win,"B,Close,70,90,70,20,@tabstop|0x50010000|BS_NOTIFY,60"
SETFOCUS win ,10
run=1
Waituntil run=0
closewindow win
end
SUB handler
Select @CLASS
case @idclosewindow
run=0
case @idcreate
centerwindow win
case @idcontrol
select @controlid
case 10
if Enter(9) <> 0
if (@notifycode=@ensetfocus) then currentID=10
if (@notifycode=@enkillfocus)& (run=1) then lostfocus10()
endif
case 20
if Enter(9) <> 0
if (@notifycode=@ensetfocus) then currentID=20
if (@notifycode=@enkillfocus)& (run=1) then lostfocus20()
endif
case 30
if Enter(9) <> 0
if (@notifycode=@ensetfocus) then currentID=30
if (@notifycode=@enkillfocus)& (run=1) then lostfocus30()
endif
endselect
'----------------------------------------------------------------
case @idkeydown
If (@code=0x0D)
setprecision 4
ebox1$ = getcontroltext(win,10)
ebox2$ = getcontroltext(win,20)
result=val(ebox1$)+val(ebox2$)
setcontroltext win,30,""
setcontroltext win,30,str$(result)
Enabletabs win,1
Endif
Endselect
RETURN
'-------------------------------------------------------------------
SUB lostfocus10
ebox1$=getcontroltext(win,10)
move win,220,55
print win," "
IF ebox1$ <> ""
move win,220,55
print win,"Ebox1: ",ebox1$
ELSE
messagebox win,"Edit box 1 is empty","No entry"
Endif
Return
'-------------------------------------------------------------------
SUB lostfocus20
ebox2$=getcontroltext(win,20)
move win,220,85
print win," "
IF ebox2$ <> ""
move win,220,85
print win,"Ebox2: ",ebox2$
ELSE
messagebox win,"Edit box 2 is empty","No entry"
Endif
Return
'-------------------------------------------------------------------
SUB lostfocus30
ebox3$=getcontroltext(win,30)
'move win,220,85
'print win," "
IF ebox3$ <> ""
messagebox win,"Edit box 3 is not empty","No empty"
Enabletabs win,1
setfocus win,40
ELSE
Enabletabs win,0
setfocus win
Endif
Return
Zlatko
I think he is wanting to use the ENTER key and not the TAB key.
Using the ENTER key allows everything to be done with the right hand ( the numeric keys and enter key are on the right side of the keyboard.
Using the TAB key requires using the left hand.
And using the ENTER key makes it work more like a calculator.
Larry
Mike’s program also formats the entered number. Like if I enter 10 the program formats to 10.0000. That is very neat. Also I noticed, he used @notifycode=@ensetfocus and so Graham.
This is so exiting. 8)
Yes, Zlatko’s sample works fine with TAB. No doubt about that, and I could use that for my program, but ENTER key is more natural and more elegant.
This is way beyond what I wanted to accomplish. ;D
Thanks to all
Hobo
I think this works as far as pressing ENTER key. I am sure it is crude, but works.
To make it neater I tied to use USING to format my input, but I could not make it to format my input variable to 3 decimal places. Any suggestion?
Anyway I am going to use this demo experiment to apply my â€Ã...“realâ€Ã, working project.
Thanks again
Hobo
Hi Hobo ....
What to say,very well for beginner ;)
You only forget define DEF result:FLOAT and your result will be with 3 decimal places.
zlatko
I thought I am done, but my program has a strange behavior and I have no idea why. :o
When I am in the middle of entering numbers into the EDITBOX and then I leave the program. In other words, I put it in sleep mode, or inactive position, to work with, for example MSWord, but any programs would do and then whenever I use ENTER key my program wakes up and response to the ENTER key input. It should not do that, should it?
Here is my sample program to show if somebody interested and could say something about it.
Cheers :)
Hobo
DECLARE "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
DEF win:WINDOW
DEF inputa$,inputb$,inputc$,result$:STRING
DEF focus:INT
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
SETPRECISION 3
CENTERWINDOW win
ENABLETABS win,1
STARTTIMER win,10,1
focus=2
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,@tabstop|@cteditright,2"
showwindow win, @swhide,2
CONTROL win,"E,inputY,120,65,70,20,@tabstop|@cteditright,3"
showwindow win, @swhide,3
CONTROL win,"E,output,120,115,70,20,@tabstop|@cteditright,4"
showwindow win, @swhide,4
CONTROL win,"T,Sum =,75,115,30,20,0,5"
showwindow win, @swhide,5
SETFONT win, "MS Sans Serif", 9, 400,0,5
SETCONTROLCOLOR win,5,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,6"
SETCONTROLCOLOR win,6,rgb(0,0,0),RGB(255,255,0)
CONTROL win,"T,Click to Stay on Top,20,180,150,20,0,12"
SETCONTROLCOLOR win,12,0,rgb(255,255,0)
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
IF @CONTROLID=1
addnumber()
ENDIF
IF (@CONTROLID=6)
mark = GETSTATE (win, 6)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
CASE @IDTIMER
IF (Enter(13) <> 0)
do:until Enter(13) = 0
add2numberoperation()
ENDIF
ENDSELECT
RETURN
SUB addnumber
LINE win,100,100,190,100
showwindow win, @swrestore,2
showwindow win, @swrestore,3
showwindow win, @swrestore,4
SETCONTROLTEXT win,2,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETFOCUS win,2
focus=2
RETURN
SUB add2numberoperation
select focus
case 2
inputa$ = GETCONTROLTEXT (win,2)
SETFOCUS win,3
focus=3
case 3
inputb$ = GETCONTROLTEXT (win,3)
result=VAL(inputa$)+VAL(inputb$)
SETCONTROLTEXT win,4,STR$(result)
SETFOCUS win,1
focus=4
case 4
SETCONTROLTEXT win,2,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETFOCUS win,2
focus=2
endselect
RETURN
Try this solution... Check that the foreground window is indeed the window from your own program.
Cheers!
DECLARE "user32",SetWindowPos(Hwnd:int,HwndAfter:int,x:int,y:int,cx:int,cy:int,flags:int)
DECLARE "user32",Enter alias GetAsyncKeyState(vKey:int),int
DECLARE "user32",GetForegroundWindow(),INT
DEF win:WINDOW
DEF inputa$,inputb$,inputc$,result$:STRING
DEF focus:INT
DEF MyWin:INT
WINDOW win,0,0,200,300,@MINBOX,0," CURVE Wiz",Handler
SETWINDOWCOLOR win,RGB(255,255,0)
SETPRECISION 3
CENTERWINDOW win
ENABLETABS win,1
STARTTIMER win,10,1
focus=2
'Draw Buttons'
CONTROL win,"B,Add2Num,5,5,60,20,0,1"
SETFONT win, "MS Sans Serif", 9, 400,0,1
'Add edit fields
CONTROL win,"E,inputX,120,40,70,20,@tabstop|@cteditright,2"
showwindow win, @swhide,2
CONTROL win,"E,inputY,120,65,70,20,@tabstop|@cteditright,3"
showwindow win, @swhide,3
CONTROL win,"E,output,120,115,70,20,@tabstop|@cteditright,4"
showwindow win, @swhide,4
CONTROL win,"T,Sum =,75,115,30,20,0,5"
showwindow win, @swhide,5
SETFONT win, "MS Sans Serif", 9, 400,0,5
SETCONTROLCOLOR win,5,0,rgb(255,255,0)
LINE win,100,100,190,100,RGB(255,255,0)
'Add Checkbox
CONTROL win,"C,,25,150,20,20,0x50000003,6"
SETCONTROLCOLOR win,6,rgb(0,0,0),RGB(255,255,0)
CONTROL win,"T,Click to Stay on Top,20,180,150,20,0,12"
SETCONTROLCOLOR win,12,0,rgb(255,255,0)
MyWin = win
run = 1
WAITUNTIL win=0
END
Handler:
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
CASE @IDCONTROL
IF @CONTROLID=1
addnumber()
ENDIF
IF (@CONTROLID=6)
mark = GETSTATE (win, 6)
IF mark =1
SetWindowPos(win,-1,0,0,0,0,2|1)
ELSE
SetWindowPos(win,-2,0,0,0,0,2|1)
ENDIF
ENDIF
CASE @IDTIMER
IF (Enter(13) <> 0) & (MyWin = GetForegroundWindow())
do:until Enter(13) = 0
add2numberoperation()
ENDIF
ENDSELECT
RETURN
SUB addnumber
LINE win,100,100,190,100
showwindow win, @swrestore,2
showwindow win, @swrestore,3
showwindow win, @swrestore,4
SETCONTROLTEXT win,2,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETFOCUS win,2
focus=2
RETURN
SUB add2numberoperation
select focus
case 2
inputa$ = GETCONTROLTEXT (win,2)
SETFOCUS win,3
focus=3
case 3
inputb$ = GETCONTROLTEXT (win,3)
result=VAL(inputa$)+VAL(inputb$)
SETCONTROLTEXT win,4,STR$(result)
SETFOCUS win,1
focus=4
case 4
SETCONTROLTEXT win,2,""
SETCONTROLTEXT win,3,""
SETCONTROLTEXT win,4,""
SETFOCUS win,2
focus=2
endselect
RETURN
Well done Johnny ;)
Wowâ€Ã,¦thank you Johnny. I was afraid nobody could help me at this time. It was elegant how you patched my code. You really made my day. Thanks again. :)
Regards,
Hobo
I got this idea. If you work in an office like me and notes, little scribbles with information written down on it, lay all around and when I need one of those I can’t find it. So why not make a little â€Ã...“NoteBarâ€Ã, that can pop up with a click and have all there?
So, I did exactly that, but I wonder if I could use string variables for the menu labels? So it would be more organized and not a â€Ã...“mileâ€Ã, long. And my other question. Is there a way to break a line and continue at the next line?
BTW, you can move the NoteBar by clicking just under the bar
Cheers,
Hobo
This example is weird for me.
First when i press menu item Length window close?
And where you find this and what is this? -
CASE @IDLbuttonDn
Select @HitWindow
Case Win
SendMessage Win,@WM_NCLButtonDown,@HTCaption,0
endselect
Like i see message is @WM_NCLButtonDown??
And what is purpose of :
CASE @IDCONTROL
STOPTIMER win,1
CLOSEWINDOW win
???
By the way Note program allready exists.
Try in attachment.
The note program you have sent me works and very nice. Thanks Aurel. :)
Yes, the menu items are not working yet. I have not made my mind how to do the rest.
The code â€Ã,¦
CASE @IDLbuttonDn
Select @HitWindow
Case Win
SendMessage Win,@WM_NCLButtonDown,@HTCaption,0
endselect
I found it in Michael Rainey’s â€Ã...“ME Weights 2.1â€Ã, program. I don’t fully understand either, but something to do moving the window. Once I used @NoCaption statement in my program, I was not able to move the window around the screen anymore. Adding this line of command allowed the program move again.
Errâ€Ã,¦maybe it is a silly idea after all.
Hobo
Yes hobo you right i forget.
Try this:
'part of mike program
def win:window
' DRAG WINDOW WITH NO TITLE BAR
SetID "WM_NCLButtonDown",161
SetID "HTCaption",2
Window win,0,0,400,300,@nocaption|@border,0,"no cap",main
CONTROL win,"B,CloseWin,225,7,70,20,0x50000000,1"
waituntil win=0
end
sub main
Select @class
case @idclosewindow
closewindow win
case @idcontrol
If @controlid=1
closewindow win
Endif
Case @IDLbuttondn
IF win
SendMessage Win,@WM_NCLButtonDown,@HTCaption,0
ENDIF
Endselect
return
Perfect...thanks :)
Hobo