vb 如何删除文本框最后一行空行?
有时候一个,有时候不只1个.富文本框网上代码都不行.要把光标移到有文字的最后一行尾处.不行.PrivateSubCommand1_Click()IfRight(Text1...
有时候一个,有时候不只1个. 富文本框
网上代码都不行.
要把光标移到有文字的最后一行尾处.
不行.
Private Sub Command1_Click()
If Right(Text1.Text, 2) = vbCrLf Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Function myTrim(ByVal s As String) As String'''这函数也不行老报错
Dim Length As Long
Dim Char As String
If s <> "" Then
s = Trim(s)
Length = Len(s) + 1
Do
Length = Length - 1
Char = Mid(s, Length, 1)''这里老报错
Loop Until Char <> vbCr And Char <> vbLf
myTrim = Mid(s, 1, Length)
End If
End Function 展开
网上代码都不行.
要把光标移到有文字的最后一行尾处.
不行.
Private Sub Command1_Click()
If Right(Text1.Text, 2) = vbCrLf Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Function myTrim(ByVal s As String) As String'''这函数也不行老报错
Dim Length As Long
Dim Char As String
If s <> "" Then
s = Trim(s)
Length = Len(s) + 1
Do
Length = Length - 1
Char = Mid(s, Length, 1)''这里老报错
Loop Until Char <> vbCr And Char <> vbLf
myTrim = Mid(s, 1, Length)
End If
End Function 展开
7个回答
展开全部
Private Sub Command1_Click()
r = Split(Text1.Text, vbCrLf)
For i = UBound(r) To LBound(r) Step -1
If Len(r(i)) > 0 Then Exit For
Next i
Text1.Text = r(LBound(r))
For j = LBound(r) + 1 To i
Text1.Text = Text1.Text & vbCrLf & r(j)
Next j
End Sub
r = Split(Text1.Text, vbCrLf)
For i = UBound(r) To LBound(r) Step -1
If Len(r(i)) > 0 Then Exit For
Next i
Text1.Text = r(LBound(r))
For j = LBound(r) + 1 To i
Text1.Text = Text1.Text & vbCrLf & r(j)
Next j
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a() As String
a = Split(Text1.Text, vbCrLf)
Text1.Text = ""
Dim i As Integer
For i = UBound(a) To 0 Step -1
If Replace(a(i), " ", "") = "" Then
ReDim Preserve a(i - 1)
Else
Exit For
End If
Next
For i = 0 To UBound(a)
If i <> UBound(a) Then
Text1.Text = Text1.Text & a(i) & vbCrLf
Else
Text1.Text = Text1.Text & a(i)
End If
Next
End Sub
换个代码。
Dim a() As String
a = Split(Text1.Text, vbCrLf)
Text1.Text = ""
Dim i As Integer
For i = UBound(a) To 0 Step -1
If Replace(a(i), " ", "") = "" Then
ReDim Preserve a(i - 1)
Else
Exit For
End If
Next
For i = 0 To UBound(a)
If i <> UBound(a) Then
Text1.Text = Text1.Text & a(i) & vbCrLf
Else
Text1.Text = Text1.Text & a(i)
End If
Next
End Sub
换个代码。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询