Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Visual Basic Form Names

  • 18-10-2010 03:22PM
    #1
    Registered Users, Registered Users 2 Posts: 82 ✭✭


    I'm working on a text editor on Visual Basic. I have a Save As function and I want the text property of the form to change to the name the user has chosen for the file.

    So far I can get the entire file name i.e. C:\Temp\Example 1.doc

    by using...

    Me.Text = sfd.FileName 'where sfd is my save file dialog component.

    In this example I want the form text property to change to "Example 1"

    Any ideas???


Comments

  • Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭FSL


    Scan the file name until you find the last occurrence of a '\' then scan for the '.'

    The name you want is the bit in between.


  • Moderators, Business & Finance Moderators Posts: 11,056 Mod ✭✭✭✭Jim2007


    Assuming that you are working with VB.Net then look at the class: System.IO.Path. It should give you all the methods you need...

    Jim.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    might be quicker to scan backwards and look for the first "\" :-)


  • Closed Accounts Posts: 48 BingoMingo


    If the Folder is always "C:\Temp\" then use the replace function to
    replace "C:\Temp\" with "" and ".doc" with ""


  • Registered Users, Registered Users 2 Posts: 515 ✭✭✭NeverSayDie


    As per Jim2007's suggestion, you should look at the System.IO.Path namespace, it has a lot of static utility methods for this kind of thing.

    See item #4 on this article (code's in C#, but it's the same thing);
    http://geekswithblogs.net/BlackRabbitCoder/archive/2010/09/09/c.net-five-final-little-wonders-that-make-code-better-3.aspx


  • Advertisement
Advertisement