|
-
Nov 14th, 2005, 08:51 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Script Problem
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer
word() = Split(Text1.Text, " ")
n = UBound(word) + 1
Label1.Caption = n
For i = 1 To n
Spell word(i), i
Next
Text1.Text = ""
Text1.Text = word(1)
For i = 2 To n
Text1.Text = Text1.Text & " " & word(i)
Next
End Sub
VB Code:
Option Explicit
Public word() As String
Function Spell(w As String, z As Integer) As String
If w = "like" Then
word(z) = "lke"
End If
End Function
Thats the error.
The program is suppose to be like a spell checker.
Last edited by Garrett19212; Nov 14th, 2005 at 10:07 PM.
-
Nov 14th, 2005, 10:47 PM
#2
Thread Starter
Addicted Member
-
Nov 14th, 2005, 10:55 PM
#3
Re: Script Problem
You loop from 1 to n, where n is the upper bound of the array + 1. Change the For loop to:
VB Code:
For i = 0 To n - 1
Spell word(i), i
Next
-
Nov 14th, 2005, 11:11 PM
#4
Thread Starter
Addicted Member
Re: Script Problem
Ok thanks, but now I have another problem.
Say I have
in the textbox.
I click the Command1 now it appears like this
But it's suppose to be: lke lke lke
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
Command1.Enabled = False
check = True
Text1.Text = LCase(Text1.Text)
word() = Split(Text1.Text, " ")
n = UBound(word) + 1
Label1.Caption = "Words: " & n
For i = 0 To n - 1
Spell word(i), i
Next
Text1.Text = ""
For i = 0 To n - 1
Text1.Text = Text1.Text & " " & word(i)
Next
check = False
Command1.Enabled = True
End Sub
VB Code:
Option Explicit
Public word() As String
Public check As Boolean
Public n As Integer
Function Spell(w As String, z As Integer) As String
If w = "like" Then word(z) = "lke"
End Function
-
Nov 14th, 2005, 11:15 PM
#5
Re: Script Problem
You have to use _ instead of spaces.
lke__lke__lke
or
lke_lke_lke
-
Nov 14th, 2005, 11:17 PM
#6
Re: Script Problem
This code works fine for me:
VB Code:
Private Sub Command1_Click()
Dim i As Integer
Command1.Enabled = False
check = True
Text1.Text = LCase(Text1.Text)
word() = Split(Text1.Text, " ")
n = UBound(word) + 1
Label1.Caption = "Words: " & n
For i = 0 To n - 1
Spell word(i), i
Next
[b] Text1.Text = Join(word, " ") [/b]'Join is the opposite of Split
check = False
Command1.Enabled = True
End Sub
-
Nov 14th, 2005, 11:26 PM
#7
Thread Starter
Addicted Member
Re: Script Problem
Works , but only on the first line. If I type something on the second line(its got multiline on) it doesn't change it.
-
Nov 14th, 2005, 11:37 PM
#8
Re: Script Problem
That's because between the last word on one line and the first word on the next line there is a linebreak and not a space. To check every word you should first split up the lines and then split each line to get the words on that line.
VB Code:
Private Sub Command1_Click()
Dim i As Integer
Dim sLines() As String
Dim iLineCount As Long, x As Long
Dim iWordCount As Long
Command1.Enabled = False
check = True
Text1.Text = LCase(Text1.Text)
sLines = Split(Text1.Text, vbCrLf)
iLineCount = UBound(sLines)
For x = 0 To iLineCount
word() = Split(sLines(x), " ")
n = UBound(word) + 1
iWordCount = iWordCount + n
For i = 0 To n - 1
Spell word(i), i
Next
sLines(x) = Join(word, " ")
Next
Label1.Caption = "Words: " & iWordCount
Text1.Text = Join(sLines, vbCrLf)
check = False
Command1.Enabled = True
End Sub
-
Nov 14th, 2005, 11:44 PM
#9
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|