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
[313 byte] By [
MEandME] at [2007-11-11 7:39:15]

# 1 Re: Pro-blem
Try this :cool:
'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
milton at 2007-11-11 17:26:39 >

# 3 Re: Pro-blem
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 :WAVE:
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
milton at 2007-11-11 17:28:37 >
