|
-
Sep 1st, 2008, 01:34 PM
#1
Thread Starter
Addicted Member
Yet more trouble...
Ok, so I'm working on my custom made OpenFileDialog seeing as it was my only option to work with directories with the .luaproj extension.
Here's what it looks like so far:

However, if I click "Choose File", I will get this error:

Here is the main code snippet that drives the "Choose File" button:
Code:
projFileList = IO.Directory.GetFiles(ListBox1.DataSource + ListBox1.SelectedIndex.ToString + "\")
And "projFileList" is an array.
Last edited by Louix; Sep 1st, 2008 at 01:40 PM.
-
Sep 1st, 2008, 02:44 PM
#2
Re: Yet more trouble...
 Originally Posted by Louix
Ok, so I'm working on my custom made OpenFileDialog seeing as it was my only option to work with directories with the .luaproj extension.
What do you mean by this? The OpenFileDialog object can use a Filter and only show the .lauproj extention if you'd like. So why the need for a custom one?
As for your error, what is all of the code? What type is ListBox1.DataSource? Also, what type of array is projFileList?
-
Sep 1st, 2008, 02:48 PM
#3
Re: Yet more trouble...
kasracer - don't ask about the project file names... trust me... it's the discussion of a rather long and frustrating thread else where.
Louix - seeing as how you have 155 posts, I know you aren't all that new .... so I'll ask this:
What is the proper way to concatenate strings togehter:
Is it A:
Code:
ListBox1.DataSource + ListBox1.SelectedIndex.ToString + "\"
Or B:
Code:
ListBox1.DataSource & ListBox1.SelectedIndex.ToString & "\"
Choose wisely.
-tg
-
Sep 1st, 2008, 02:57 PM
#4
Re: Yet more trouble...
 Originally Posted by techgnome
kasracer - don't ask about the project file names... trust me... it's the discussion of a rather long and frustrating thread else where.
I'll read up on it then. It doesn't make sense from the view I receive in this thread.
 Originally Posted by techgnome
Louix - seeing as how you have 155 posts, I know you aren't all that new .... so I'll ask this:
What is the proper way to concatenate strings togehter:
Actually, both the & and the + are valid string concatenation operators in VB.Net. In VB 6 it was only &.
Now I can't remember the exact different but I believe using one over the other isn't a strict.
-
Sep 1st, 2008, 02:59 PM
#5
Thread Starter
Addicted Member
Re: Yet more trouble...
I've always used + and never really had a problem with it.
-
Sep 1st, 2008, 07:54 PM
#6
Frenzied Member
Re: Yet more trouble...
+ and & are the exact same besides the fact that you can use + to add integers as well.
I as a habit use &, though there is no difference.
~EDIT~
Also if projFileList is an array dont you have to do, projFileList(0) = ....?
-
Sep 1st, 2008, 08:26 PM
#7
Re: Yet more trouble...
There is a difference... may not be a problem in this case, but there is a difference.
-tg
-
Sep 1st, 2008, 08:54 PM
#8
Re: Yet more trouble...
 Originally Posted by kasracer
What do you mean by this? The OpenFileDialog object can use a Filter and only show the .lauproj extention if you'd like. So why the need for a custom one?
So I read up on exactly what you're trying to accomplish with the .lauproj extension and, in my opinion, it's not a good idea.
You're trying to re-create the folder-looks-like-a-file in OS X.
This is a feature of Finder and Finder alone in OS X (the OS X file system views Whatever.App as an actual folder). In my opinion, it's a little odd to implement a Folder Package type of format that should be a normal folder in any type of application rather than on a system level. Your users won't be able upload this file to the web and they won't be able to associate the folder with your application so you'll be breaking multiple assumed abilities in Windows.
Why are you not using a custom format? Basically a zip like file that includes everything you need? Then you can use the standard open-file dialog, you can associate the file to open with your application, and it'll behave like a normal file so you can upload it to websites, etc.
 Originally Posted by techgnome
There is a difference... may not be a problem in this case, but there is a difference.
Okay, the difference between using the + and & operators in string concatenation is quite simple.
If you use the + operator, then the types of all objects being concatenated must be of type string.
If you use the & operator, then it's a little bit more liberal and assumes both types are of type string.
As you can imagine, using the + operator should be preferred as it's more type specific.
-
Sep 1st, 2008, 11:02 PM
#9
Re: Yet more trouble...
The + operator is the addition operator. For the String class the addition operator is overridden and implemented as concatenation, but it's still the addition operator. Because the operator is overridden for the String class the concatenation implementation only applies to strings.
The concatenation operator & is specific to the operation. It will convert any object for which the CType operator is defined for type String into its String representation and concatenate it to the other operand.
As you can imagine, using the & operator should be preferred as it's more operation specific. This is valid, even with Option Strict On:
vb.net Code:
Dim str As String = 1 & 1
There is no implicit conversion there, which is why it's OK with Option Strict. It's simply part of the behaviour of the string concatenation operator.
-
Sep 2nd, 2008, 01:13 AM
#10
Lively Member
Re: Yet more trouble...
Code:
projFileList = IO.Directory.GetFiles( _
ListBox1.DataSource + ListBox1.SelectedIndex.ToString + "\")
I dont understand that.
what is ListBox1.DataSource in this case?
AFAIK it must be an Item which implements IList.
Ah, i think i got it: ur DataSource is an array of DirectoryInfo, and the error tells the plain truth: u cannot concatenize DirectoryInfo() and strings together.
whats the benefit of beeing rated?

-
Sep 2nd, 2008, 09:16 AM
#11
Re: Yet more trouble...
 Originally Posted by jmcilhinney
The concatenation operator & is specific to the operation. It will convert any object for which the CType operator is defined for type String into its String representation and concatenate it to the other operand.
Thanks for the clerification.
 Originally Posted by jmcilhinney
As you can imagine, using the & operator should be preferred as it's more operation specific.
Why would the & operator be preferred? The + requires the developer to concatenate two strings where as & does not require two strings.
Wouldn't it be better practice to use the + operator so you always know what type your variables are and what types they are being converted into?
-
Sep 2nd, 2008, 09:34 AM
#12
Re: Yet more trouble...
It's precisely that kind of thinking that gets people into trouble when they do this:
Code:
Dim a as Integer = 5
Dim b as Integer =6
text1.text = A + B
And then wonder why they got 11 instead of 56.
-tg
-
Sep 2nd, 2008, 09:48 AM
#13
Re: Yet more trouble...
 Originally Posted by kasracer
Thanks for the clerification.
Why would the & operator be preferred? The + requires the developer to concatenate two strings where as & does not require two strings.
Wouldn't it be better practice to use the + operator so you always know what type your variables are and what types they are being converted into?
If you're using the string concatenation operator then what other type would your result be but a string? If you don't want a string result then why would you be concatenating in the first place?
-
Sep 2nd, 2008, 10:00 AM
#14
Re: Yet more trouble...
 Originally Posted by techgnome
It's precisely that kind of thinking that gets people into trouble when they do this:
Code:
Dim a as Integer = 5
Dim b as Integer =6
text1.text = A + B
And then wonder why they got 11 instead of 56.
With Option Strict that would fail since they're not strings... I would like to think that if someone has Option Strict on and run into that, that they will figure out the problem and receive a better understanding of how assignment works but that's not to say that'll happen or that & is not a better alternative.
 Originally Posted by jmcilhinney
If you're using the string concatenation operator then what other type would your result be but a string? If you don't want a string result then why would you be concatenating in the first place?
I'm not saying I would expect a different result but I would prefer the code explicitly state a conversion is taking place.
I just always try to avoid implicit conversions as they can cause code confusion to those not as familiar and it may not always work the way you expect it to work with custom classes (can you overload the & operator?).
Last edited by Kasracer; Sep 2nd, 2008 at 10:04 AM.
-
Sep 2nd, 2008, 10:08 AM
#15
Re: Yet more trouble...
 Originally Posted by kasracer
With Option Strict that would fail since they're not strings...
I'm not saying I would expect a different result but I would prefer the code explicitly state a conversion is taking place.
I just always try to avoid implicit conversions as they can cause code confusion to those not as familiar and it may not always work the way you expect it to work with custom classes (can you overload the & operator?).
Like I said, there is no implicit conversion. Implicit conversions are not permitted with Option Strict On. With Option Strict On this is perfectly legal:
vb.net Code:
Dim str As String = 100 & 100
because the & operator is defined for type Integer and type Integer. This, on the other hand, is not legal:
vb.net Code:
Dim f As New Form Dim str As String = "100" & f
because the & operator is not defined for type String and type Form. That second code would require an implicit conversion. The first code does not. An implicit conversion would be required if the & operator only accepted String operands, which is not the case. The & operator accepts any operand whose type defines the CType operator to type String. The operator itself actually performs an EXPLICIT conversion.
-
Sep 2nd, 2008, 10:24 AM
#16
Re: Yet more trouble...
So are you saying that because you're using the & operator that the conversion is explicit? That seems kind of silly since the Operator is acting upon and converting two variables. Well, whatever floats your boat.
I think this thread is officially derailed (sorry Louix!).
-
Sep 2nd, 2008, 06:37 PM
#17
Re: Yet more trouble...
Actually, it occurred to me that I may have been talking through my hat somewhat. Implicit narrowing conversions are not allowed under Option Strict but widening conversions are. To be official, I thought "hey, why not read the documentation".
http://msdn.microsoft.com/en-us/libr...xw(VS.80).aspx
That says:
The & operator is recommended for string concatenation
but it certainly makes no implication of + being wrong at all. As a great philosopher once said:
Well, whatever floats your boat.
-
Sep 2nd, 2008, 08:14 PM
#18
Re: Yet more trouble...
Actually, I wasn't talking through my hat as much as I thought. If you type the following code with Option Strict On:
vb.net Code:
Dim str1 As String = 1 Dim str2 As String = 1 & 1
the first line will display an error stating that:
Option Strict On disallows implicit conversions from 'Integer' to 'String'.
The fact that the second line displays no such error proves that it involves no implicit conversions.
Note that I do like to prove a point, whether anyone cares or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|