Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding another symbol in a (different) module expression. 1

Status
Not open for further replies.

greekpatriott

Technical User
Dec 15, 2004
65
CY
Hello,
Is it possible to add another symbol instead of "." in this module??? Can I have two symbols at the same time such as "." or "-"?
Cheers

Public Function basChopLast(strIn As String) As String

Dim MyAry() As String

MyAry = Split(strIn, ".")


If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If

basChopLast = Join(MyAry, ".")

End Function
 
Maybe something similar to this but it does not work
Public Function basChopLast(strIn As String) As String

Dim MyAry() As String

MyAry = Split(strIn, ".")
MyAry = Split(strIn, "-")


If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If

basChopLast = Join(MyAry, ".")
basChopLast = Join(MyAry, "-")

End Function
 
Hello, again I try not to be a burden. This is what I tried even if I dont know programming. This is not however what I exactly I need though it works. Any better suggestions??

Public Function basChopLast(strIn As String, delimeter) As String
Select Case delimeter
Dim MyAry() As String
Case 1
MyAry = Split(strIn, ".")
If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If
basChopLast = Join(MyAry, ".")
Case 2
MyAry = Split(strIn, "-")
If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If
basChopLast = Join(MyAry, "-")
End Select
End Function
 
Maybe something in the line of this though it is not working as expected:
Public Function basChop(strIn As String) As String

Dim MyAry() As String
Set delimeter = "." Or "-"
MyAry = Split(strIn, delimeter)
If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If
basChopLast = Join(MyAry, delimeter)
End Function
 
ok another solution that I came up with but still it is similar to case 1 case 2 as above. Anyone who is familiar to programming maybe able to help me out. Cheers.

Public Function basChop(strIn As String, delimeter As String) As String

Dim MyAry() As String
If delimeter = "." Then GoTo 10
If delimeter = "-" Then GoTo 20
10 MyAry = Split(strIn, ".")
11 If (UBound(MyAry) > 0) Then
12 ReDim Preserve MyAry(UBound(MyAry) - 1)
13 End If
14 basChop = Join(MyAry, ".")
15 GoTo 25
20 MyAry = Split(strIn, "-")
21 If (UBound(MyAry) > 0) Then
22 ReDim Preserve MyAry(UBound(MyAry) - 1)
23 End If
24 basChop = Join(MyAry, "-")
25 End Function
 
ok I have a 3rd solution, still I did not find a way to remove the delimeter in the function ChopQ. Is this feaible or not? Can anyone enlighten me? Thanks


Public Function ChopQ(strIn As String, delimeter As String) As String

Dim MyAry() As String
If delimeter = "." Then MyAry = Split(strIn, ".")
If delimeter = "-" Then MyAry = Split(strIn, "-")
If (UBound(MyAry) > 0) Then
ReDim Preserve MyAry(UBound(MyAry) - 1)
End If
If delimeter = "." Then ChopQ = Join(MyAry, ".")
If delimeter = "-" Then ChopQ = Join(MyAry, "-")
End Function
 
A starting point:
Code:
Public Function ChopQ(strIn As String) As String
Dim i As Long, j As Long
i = InStrRev(strIn, ".")
j = InStrRev(strIn, "-")
If j > i Then i = j
If i > 0 Then
  ChopQ = Left(strIn, i - 1)
Else
  ChopQ = strIn
End If
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
? CHOPQS("3.5.6-7.8-20")
3.5.6-7.8

Hey this is excellent staff. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top