Results 1 to 5 of 5

Thread: Title Bar Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Tacoma, WA
    Posts
    13

    Title Bar Help

    I'm creating a notepad. When you save or open a text file its supposed to display the name of the file in the titlebar of the form. However, the way I have it coded, it displays the entire path of the file too. How do I get it to display just the name? Thanks.
    VB Code:
    1. Sub Titlebar()
    2. Me.Text = CStr(documentName) & " - NotePad"
    3. End Sub

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Try This

    Add this to the form or change Private to Public and put it in a module
    VB Code:
    1. Private Function GetFileName(ByVal strPath As String) As String
    2.         Dim strTmp() As String = Split(strPath, "\")
    3.         Return strTmp(strTmp.GetUpperBound(0))
    4.     End Function

    Then use ur code like this:

    VB Code:
    1. Sub Titlebar()
    2. Me.Text = getFileName(CStr(documentName)) & " - NotePad"
    3. End Sub
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Tacoma, WA
    Posts
    13

    Thanks

    Thanks! It worked great!

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    This functionality is built into the FileInfo object:
    VB Code:
    1. Dim fi As System.IO.FileInfo = New System.IO.FileInfo("C:\AFolder\AnotherFolder\MyTextFile.txt")
    2. Me.Text = fi.Name & " - NotePad"

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by hellswraith
    This functionality is built into the FileInfo object:
    VB Code:
    1. Dim fi As System.IO.FileInfo = New System.IO.FileInfo("C:\AFolder\AnotherFolder\MyTextFile.txt")
    2. Me.Text = fi.Name & " - NotePad"
    Yeah this is what I used.

    Better than sticking in a loop.

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