vb编程:单词分解怎么编?Private Sub Command1_Click() Dim s As String,a() As String,i As Integer s = Text1.Text Call aword(s,a) List1.AddItem p End Sub Private Sub Command2_Click() Text1.Text = "" List1.Clear Text1.SetFocus End Sub Private Sub
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 02:17:10
vb编程:单词分解怎么编?Private Sub Command1_Click() Dim s As String,a() As String,i As Integer s = Text1.Text Call aword(s,a) List1.AddItem p End Sub Private Sub Command2_Click() Text1.Text = "" List1.Clear Text1.SetFocus End Sub Private Sub
vb编程:单词分解怎么编?
Private Sub Command1_Click()
Dim s As String,a() As String,i As Integer
s = Text1.Text
Call aword(s,a)
List1.AddItem p
End Sub
Private Sub Command2_Click()
Text1.Text = ""
List1.Clear
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub aword(s As String,word() As String)
Dim ch As String * 1,p As String,k As Integer
For i = 1 To Len(s) - 1
ch = Mid(s,i,1)
If Asc(ch) 32 And ch "." Then
p = p & ch
Else
k = k + 1
ReDim Preserve word(k)
word(k) = p
p = ""
End If
Next i
End Sub
主过程应该怎么调用?
vb编程:单词分解怎么编?Private Sub Command1_Click() Dim s As String,a() As String,i As Integer s = Text1.Text Call aword(s,a) List1.AddItem p End Sub Private Sub Command2_Click() Text1.Text = "" List1.Clear Text1.SetFocus End Sub Private Sub
该程序不对啊,List1.AddItem p :这时的变量p已经为空了.
需要有三个按钮、一个文本框、一个listbox
我改后可以正常分解单词:
Private Sub Command1_Click()
Dim s As String,a() As String,i As Integer
s = Text1.Text
Call aword(s,a)
End Sub
Private Sub Command2_Click()
Text1.Text = ""
List1.Clear
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub aword(s As String,word() As String)
Dim ch As String * 1,p As String,k As Integer
Dim n As Integer,i As Integer
For i = 1 To Len(s)
ch = Mid(s,i,1)
n = Asc(ch)
If (n > 96 And n < 123) Or (n > 64 And n < 89) Or (n > 47 And n < 58) Or ch = "-" Or ch = "'" Then
p = p & ch
ElseIf p "" Then
k = k + 1
ReDim Preserve word(k)
word(k) = p
List1.AddItem p
p = ""
End If
Next i
If p "" Then List1.AddItem p
End Sub
--------------------
你这里很多变量都是局部变量,可以省去.省去后代码如下:
Private Sub Command1_Click()
Dim s As String
s = Text1.Text
Call aword(s)
End Sub
Private Sub Command2_Click()
Text1.Text = ""
List1.Clear
Text1.SetFocus
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub aword(s As String)
Dim ch As String * 1,p As String
Dim n As Integer,i As Integer
For i = 1 To Len(s)
ch = Mid(s,i,1)
n = Asc(ch)
If (n > 96 And n < 123) Or (n > 64 And n < 89) Or (n > 47 And n < 58) Or ch = "-" Or ch = "'" Then
p = p & ch
ElseIf p "" Then
List1.AddItem p
p = ""
End If
Next i
If p "" Then List1.AddItem p
End Sub