DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5

Thread: Pro-blem

  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Pro-blem

    Hi,

    string = C:\Something\Something\Something and something\

    I need code which will be doing something like this with above string:

    (Click!)
    string = C:\Something\Something\

    (Click!)
    string = C:\Something\

    (Click! :-)
    string = C:\

    it's f hard

  2. #2
    Join Date
    Nov 2004
    Location
    Perth Western Australia
    Posts
    9

    Hi MeandMe

    Try this

    'Create a new form with one text box and one command button
    'Milton Neal miltonneal@arach.net.au

    Option Explicit
    Dim strLen As Integer
    Dim strText As String

    Private Sub Command1_Click()
    Dim lofs As Integer ' Length of string
    Dim c As Integer ' Counter
    Dim strTemp As String 'Temp string buffer

    lofs = strLen
    strTemp = Left(Text1.Text, lofs)
    For c = 1 To lofs
    If Left(Right(strTemp, c), 1) = "\" Then 'Get the last char of the string and compare with \
    strTemp = Left(Text1.Text, lofs - c + 1) 'Move it int the text box
    Text1.Text = strTemp
    strLen = Len(strTemp) - 1 'Save the new string length minus the \
    Exit Sub 'Done
    End If
    Next c

    End Sub

    Private Sub Form_Load()
    strText = "C:\something\something\or something"
    Text1.Text = strText
    strLen = Len(strText)
    End Sub

  3. #3
    Join Date
    Jan 2006
    Posts
    4
    VERY good code!

    Thanx for it

  4. #4
    Join Date
    Nov 2004
    Location
    Perth Western Australia
    Posts
    9

    Exclamation Hi again

    Wasn't thinking to well last night .. but who does at 1 in the morning ...lol
    Just a small change to the command click ... just incase the initial string ends with the '\' character. ... good luck

    Private Sub Command1_Click()
    Dim lofs As Integer ' Length of string
    Dim c As Integer ' Counter
    Dim strTemp As String 'Temp string buffer

    If Right(Text1.Text, 1) = "\" Then strLen = Len(Text1.Text) - 1 'See if the last char is a \
    lofs = strLen
    strTemp = Left(Text1.Text, lofs)
    For c = 1 To lofs
    If Left(Right(strTemp, c), 1) = "\" Then 'Get the last char of the string and compare with \
    strTemp = Left(Text1.Text, lofs - c + 1) 'Move it int the text box
    Text1.Text = strTemp
    strLen = Len(strTemp) 'Save the new string length
    Exit For 'Done
    End If
    Next c

    End Sub

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    You might also look at the InStrRev function. ;-)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. StrongDisk Pro 3.0 is Released
    By Evgeniy Chanyshev in forum vb.announcements
    Replies: 0
    Last Post: 05-21-2003, 09:01 AM
  2. IIS Compression WinXP Pro
    By Murray Foxcroft in forum Web
    Replies: 0
    Last Post: 04-23-2002, 02:09 AM
  3. Re: DCOM on Win98 connecting to WIN2K Pro
    By Marco in forum VB Classic
    Replies: 0
    Last Post: 03-05-2002, 10:17 PM
  4. VB Interface for FileMaker Pro
    By MightyMouse in forum VB Classic
    Replies: 1
    Last Post: 08-21-2001, 12:37 AM
  5. Linking to Fox Pro Tables
    By Scot Naef in forum Database
    Replies: 8
    Last Post: 01-11-2001, 08:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links