Public Function CountCharacters(source$) As Integer Dim counter%, t% Const Characters$ = "abcdefghijklmnopqrstuvwxyz"
For t% = 1 To Len(source$) If InStr(Characters, LCase$(Mid$(source$, t%, 1))) <> 0 Then counter% = counter% + 1 End If Next t% CountCharacters = counter% End Function
使用时就象这样: vString$ = "Testing .... about what?" MsgBox CountCharacters(vString$)
''''在新窗体上放一个command和三个textbox,然后加入以下代码 ''''按F5运行,注意先把Command的caption改成"&Replace somebody with me"
Private Sub Command1_Click() Const vString$ = "testing for somebody on the net" Select Case Command1.Caption Case "&Replace text in all textboxes" Text1.Text = vString Text2.Text = vString Text3.Text = vString Command1.Caption = "&Replace somebody with me" Case "&Replace somebody with me" Call ChangeText Command1.Caption = "&Replace text in all textboxes" End Select
End Sub
Function sReplace(SearchLine As String, SearchFor As String, ReplaceWith As String) Dim vSearchLine As String, found As Integer
found = InStr(SearchLine, SearchFor): vSearchLine = SearchLine If found <> 0 Then vSearchLine = "" If found > 1 Then vSearchLine = Left(SearchLine, found - 1) vSearchLine = vSearchLine + ReplaceWith If found + Len(SearchFor) - 1 < Len(SearchLine) Then _ vSearchLine = vSearchLine + Right$(SearchLine, _ Len(SearchLine) - found - Len(SearchFor) + 1) End If sReplace = vSearchLine
End Function
Private Sub ChangeText() Dim Control
For Each Control In Form1.Controls If TypeOf Control Is TextBox Then Control.Text = sReplace(Control.Text, "somebody", "me") End If Next Control
End Sub --5-------------------------------------------------------------
''''on the general section Dim vWords() Dim Max% Dim vCheckWord()
Private Form1_Load() Text1.SetFocus Text1.Text = "living in america but not really" Max% = 10
''''make array ''''you can use an ascii file to get the words Redim vCheckWord(Max) vCheckWord(0) = "walther" vCheckWord(1) = "musch" vCheckWord(2) = "america" vCheckWord(3) = "tilburg" vCheckWord(4) = "hallo" vCheckWord(5) = "testen" vCheckWord(6) = "testing" vCheckWord(7) = "really" vCheckWord(8) = "visual" vCheckWord(9) = "basic"
End Sub
Sub SplitStringintoWords(bron$) Dim c%, p%, t%, vCheck% Dim TempBron$, tmp$ Dim vOke As Boolean
''''splitting the input into words t% = 0 TempBron$ = bron$ For c% = 1 To Len(bron$) p% = InStr(TempBron$, Chr(32)) If p% <> 0 Then ReDim Preserve vWords(t%) tmp = Left$(TempBron$, p% - 1) vWords(t%) = StripString(tmp) TempBron$ = Right$(TempBron$, Len(TempBron$) - p) t% = t% + 1 c% = c% + p% End If Next c% ReDim Preserve vWords(t%) vWords(t%) = StripString(TempBron)
''''checking against spellingschecker vOke = False For c% = 0 To t% For vCheck% = 0 To Max If vCheckWord(vCheck%) <> vWords(c%) Then vOke = False Else vOke = True vCheck% = Max% End If Next vCheck% If Not vOke Then MsgBox vWords(c%) vOke = False Next c%
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then ''''split string into words Call SplitStringintoWords(Text1.Text) End If
End Sub
Function StripString(source As String) As String Const Letters$ = "abcdefghijklmnopqrstuvwxyz" Dim p%, tmp$
tmp = source$ For p% = 1 To Len(source$) If InStr(Letters, LCase(Mid$(source$, p%, 1))) = 0 Then Select Case p% Case 1 tmp = Right$(source$, Len(source$) - p%) Case Len(source$) tmp = Left$(source$, Len(source$) - 1) Case Else tmp = Left$(source$, p%) & Right$(source$, Len(source$) - p%) End Select End If Next p% StripString = tmp
GetFileName = PathString For p% = Len(PathString) To 0 Step -1 If Mid$(PathString,p%,1) = "\" then GetFileName = Right$(PathString,p%) Exit Function End If Next p% End Function --7-------------------------------------------------------------
没有相关教程