HELP! I'm stupid.... novice "wanna be" or trying to be...
- Posted by Ed Wall <edwall6634 at msn.com> Aug 09, 2005
- 597 views
Programmer. I'm also into making wine and mead. I'm trying to write a very simple program to convert the cc's of sodium hydroxide used to the % of tartaric acid and the parts per thousand of sulfuric acid. But, I don't know what i'm doing. I just play with computers. Can some one help me solve this problem? The problem is that, besides a few bugs that need to be worked out, "I can do it!", I don't know how to multiply the information in the editText box with the other part of the formula. By viewing the code i'm sure that someone will either say i'm a complete idiot, or think that i'm doing ok for a newbee and help me with the simplist solution to this problem. Here's the code: I think the problem is in the procedure convert_CCSHTS(), i guess? I'm sure there could be a simpler code to write this program, it's just that I don't know it. Can anyone recommend a good book on this type of programming that I could get to help me become a better programmer? Any help will be much appreciated. Thank you. Peace, Bill -- This program computes tartaric and sulfuric acid contents of wine or mead must. -- Author: Swain Wall -- Date: August 4, 2005 -- Include library routine(s). include win32lib.ew -- Exclude warning. without warning with trace -- Declare integer(s). global integer counter -- Define integer(s). counter = 0 -- Declare sequence(s). sequence AllowedCharacters, checkCCSH -- Define sequence(s). AllowedCharacters = {46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57} -- Declare atom(s). atom top, left, height, width --Define atom(s). -- Set the size to one half of the screen's size. width = 0.5 height = 0.5 -- Set the top-lefthand corner so that the window is centered in the screen. top = (1 - height) / 2 left = (1 - width) / 2 -- Declare/Define constant(s). constant sulfuric = 1.6, tartaric = .25, -- Create MainWindow. MainWindow = create(Window, "Tartaric/Sulfuric Acid Conversion Program", 0, left, top, width, height, 0), -- Create MainWindow List(s) Heading(s). CCSHHead = create(LText, "CC's Sodium Hydroxide Used" , MainWindow, 25, 20, 150, 20, 0), PTAHead = create(LText, "Percentage of Tartaric Acid", MainWindow, 235, 20, 150, 20, 0), PPTSAHead = create(LText, "(PPT) of Sulfuric Acid" , MainWindow, 235, 80, 200, 20, 0), -- Create MainWindow Tartaric Acid input window. CCSH = create(EditText, "", MainWindow, 69, 40, 40, 20, 0), -- Create MainWindow List(s). PTAAnswer = create(LText, "" , MainWindow, 278, 40, 40, 20, 0), PPTSAAnswer = create(LText, "" , MainWindow, 278, 100, 40, 20, 0), -- Create MainWindow Acid Level Chart Heading(s). TW = create(LText, "Type of Wine", MainWindow, 25, 120, 80, 20, 0), PT = create(LText, "% Tartaric" , MainWindow, 120, 120, 80, 20, 0), PPTS = create(LText, "ppt Sulfuric", MainWindow, 200, 120, 80, 20, 0), -- Create MainWindow Acid Level Type of Wine index(s). wg = create(LText, "white grapes", MainWindow, 25, 140, 80, 20, 0), rg = create(LText, "red grapes" , MainWindow, 29, 160, 80, 20, 0), f = create(LText, "fruits" , MainWindow, 41, 180, 80, 20, 0), -- Create MainWindow Acid Level % Tartaric index(s). wgT = create(LText, ".65 - .75" , MainWindow, 122, 140, 80, 20, 0), rgT = create(LText, ".60 - .65" , MainWindow, 122, 160, 80, 20, 0), fT = create(LText, ".55 - .65" , MainWindow, 122, 180, 80, 20, 0), -- Create MainWindow Acid Level ppt Sulfuric index(s). wgS = create(LText, "4.2 - 4.9" , MainWindow, 206, 140, 80, 20, 0), rgS = create(LText, "3.9 - 4.2" , MainWindow, 206, 160, 80, 20, 0), fS = create(LText, "3.6 - 4.2" , MainWindow, 206, 180, 80, 20, 0), -- Create MainWindow Typical Acid Level Statement. TALS = create(LText, "Typical Acidity is 0.6% Tartaric or 4 ppt Sulfuric", MainWindow, 25, 200, 250, 20, 0), -- Create MainWindow Button(s). CTSA = create(Button, "Convert" , MainWindow, 165, 40, 60, 20, 0), 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, "Ready", MainWindow, 0, 0, 0, 0, 0, WS_EX_STATICEDGE) ---------------------------------------------------------------------- procedure onOpen_MainWindow() ---------------------------------------------------------------------- integer i i = sendMessage(CCSH, EM_LIMITTEXT, 3, 0) -- max 3 char. using EM_LIMITTEXT. end procedure ---------------------------------------------------------------------- procedure check_CCSH() ---------------------------------------------------------------------- -- Check for illegal character(s) entered. checkCCSH = getText(CCSH) for j = 1 to length(checkCCSH) do for k = 1 to length(AllowedCharacters) do if equal(checkCCSH[j], AllowedCharacters[k]) then counter = counter + 1 end if end for end for end procedure ---------------------------------------------------------------------- procedure convert_CCSHTS() ---------------------------------------------------------------------- -- If legal character(s) entered, then -- Convert CC's Sodium Hydroxide to precentage of Tartaric and ppt Sulfuric Acid. if counter = 3 then setText(PTAAnswer , getText(CCSH)) -- This is where I need to multiply tartaric -- setText(PTAAnswer, getText(C) * tartaric)) I tried this... -- setText(PTAAnswer, sprintf("%d", getText(C) * tartaric)) -- I tried this too setText(PPTSAAnswer, getText(CCSH)) -- This is where I need to multiply sulfuric setText(SB ,"Converted...") counter = 0 else -- Send user note to status bar, clear invalid entries and reset status bar. setText(SB, "Illegal Character(s) Entered") sleep(2) setText(CCSH, "") setText(SB , "Ready") counter = 0 end if end procedure ---------------------------------------------------------------------- procedure onKey_Convert(integer key, integer shift) ---------------------------------------------------------------------- -- Check for Enter Key Pressed. if key = 13 then -- Check for illegal character(s) entered into edit box. check_CCSH() -- Convert CCSH to Tataric/Sulfuric. convert_CCSHTS() end if end procedure ----------------------------------------------------------------------- procedure onClick_Convert() ----------------------------------------------------------------------- -- Check for illegal character(s) entered into edit box. check_CCSH() -- Convert CCSH to Tataric/Sulfuric. convert_CCSHTS() end procedure ----------------------------------------------------------------------- procedure onClick_Clear() ----------------------------------------------------------------------- -- Clear CCSH box, PTAAnswer and PPTSAAnswer. setText(CCSH , "") setText(PTAAnswer , "") setText(PPTSAAnswer, "") setText(SB , "Ready") end procedure closeWindow(MainWindow) end procedure -- Handle routine(s). onOpen[MainWindow] = routine_id("onOpen_MainWindow") onKeyPress[CCSH] = routine_id("onKey_Convert" ) onClick[CTSA] = routine_id("onClick_Convert" ) onClick[ClearButton] = routine_id("onClick_Clear" ) onClick[ExitButton] = routine_id("onClick_Exit" ) -- Give control to windows. WinMain(MainWindow, Normal) -- End Program.