Results 1 to 9 of 9

Thread: [RESOLVED] Script Problem

  1. #1

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Resolved [RESOLVED] Script Problem

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim n As Integer
    5. Dim i As Integer
    6. word() = Split(Text1.Text, " ")
    7. n = UBound(word) + 1
    8. Label1.Caption = n
    9. For i = 1 To n
    10. Spell word(i), i
    11. Next
    12. Text1.Text = ""
    13. Text1.Text = word(1)
    14. For i = 2 To n
    15. Text1.Text = Text1.Text & " " & word(i)
    16. Next
    17. End Sub
    VB Code:
    1. Option Explicit
    2. Public word() As String
    3. Function Spell(w As String, z As Integer) As String
    4. If w = "like" Then
    5. word(z) = "lke"
    6. End If
    7. End Function

    VB Code:
    1. Spell word(i), i
    Thats the error.

    The program is suppose to be like a spell checker.
    Last edited by Garrett19212; Nov 14th, 2005 at 10:07 PM.

  2. #2

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Re: Script Problem

    bump

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. For i = 0 To n - 1
    2.     Spell word(i), i
    3. Next

  4. #4

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Re: Script Problem

    Ok thanks, but now I have another problem.
    Say I have
    like like like
    in the textbox.
    I click the Command1 now it appears like this
    lke lke like
    But it's suppose to be: lke lke lke

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4. Dim i As Integer
    5. Command1.Enabled = False
    6. check = True
    7. Text1.Text = LCase(Text1.Text)
    8. word() = Split(Text1.Text, " ")
    9. n = UBound(word) + 1
    10. Label1.Caption = "Words: " & n
    11. For i = 0 To n - 1
    12. Spell word(i), i
    13. Next
    14. Text1.Text = ""
    15. For i = 0 To n - 1
    16. Text1.Text = Text1.Text & " " & word(i)
    17. Next
    18. check = False
    19. Command1.Enabled = True
    20. End Sub

    VB Code:
    1. Option Explicit
    2. Public word() As String
    3. Public check As Boolean
    4. Public n As Integer
    5.  
    6. Function Spell(w As String, z As Integer) As String
    7. If w = "like" Then word(z) = "lke"
    8. End Function

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Script Problem

    You have to use _ instead of spaces.

    lke__lke__lke

    or

    lke_lke_lke

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Script Problem

    This code works fine for me:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim i As Integer
    3.     Command1.Enabled = False
    4.     check = True
    5.     Text1.Text = LCase(Text1.Text)
    6.     word() = Split(Text1.Text, " ")
    7.     n = UBound(word) + 1
    8.     Label1.Caption = "Words: " & n
    9.     For i = 0 To n - 1
    10.         Spell word(i), i
    11.     Next
    12. [b]    Text1.Text = Join(word, " ") [/b]'Join is the opposite of Split
    13.     check = False
    14.     Command1.Enabled = True
    15. End Sub

  7. #7

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    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.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Sub Command1_Click()
    2.     Dim i As Integer
    3.     Dim sLines() As String
    4.     Dim iLineCount As Long, x As Long
    5.     Dim iWordCount As Long
    6.    
    7.     Command1.Enabled = False
    8.     check = True
    9.     Text1.Text = LCase(Text1.Text)
    10.     sLines = Split(Text1.Text, vbCrLf)
    11.     iLineCount = UBound(sLines)
    12.     For x = 0 To iLineCount
    13.         word() = Split(sLines(x), " ")
    14.         n = UBound(word) + 1
    15.         iWordCount = iWordCount + n
    16.         For i = 0 To n - 1
    17.             Spell word(i), i
    18.         Next
    19.         sLines(x) = Join(word, " ")
    20.     Next
    21.     Label1.Caption = "Words: " & iWordCount
    22.     Text1.Text = Join(sLines, vbCrLf)
    23.     check = False
    24.     Command1.Enabled = True
    25. End Sub

  9. #9

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Re: Script Problem

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width