New topic: Simple method to change from Boolean (chkbox values) to Y/N?
<http://forums.realsoftware.com/viewtopic.php?t=45861> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message tseyfarth Post subject: Simple method to change from Boolean (chkbox values) to Y/N?Posted: Fri Nov 09, 2012 9:02 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 732 Hello All, Has anyone fond/created a simple way to exchange the Boolean value of checkboxes, into Y/N or 0/1 responses? Normally, I would code as: VarA = "N" //or whatever the default should be If chkBox.Value = True Then VarA = "Y" However this requires 2 lines per checkbox. And I have a lot to do.... Ideas anyone. Thanks, Tim Top Thom McGrath Post subject: Re: Simple method to change from Boolean (chkbox values) to Posted: Fri Nov 09, 2012 10:18 pm Site Admin Joined: Tue May 06, 2008 1:07 pm Posts: 1250 Location: Greater Hartford Area, CT Write a function. Takes a Boolean and two responses, returns one of the responses based on the value of the Boolean. _________________ Thom McGrath - @tekcor Web Framework Architect, Real Software, Inc. Top tseyfarth Post subject: Re: Simple method to change from Boolean (chkbox values) to Posted: Fri Nov 09, 2012 11:10 pm Joined: Sat Dec 04, 2010 9:14 pm Posts: 732 Good idea Thom, Thanks for your response! Tim Top npalardy Post subject: Re: Simple method to change from Boolean (chkbox values) to Posted: Fri Nov 09, 2012 11:26 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7535 Location: Canada, Alberta, Near Red Deer tseyfarth wrote:Hello All, Has anyone fond/created a simple way to exchange the Boolean value of checkboxes, into Y/N or 0/1 responses? Normally, I would code as: VarA = "N" //or whatever the default should be If chkBox.Value = True Then VarA = "Y" However this requires 2 lines per checkbox. And I have a lot to do.... Ideas anyone. Thanks, Tim An extension method for checkboxes that lets you grab it as Y or N would be plausible as well. _________________ My web site Great White Software RBLibrary.com REALbasic learning Top doofus Post subject: Re: Simple method to change from Boolean (chkbox values) to Posted: Fri Nov 09, 2012 11:28 pm Joined: Thu Sep 10, 2009 2:50 am Posts: 299 Location: Santa Cruz, CA, USA Here's some one liner possibilities dim VarA As String if chkBox.Value then VarA = "Y" else VarA = "N" //inline VarA = boolToStr(chkBox.Value) //regular method VarA = chkBox.Value.toStr //extension method //================================= //regular method Function boolToStr(b As Boolean) As String if b then return "Y" return "N" End Function //extension method (must be in a Module) Function toStr(extends b As Boolean) As String if b then return "Y" return "N" End Function Top shaosean Post subject: Re: Simple method to change from Boolean (chkbox values) to Posted: Sat Nov 10, 2012 12:46 am Joined: Mon Aug 15, 2011 10:25 pm Posts: 217 or make a sub-class and over-ride the Value property _________________ Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7 Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
