vb中如何删除text中指定行的数据
答案:4 悬赏:40 手机版
解决时间 2021-02-23 02:26
- 提问者网友:谁的错
- 2021-02-22 17:27
vb中如何删除text中指定行的数据
最佳答案
- 五星知识达人网友:举杯邀酒敬孤独
- 2021-02-22 17:36
Private Sub Command1_Click()
For i = 1 To 20
Text1 = Text1 & vbCrLf & i + 213
Next i
End Sub
Private Sub Command2_Click()
k = Val(InputBox("请输入你要删除的行:"))
On Error Resume Next
a = 1
For i = 1 To Val(k) - 1
a = InStr(a + 1, Text1.Text, vbCrLf)
Next i
wz2 = InStr(a + 1, Text1.Text, vbCrLf)
If i = 1 Then
Text1 = Mid(Text1, wz2 + 1)
ElseIf wz2 > 0 Then
Text1.Text = Mid(Text1, 1, a - 1) & Mid(Text1, wz2)
Else
Text1.Text = Mid(Text1, 1, a - 1)
End If
End Sub
For i = 1 To 20
Text1 = Text1 & vbCrLf & i + 213
Next i
End Sub
Private Sub Command2_Click()
k = Val(InputBox("请输入你要删除的行:"))
On Error Resume Next
a = 1
For i = 1 To Val(k) - 1
a = InStr(a + 1, Text1.Text, vbCrLf)
Next i
wz2 = InStr(a + 1, Text1.Text, vbCrLf)
If i = 1 Then
Text1 = Mid(Text1, wz2 + 1)
ElseIf wz2 > 0 Then
Text1.Text = Mid(Text1, 1, a - 1) & Mid(Text1, wz2)
Else
Text1.Text = Mid(Text1, 1, a - 1)
End If
End Sub
全部回答
- 1楼网友:往事埋风中
- 2021-02-22 19:47
Private Sub Command1_Click()
For i = 1 To 20
Text1 = Text1 & vbCrLf & i + 213
Next i
End Sub
Private Sub Command2_Click()
k = Val(InputBox("请输入你要删除的行:"))
On Error Resume Next
a = 1
For i = 1 To Val(k) - 1
a = InStr(a + 1, Text1.Text, vbCrLf)
Next i
wz2 = InStr(a + 1, Text1.Text, vbCrLf)
If i = 1 Then
Text1 = Mid(Text1, wz2 + 1)
ElseIf wz2 > 0 Then
Text1.Text = Mid(Text1, 1, a - 1) & Mid(Text1, wz2)
Else
Text1.Text = Mid(Text1, 1, a - 1)
End If
End Sub
- 2楼网友:神的生死簿
- 2021-02-22 18:54
private sub command1_click()
dim d as integer,i as integer
dim t() as string
t=split(text1.text,vbcrlf)
d=val(inputbox("输入要删除的行号:"))
if d=0 or d>ubound(t)+1 then
msgbox "行号错误"
exit sub
end if
text1=""
for i=0 to ubound(t)
if i<>d-1 then
text1=text1 & t(i) & vbcrlf
end if
next i
end sub
- 3楼网友:独钓一江月
- 2021-02-22 18:42
如果你的text1是自动换行的, 我没办法实现
如果不是, 可以试着这样
dim v
v = split(text1, vbcrlf)
split是一个按特定字符拆分字符串的函数, 返回一个数组, 比如v = split("abc|def|ghi", "|") 可以得到有三个元素的数组v, v(0) = "abc", v(1) = "def", v(2) = "ghi"
上面的写法是使用vbcrlf, 也就是换行符来拆分字符串, 具体怎么样来实现你想要的功能, 我想可以当v(5) = "" 时, 把v(6)赋给v(5), v(7)赋给v(6) ....以此类推, 把v(ubound(v)) 赋给v(ubound(v)-1)然后把数组重新拼成字符串显示在text1里面
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯