Michael Duc
Michael Duc

Reputation: 11

Trim Function doesn't remove any spaces from any side

I try to trim spaces in Calc using a macro. The Trim function doesn't seem to work

I tried using Trim, LTrim, RTrim but same result. Anybody have an idea of where is wrong?

oCSL is "Arang and the Magistrate"

oCSR and z should also be like oCSL after Trim but still stays "Arang and the Magistrate   "

Code below:

Dim oAC As Object, oC As Object, oAS As Object, oCSL As String, oCSR As String
Dim oASn As Integer
Dim CellRangeAddress As New com.sun.star.table.CellRangeAddress
Dim CellAddress As New com.sun.star.table.CellAddress
oC = ThisComponent
oAS = oC.getcurrentcontroller.ActiveSheet
oASn = oC.getCurrentController().getActiveSheet().getRangeAddress().sheet

Dim Ll As Integer, Lc As Integer, r As Integer
Dim z As String, y As String
Ll = 400
Lc = 0
r = 400

' Read Each Left Side Line
Do
    Do
        ' Locate Position For Right Side
        Do
            oCSL = Trim(UCase(oAS.getCellByPosition(Lc, Ll).String))    ' oSCL Value Returned "Arang and the Magistrate"
            oCSR = Trim(UCase(oAS.getCellByPosition(7, r).String))      ' oCSR Value Returned "Arang and the Magistrate   "

z = RTrim(oAS.getCellByPosition(7, r).String)         ' z Returns Also "Arang and the Magistrate   "
            If strcomp(oCSL, oCSR) < 0 Then
            ThisComponent.CurrentController.Select(oAS.getCellByPosition(7, r))     ' Reposition Selected Area
                'ThisComponent.CurrentController.Select(oAS.getCellByPosition(Lc, Ll))      ' Reposition Selected Area
                MsgBox ("At " & r & " Not Found " & Chr(13) & oCSL)         ' Not Found
                ' Insert New Movie
                Exit Do
            else
                If UCase(oCSL) = UCase(OcSR) Then
                    ThisComponent.CurrentController.Select(oAS.getCellByPosition(7, r))     ' Reposition Selected Area
                    'MsgBox ("At " & r & " Same Value " & oCSL)     ' Same Value
                    r = r + 1
                    Exit Do
                else
                    r = r + 1
                End If
            End If
        Loop While Lc <= 4
        Lc = Lc + 1
    Loop While Lc <= 4
    Ll = Ll + 1                         ' Next Line
    Lc = 0                              ' Reset Column
Loop While oCSL <> ""                   ' getCellByPosition Starts From Col 0 Row 0

Upvotes: 0

Views: 84

Answers (1)

Michael Duc
Michael Duc

Reputation: 11

I found the reason. After using Asc() in order to figuring out if it's spaces and it wasn't spaces but special characters. Sorry for bothering everybody.

Upvotes: 1

Related Questions