1. Message for Greg Haberek :
- Posted by Ed Wall <edwall6634 at msn.com> Aug 12, 2005
- 516 views
Hey Greg, I'm working on another little program that converts original gravity readings and final gravity readings to alcohol content by weight and alcohol content by volume. It works, and I used a lot of code that you previously taught me. I have a problem though. I'm using two editText boxes with this program instead of one like in the other. My intent is to write a progam that will run other programs while still running the main program, but that we will have to get to when the time comes. Question: (actually I have alot of questions for you, but I don't want to push my luck, or burdon you with a bunch of things at one time.) How do I place the cursor in the editText box when I open the program, so I don't have to click in it to put it there. And, how do I send the cursor to the second editText box without clicking on it. I was also wanting to put a convert button in this program, but I don't understand how to make it work within the procedure in the program that i've written. Do you think this progam is too long? If so how should I shorten it? Feel free to make any corrections that you see fit. I want to learn Euphoria like you know it, but remember that i'm just scratching on the surface. My programming experience has been with Cobal, GW-Basic, Quick Basic and VAX Basic. I know MS-Dos good enough to do a few things, if I haven't forgot, and i've tried to learn Windows and as many applications as I could. Like Word, Excell and Powerpoint. I found Euphoria by accident, and I love it. It's just what I was looking for, now I need to learn how to use it, and I want to learn how to use it correctly. Here's the program: -- This program calculates the percentage of alcohol by weight and the percentage of -- alcohol by volume of wine, mead or beer. Specific Gravity measurements for O.G. -- (original gravity) must be taken from the must or wort using a hydrometer and -- documented, then measurments of F.G. (final gravity) must be taken from the fermented -- wine, mead or beer and documented in order to calculater the percentage of alcohol of by -- weight or volume of your racked and/or finished fine home-made brew! -- Program Name: peralc.exw -- Author: Swain Wall -- Date : August 11, 2005 -- Include library routine(s). include win32lib.ew -- Exclude warning. without warning with trace -- Declare sequence(s). sequence AllowedCharacters -- Define sequence(s). AllowedCharacters = ".0123456789" -- Declare/Define constant(s). constant -- Create MainWindow. MainWindow = create(Window, "Calculate Percentage of Alcohol", 0, Center, Center, 0.5, 0.5, 0), -- Create MainWindow Entry(s) Heading(s). OGHead = create(LText, "Original Gravity Reading", MainWindow, 35, 20, 142, 20, 0), FGead = create(LText, "Final Gravity Reading" , MainWindow, 35, 65, 172, 20, 0), -- Create MainWindow Original Gravity input window. OG = create(EditText, "" , MainWindow, 69, 40, 40, 20, 0), FG = create(EditText, "" , MainWindow, 69, 85, 40, 20, 0), -- Create MainWindow O.G., S.G. or F.G Entry list(s). OGEntry = create(LText, "" , MainWindow, 278, 40, 85, 20, 0), FGEntry = create(LText, "" , MainWindow, 278, 80, 85, 20, 0), -- Create MainWindow Alcohol by Volume Entry. ABWAnswer = create(LText, "" , MainWindow, 25, 140, 210, 20, 0), ABVAnswer = create(LText, "" , MainWindow, 25, 160, 210, 20, 0), -- Create MainWindow Button(s). ClearButton = create(Button, "Clear" , MainWindow, 340, 160, 40, 20, 0), ExitButton = create(Button, "Exit" , MainWindow, 340, 220, 40, 20, 0), -- Create MainWindow Statis Bar. SB = createEx(StatusBar, "Enter Original Gravity Reading...", MainWindow, 0, 0, 0, 0, 0, WS_EX_STATICEDGE) --------------------------------------------------------------------------- procedure onOpen_MainWindow(integer self, integer event, sequence params) --------------------------------------------------------------------------- VOID = sendMessage(OG, EM_LIMITTEXT, 5, 0) VOID = sendMessage(FG, EM_LIMITTEXT, 5, 0) end procedure --------------------------------------------------------------------------- procedure calc_alc() --------------------------------------------------------------------------- -- Declare variable(s). atom ogr, fgr sequence ABW, ABV -- Convert O.G and F.G to Alcohol by Weight. -- Formula: ABW = (O.G-F.G)105. ogr = getNumber(OG) fgr = getNumber(FG) ABW = sprintf("The Alcohol Content by Weight is %1.2f %%", (ogr-fgr)*105) setText(ABWAnswer, ABW) -- Convert Alcohol by Weight to Alcohol by Volume. -- Formula: ABV = (ABW)(1.25) ABV = sprintf("The Alcohol content by Volume is %1.2f %%", ((ogr-fgr)*105)*1.25) setText(ABVAnswer, ABV) setText(SB, "Converted...") end procedure --------------------------------------------------------------------------- procedure onKey_OG(integer self, integer event, sequence params) --------------------------------------------------------------------------- -- Declare/Define variables(s). atom og sequence ognumber integer key, shift key = params[1] shift = params[2] -- Check for Enter Key Pressed. if key = VK_ENTER then og = getNumber(OG) if equal(0, og) then setText(SB, "Original Gravity Must Be Entered...") sleep(2) setText(SB, "Enter Original Gravity Reading..." ) return else ognumber = sprintf("O.G. = %1.3f", og) setText(OGEntry, ognumber) setText(SB , "Enter Final Gravity Reading...") end if else -- Check for illegal character(s) entered into edit box. if not find(key, AllowedCharacters) then returnValue(-1) -- Disallow keypress setText(SB, "Numbers and decimal point only...") sleep(2) setText(SB, "Enter Original Gravity Reading...") return end if end if end procedure --------------------------------------------------------------------------- procedure onKey_FG(integer self, integer event, sequence params) --------------------------------------------------------------------------- -- Declare/Define variable(s). atom fg, og sequence fgnumber, ogCheck integer key, shift key = params[1] shift = params[2] -- Check for Enter Key Pressed. if key = VK_ENTER then fg = getNumber(FG) og = getNumber(OG) if fg > og then setText(SB, "F.G. Can't be Greater than O.G...") sleep(2) setText(FG, "") setText(SB, "Enter Final Gravity Reading and Press Enter...") return else ogCheck = getText(OGEntry) if equal("", ogCheck) then ogCheck = sprintf("O.G. = %1.3f", og) setText(OGEntry, ogCheck) end if fgnumber = sprintf("F.G. = %1.3f", fg) setText(FGEntry, fgnumber) calc_alc() end if else -- Check for illegal character(s) entered into edit box. if not find(key, AllowedCharacters) then returnValue(-1) -- Disallow keypress setText(SB, "Numbers and decimal point only...") sleep(2) setText(SB, "Enter Final Gravity Reading and Press Enter...") return end if end if end procedure --------------------------------------------------------------------------- procedure onClick_Clear(integer self, integer event, sequence params) --------------------------------------------------------------------------- -- Clear Entries from editText Box(s) and Entry list(s). setText(OG , "" ) setText(OGEntry , "" ) setText(FG , "" ) setText(FGEntry , "" ) setText(ABWAnswer, "" ) setText(ABVAnswer, "" ) setText(SB , "Enter Original Gravity Reading") end procedure --------------------------------------------------------------------------- procedure onClick_Exit(integer self, integer event, sequence params) --------------------------------------------------------------------------- -- Exit Program. closeWindow(MainWindow) end procedure -- Handle routine(s). setHandler(MainWindow , w32HOpen , routine_id("onOpen_MainWindow")) setHandler(OG , w32HKeyPress, routine_id("onKey_OG" )) setHandler(FG , w32HKeyPress, routine_id("onKey_FG" )) setHandler(ClearButton, w32HClick , routine_id("onClick_Clear" )) setHandler(ExitButton , w32HClick , routine_id("onClick_Exit" )) -- Give control to windows. WinMain(MainWindow, Normal) -- End Program. Thank You for your help, Bill
2. Re: Message for Greg Haberek :
- Posted by Greg Haberek <ghaberek at gmail.com> Aug 12, 2005
- 490 views
> I'm working on another little program that converts original gravity read= ings > and final gravity readings to alcohol content by weight and alcohol conte= nt > by volume. It works, and I used a lot of code that you previously taught = me. > I have a problem though. I'm using two editText boxes with this program > instead of one like in the other. My intent is to write a progam that wil= l > run other programs while still running the main program, but that we will > have to get to when the time comes. > Question: (actually I have alot of questions for you, but I don't want to > push my luck, or burdon you with a bunch of things at one time.= ) E-mail me privately at ghaberek at gmail.com and I will feel free to go through them all and answer them. I'm not the ultimate Win32Lib guru, Derek obviously is, but I've been using it since the days when David Cuny still ran the project, so I've got quite a bit of user experience, rather than author experience with it. > How do I place the cursor in the editText box when I open the program, so= I > don't have to click in it to put it there. And, how do I send the cursor = to > the second editText box without clicking on it. I was also wanting to put= a > convert button in this program, but I don't understand how to make it wor= k > within the procedure in the program that i've written. Do you think this > progam is too long? If so how should I shorten it? Feel free to make any > corrections that you see fit. I'm at work right now, just wasting time on a computer. I don't have Euphoria on me, so I'll have to make this quick and cheap.
-- auto-focus example procedure MyWin_onActivate( integer self, integer event, sequence params ) -- onActivate happens *after* the window becomes visible, -- as opposed to onOpen, which happens *before* -- set foucs to our first text control setFocus( MyTextCtrl01 ) end procedure setHandler( MyWin, w32HActivate, routine_id("MyWin_onActivate") ) -- auto-tab example procedure MyTextCtrl01_onKeyPress( integer self, integer event, sequence params ) -- this causes focus to go from MyTextCtrl01 to -- MyTextCtrl02 when the user presses the Enter key -- -- there are more involved ways of doing auto-tabbing, -- but for only two text fields, this will work just fine integer keyCode, shift keyCode = params[1] shift = params[2] if keyCode = VK_ENTER then -- user pressed Enter key, go to next field setFocus( MyTextCtrl02 ) end if end procedure setHandler( MyTextCtrl01, w32HKeyPress, routine_id("MyTextCtrl01_onKeyPress= ") )
> I want to learn Euphoria like you know it, but remember that i'm just > scratching on the surface. My programming experience has been with Cobal, > GW-Basic, Quick Basic and VAX Basic. I know MS-Dos good enough to do a fe= w > things, if I haven't forgot, and i've tried to learn Windows and as many > applications as I could. Like Word, Excell and Powerpoint. I found Euphor= ia > by accident, and I love it. It's just what I was looking for, now I need = to > learn how to use it, and I want to learn how to use it correctly. I'll look at your program more tomorrow. I've been working since 7:00 AM and now its 11:00 PM, so when I get home, I'm gonna sleep.... a lot. One tip I can't stress enough is variable/constant names. If you get in a good habit early on, it will really make life easier in the future. OG and FG aren't the best names for controls. Here's a fairly generalized version of Derek's notation used in Win32Lib: control IDs: CapitalLetterForEachWord routines: lowerCaseFirst() constants: kMyConstant (start with lower-case K) global variables: vMyVarName (start with lower-case V) local variables (in routines): lMyVarName (start with lower-case L) routine parameters: pParamName (start with lower-case P) Using brief, yet descriptive names will help people like me, who are reading your code, to easier understand what's going on. Just opening up win32lib.ew and poking around, you'll see how Derek uses that notation. IMHO, it works well, so I've adopted it into my programming. Obviously, choose what works best for you. ~Greg
3. Re: Message for Greg Haberek :
- Posted by Ed Wall <edwall6634 at msn.com> Aug 12, 2005
- 471 views
Obviously, choose what works best for you. ~Greg Me too! Hope you get a good nights sleep, and have good dreams. I'll give it a try. Looking through win32lib.ew is like looking through a spanish book. I understand a little, but the rest is "Greek" to me. I try to sort out what I am trying to ask you, and I will try to put it together as best I can. You can expect an e-mail, at my liberty. P.S. Take a day off and go fishing. You don't have to fish, but just being in the out doors and listening to the sounds of nature helps me find a little peace and releases a lot of stress. My father was an aerospace "Physics Major " engineer, (N.O.R.A.D., NASA) and he eventually built up a lot of ....... crap. My brother is an administrator and wants to get his masters, info is like squeezing blood from a turnip with him. I'm glad I don't have a stressfull J.O.B. I'll keep in touch. Relax! Have a home brew! Thank you, Bill