I thought this little bit of magic was worth reviewing .. :)
If you've ever tried it, you will know that pressing the Enter key, while an Edit Control has the focus, will not process whatever you have typed into it. ::) Microsoft never saw fit to generate a message for this common user action - all you get is an 'error' beep.
Unbelievable :o. Note IWB has a specially included statement SETCONTROLNOTIFY to provide a way to detect the Enter key. Unfortunately, this is not available in Creative.
So the easiest way round this, is to have a dedicated button in your program to process whatever you've typed into the Edit control. It's foolproof, but a bit clunky. ;D
I'm working on a program where the usual way of just pressing Enter should process the data without any fuss and extra buttons. :P
So that's where this magic method comes in. Goodness knows how it works, but it does.
It seems that although Windows does not generate a message from an Edit control when the Enter key is pressed, it does send a message via the Menu system - whether you have a menu in your Window or not.
This message can be intercepted using the @IDMenuPick message, and acting on an if (@code = @IDOK) statement.
As a bonus, you can also use if (@code = @IDCancel) then run = 0 to exit the program using the ESCape key.
The following test program show how it works .. note that one other statement enabletabs w,1 is required once you've initialised the window w.
' Press Enter in an Edit Control - GWS 2015
wstyle = @minbox
' open a window ..
window w,-600,0,600,400,wstyle,0,"Creative Basic",messages
enabletabs w,1 :' ************ Needed to capture the Enter keypress
run = 1
WAITUNTIL run = 0
' this section captures the Enter Key
' has the Enter key been pressed ..
if (@code = @IDOK)
' process the Edit control data ..
a$ = getcontroltext(w,2)
print w,"You entered :"
' check for ESC key to exit ..
if (@code = @IDCancel) then run = 0
run = 0
run = 0
if (@notifycode = @ENSETFOCUS) then setcontroltext w,2,""
It seems to work fine in XP - whether it works in later versions of Windows I do not know. I'd be interested if anyone tries it out.
Best wishes, :)
Thanks for sharing Graham!
Tried your code on Win7Pro. Worked like a dream.
I had the same problem with ENTER in a RichEdit Control some time ago. Several methods were tried, but not all of them worked equally well, so finally ended up copying a method from the old IB Std days.
Don't remember if this ever was posted on this forum, so here it is:
My grandson just arrived, and we tried your code on his laptop running Win 8.1, loading the free version of CB from a USB memory stick.
That's good to know - it seems to be solid across all the Window's versions then.
It's a bit weird, but only uses a couple of standard CBasic instructions, so it's pretty good.
Some other methods I've tried needed API routines and timers - a bit of overkill really.
I nearly bought an old Trio TS520, sold as 'not working' on Ebay - just for a project - but it went up to over Â£150 in auction. I thought that was excessive for a load of electronic scrap, so I didn't bid in the end .. ::)
All the best, :)
A "not working" TS-520 is not worth many pounds...
It was a nice rig when it first were introduced back in the stone age, but today you get newer, and working, rigs for much less than Â£150.
Ebay auctions sometimes work in strange ways. I have seen used electronics sold there for much higher prices than what the equipment was sold for when it was brand new.
Must be something happening to peoples brains when they are bidding. I just don't understand it.
Thanks for your Short Dipole example Egil ;D
You're very busy creating these interesting and useful amateur radio examples.
The 'short dipole' just about halves the length, from over 20m to 10m. Probably with the tee joint at the co-ax fairly high (maybe a V- formation), you would get about 5 metres of wire running at high current in the centre, and a bit off the ends. Should be quite a decent signal.
Don't know if you've tried one - just wondering about bandwidth .. :) I would guess about 100KHz at that frequency :)
Couldn't see a RE (rich edit) control in the program though - maybe it was another program you were thinking of ..
Best wishes, :)
It was tested by myself on 40 and 20. In an inverted-V configuration with the top 12 meters up, SWR was below 2:1 over a bandwidth of 120 kHz on 40m, and around 200 kHz on 20 meters.
Others have tested it, and reported 40 kHz on 80m. With a good antenna tuner it should be possible to press the antenna into good service over the entire bands.
The idea for this calculator was found in a small book by John Heys
) called "Practical Wire Antennas
He states that the dipoles can be cut to half size, if an inductor with appproximately 950 ohms reactance is inserted exactly in the middle of each leg.
When I built one for 80 meters using the dimensions given in his book, it worked so good that I decided to make this calculator.
The inductance given in the drawing, is the value corresponding to 950 ohms. But to simplify calculations, I found that quarter turn resolution for the coil windings was more than good enough for practical work.
So, if you inspect my code, you'll find that the code add a quarter turn to the coil and calculates the reactance, and repeat this until the reactance passes 950 ohms.
Comparisons showed that the half size loaded dipole produced a signal only 4dB lower than a full size inverted-V dipole fed at the same height. This is less than 1 "S"! And during normal band conditions this is barely noticeable.
I just love projects like this!
QuoteCouldn't see a RE (rich edit) control in the program though - maybe it was another program you were thinking of ..
The very last part of the program is setting up the two RE-controls. But I did not like the appearance of them, so I gave them a "fake Edit Control look".... 8) 8)