New topic: Is it even possible to do this?
<http://forums.realsoftware.com/viewtopic.php?t=47847> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message timehacker11 Post subject: Is it even possible to do this?Posted: Sat May 11, 2013 12:43 am Joined: Sat Apr 20, 2013 7:41 pm Posts: 31 If ListBox1.SelectedItem.ToString.Contains("szs") Then MsgBox("You've selected a SZS File!") ElseIf ListBox1.SelectedItem.ToString.Contains("brres") Then MsgBox("You've selected a BRRES file!") Else MsgBox("Boo! No Nintendo files selected!") End If I am assuming it isn't possible like a lot of things aren't but are in single platform languages Top taylor-design Post subject: Re: Is it even possible to do this?Posted: Sat May 11, 2013 1:59 am Joined: Wed Mar 22, 2006 11:15 am Posts: 672 Location: Southern California timehacker11 wrote:I am assuming it isn't possible like a lot of things aren't but are in single platform languages I'm not sure what you mean by this last comment. What you're asking about has nothing to do with single vs. cross platform. That said, there is no ListBox.SelectedItem method. So you would need to do something like: Dim i As Integer = Listbox1.ListIndex If i < 0 Then MsgBox("Boo! No files selected!") ElseIf ListBox1.Cell(i,0).InStr("szs") > 0 Then MsgBox("You've selected a SZS File!") ElseIf ListBox1.Cell(i,0).InStr("brres") > 0 Then MsgBox("You've selected a BRRES file!") Else MsgBox("Boo! No Nintendo files selected!") End If You could use Extends to add functions like "SelectedItem" to ListBox, and "Contains" to string. _________________ Daniel L. Taylor Custom Controls for Real Studio WE! Visit: http://www.webcustomcontrols.com/ Top kermit Post subject: Re: Is it even possible to do this?Posted: Sat May 11, 2013 4:50 am Joined: Mon May 30, 2011 12:56 am Posts: 682 if the listbox is not multi select, then something like this will do it: dim selection as string dim answer as string answer = "Boo! No Nintendo files selected!" selection = listbox1.list(Listbox1.ListIndex) if InStr(selection,"szs") > 0 then answer ="You've selected a SZS File!" if InStr(selection,"brres")> 0 then answer ="You've selected a BRRES File!" msgbox answer Top Karen Post subject: Re: Is it even possible to do this?Posted: Sat May 11, 2013 9:12 am Joined: Fri Sep 30, 2005 8:53 am Posts: 1000 Of course it is possible... May I suggest you read the documentation on the listbox in language reference for the listbox API? What you are asking shows you did not look there first. You won't learn the language and the framework well enough to do anything significant without doing some homework. - Karen Top taylor-design Post subject: Re: Is it even possible to do this?Posted: Sat May 11, 2013 2:14 pm Joined: Wed Mar 22, 2006 11:15 am Posts: 672 Location: Southern California kermit wrote:if the listbox is not multi select, then something like this will do it: .. selection = listbox1.list(Listbox1.ListIndex) .. Always check for no selection, which is -1. Most ListBox methods that take an index will throw an OutOfBounds. ListBox.List will return the entire list as a string with -1, which is odd, and will create a subtle bug instead of an out right exception. Actually, I tend to code even more defensively just in case a bug elsewhere ever returns a crazy result: If ListBox1.Index < 0 Or ListBox1.Index >= ListBox1.ListCount Then TakeSomeDefensiveAction... _________________ Daniel L. Taylor Custom Controls for Real Studio WE! Visit: http://www.webcustomcontrols.com/ Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 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]
