Iamdan Posted June 7, 2007 Share Posted June 7, 2007 Fixed the first problem now I just have this question: Also, how would I go about separating characters in an edit box? The user inputs a sentence, and I need to assign each letter to a variable as a number, so I can output that sentence but using a simple encryption I will change the letters so it is x letters forward or backward. EG: 'hello' 3 letters forward will become 'jhoor', 'jhoor' 3 letters backward will be 'hello'. I have a scrollbar that I use to set the variable 'key' and will just add 'key' to each letter, then add an if statement 'if it is over 26, then take away 26.' (old post)>>This is in Delphi 7SE if encoderadiobtn.Checked = true then encode; if decoderadiobtn.Checked = true then decode; if encoderadiobtn.Checked = false and decoderadiobtn.Checked = false then MessageDlg('Please choose encode or decode' , mtError, [mbOk], 0,); It is part of a start button procedure It compiles and runs fine, except when I click start with them both unchecked the error doesn't come up when it should, encode runs the procedure and the message, (it should just run the procedure) and decode runs the procedure like it should. What I want it to do, is display the message if none are checked, run the encode procedure if it is checked, and the decode procedure if it is checked. I am sure this is something really stupid that I overlooked, but I have been trying to get this simple thing to work for about 20 minutes. Can anybody tell me what I am doing wrong? Link to comment Share on other sites More sharing options...
Looce Posted June 11, 2007 Share Posted June 11, 2007 You might want to make one of the two radio buttons checked at design time. Set the Checked property of, say, EncodeRadioBtn, to True, then you can remove your last IF entirely. Alternatively, try this: if (not EncodeRadioBtn.Checked) and (not DecodeRadioBtn.Checked) then MessageDlg('Please choose Encode or Decode.', mtError, [mbOk], 0) else if EncodeRadioBtn.Checked then Encode else Decode; { other code here } IF/ELSE IF/ELSE allows you to decide one action to execute according to the first condition that is met, then jump to the {other code here}. This would eliminate your code path problem. P.S. It seems to me that you retyped the code into this thread and didn't copy-paste. The MessageDlg line does not compile. Your current code seems to be: if encoderadiobtn.Checked = true then encode; if decoderadiobtn.Checked = true then decode; if encoderadiobtn.Checked = true and decoderadiobtn.Checked = false then MessageDlg('Please choose encode or decode' , mtError, [mbOk], 0,); { Syntax error: Expression expected before ) } Link to comment Share on other sites More sharing options...
Iamdan Posted June 11, 2007 Author Share Posted June 11, 2007 You might want to make one of the two radio buttons checked at design time. Set the Checked property of, say, EncodeRadioBtn, to True, then you can remove your last IF entirely. I got it to work just by putting encoderadiobtn.checked = true etc in brackets, but that is much better. Also, how would I go about separating characters in an edit box? The user inputs a sentence, and I need to assign each letter to a variable as a number, so I can output that sentence but using a simple encryption I will change the letters so it is x letters forward or backward. EG: 'hello' 3 letters forward will become 'jhoor', 'jhoor' 3 letters backward will be 'hello'. I have a scrollbar that I use to set the variable 'key' and will just add 'key' to each letter, then add an if statement 'if it is over 26, then take away 26.' BTW I did copy and paste the code in, some versions of delphi have slightly different syntax than others. What I have written compiled fine with delphi 7SE, but if I wanted to compile it with delphi 5 then i would have to change it to if encoderadiobtn.Checked := true then encode; It doesn't compile without that colon. Link to comment Share on other sites More sharing options...
mastermule52 Posted June 11, 2007 Share Posted June 11, 2007 you can eliminate your "if greater than 26 then take away 26" line by going like this, if you so desire ... although i don't know the syntax of the language you're using function encrypt(char c) let x = getNumberFromLetter© // if c = 'a' then x = 1 x += key; return getLetterFromNumber( mod(x,26) ) // if input = 5, returns 'e' end function http://en.wikipedia.org/wiki/Modulo_operation =) The refuge that you built to flee that places that you've come to fear the most ... is the place that you have come to fear the most.Operator - http://www.heartunit.orgCouncil - http://z8.invisionfree.com/skillazModerator - http://forum.meebo.com Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now