Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Apr 27, 2017 1:46 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Is it even possible to do this?
PostPosted: Sat May 11, 2013 12:43 am 
Offline

Joined: Sat Apr 20, 2013 7:41 pm
Posts: 37
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

_________________
Xojo Countdown:
http://timehacker11.com/apps/countdowns/xojo/


Top
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sat May 11, 2013 1:59 am 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
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
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sat May 11, 2013 4:50 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
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
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sat May 11, 2013 9:12 am 
Offline

Joined: Fri Sep 30, 2005 8:53 am
Posts: 1002
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
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sat May 11, 2013 2:14 pm 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
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
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sun May 12, 2013 3:42 am 
Offline

Joined: Sat Apr 20, 2013 7:41 pm
Posts: 37
taylor-design wrote:
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.


Thanks for the code.

@Karen: I infact did look in the LR, but I'm so used to VB.NET where every piece of code is "Englishified". For example, VB.NET has the SelectedItem method, while RealBasic does not, atleast not by default.

@taylor design: I've just looked into the Extends method in the LR, and it looks amazing and super powerful. Will do some experimentation with it. Although where would I put it? In a class method?

_________________
Xojo Countdown:
http://timehacker11.com/apps/countdowns/xojo/


Top
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sun May 12, 2013 3:52 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Extension methods must be put into a module.

_________________
Boredom Software


Top
 Profile  
 
 Post subject: Re: Is it even possible to do this?
PostPosted: Sun May 12, 2013 3:58 am 
Offline

Joined: Wed Mar 22, 2006 11:15 am
Posts: 712
Location: Southern California
timehacker11 wrote:
@taylor design: I've just looked into the Extends method in the LR, and it looks amazing and super powerful. Will do some experimentation with it. Although where would I put it? In a class method?


Put Extends methods in a module. I usually name the module after the class being extended, i.e. "ListBoxExt".

Keep in mind that you can't override an Extends method in a subclass.

_________________
Daniel L. Taylor
Custom Controls for Real Studio WE!
Visit: http://www.webcustomcontrols.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group