我的意思就是说在我那现成的代码里直接修改添加回车键所代表字符数的代码!
我的意思就是说在我那现成的代码里直接修改添加回车键所代表字符数的代码!
现在代码改为如下:
Private Sub Text1_Change()
Dim str As String
Dim T As Integer
Dim tx As Integer
Dim i As Integer
Dim n As Single
T = 0
For tx = 0 To Len(Text1.Text)
Text1.SelStart = tx
Text1.SelLength = 1
str = Text1.SelText
If str = "," Or str = "。" Or str = "!" Or str = "《" Or str = "》" Or str = "“" Or str = "”" Or str = ":" Or str = "(" Or str = ")" Or str = "(" Or str = ")" Or str = ";" Or str = "、" Or str = "?" Or str = "," Or str = "." Or str = "0" Or str = "1" Or str = "2" Or str = "3" Or str = "4" Or str = "5" Or str = "6" Or str = "7" Or str = "8" Or str = "9" Then T = T + 1
Next tx
T = T / 2
For i = 1 To Len(Replace(Text1.Text, " ", "")) - T
If Asc(Mid(Text1.Text, i, 1)) = 13 Then
n = n
Else
n = n + 1
End If
Next i
Text11.Text = n
Command2.SetFocus
End Sub
两种结果:
一、以粘贴文本文字形式显示在TEXT里的结果为,
(:“按照中共安徽省委办公厅、安徽省人民政府办公厅《关于开展县域经济考核评价,促进县域经济发展的实施意”共46。5个字符)
若是在一行里,就是46(实际为46。5),若分成两行就是47,分成三行就是48分成四行就是59,自动加1。。。。)于TEXT里,统计为为回车键字数算1,每按次回车键,就自动加1而不是加2了!
二、以在VB里打开\11.TXT形式并显示到TEXT里的结果为48(只有一行字的话一行,)
分成两行字的话就是49;分成三行字的话就是50;....以此类推.
说来说去就是不想让回车在里面充数是吧?
设s=Text1.Text
加一句:
s = Replace(s, vbCrLf, vbNullString)
这样回车就再不会充数了,你换n行也是结果也是一样
其它没问题了吧?
你这好象解决了回车问题!
但空格问题呢?
令s = Replace(Text1.Text, " ", "")
Replace(s, vbCrLf, vbNullString)
这样行么?