New topic: "Get X whose Y is Z"
<http://forums.realsoftware.com/viewtopic.php?t=30586> Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message motorollin Post subject: "Get X whose Y is Z"Posted: Wed Oct 21, 2009 1:10 pm Joined: Mon Jun 16, 2008 4:53 pm Posts: 30 I need a function which will take an array of any class as one argument (x), any property of that class as another argument (y) and the value to check as the final argument (z), and return the x whose y matches z. Here's a non-working illustration. The "SOMETHING"s are datatypes I am unable to work out for the arguments to GetXWhoseYIsZ. I don't know whether this type of thing is even possible. I know I could do this with several different functions, but this is not entirely appropriate within the context of the app I'm working on. Code: Sub App.Open Dim f() As MyFoo Dim b() As MyBar f.Append(new MyFoo) f.Append(new MyFoo) f(0).Name = "Foo #1" f(1).Name = "Foo #2" b.Append(new MyBar) b.Append(new MyBar) b(0).Name = "Bar #1" b(1).Name = "Bar #2" Dim OneFoo As MyFoo Dim OneBar As MyBar OneFoo = GetXWhoseYIsZ(f, f.Name, "Foo #1") //OneFoo is now equal to the item in f whose name is "Foo #1", i.e. f(0) OneBar = GetXWhoseYIsZ(b, b.Name, "Bar #2") //OneBar is now equal to the item in b whose name is "Bar #2", i.e. b(1) End Sub GetXWhoseYIsZ(x as SOMETHING, y as SOMETHING, z as String) Dim i as Integer For i = 0 To x.Ubound If x.y = z Then Return x Next End Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 1 post ] -- 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]
