Results 1 to 18 of 18

Thread: Yet more trouble...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    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.

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Yet more trouble...

    Quote 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?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Yet more trouble...

    Quote 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.
    Quote 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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    219

    Re: Yet more trouble...

    I've always used + and never really had a problem with it.

  6. #6
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    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) = ....?

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Yet more trouble...

    There is a difference... may not be a problem in this case, but there is a difference.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Yet more trouble...

    Quote 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.
    Quote 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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Lively Member
    Join Date
    May 2008
    Posts
    117

    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?


  11. #11
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Yet more trouble...

    Quote 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.
    Quote 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?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Yet more trouble...

    Quote 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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Yet more trouble...

    Quote 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.
    Quote 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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Yet more trouble...

    Quote 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:
    1. 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:
    1. Dim f As New Form
    2.  
    3. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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!).
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. Dim str1 As String = 1
    2. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width