Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: [RESOLVED] Detect words in a listbox (Resolved)

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Detect words in a listbox (Resolved)

    Hi,

    I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.

    VB Code:
    1. Private Sub Command1_Click()
    2. For b = 0 To frmSetup.Lstblock.ListCount
    3. If Text1.Text = frmSetup.Lstblock.List(b) Then
    4. MsgBox ("Word is not allowed")
    5. Else
    6. If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
    7. Exit Sub
    8. End If
    9. End If
    10. Next b
    11. frmSetup.Show
    12. End Sub

    This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
    Last edited by Nightwalker83; Oct 18th, 2002 at 06:13 PM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    you can either use InStr or the Like operator :

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim i As Integer
    5.     For i = 0 To List1.ListCount - 1
    6.         If UCase(List1.List(i)) Like UCase("*" & Text1.Text & "*") Then List1.ListIndex = i
    7.     Next i
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.     With List1
    12.     .Clear
    13.     .AddItem "CPU"
    14.     .AddItem "RAM"
    15.     .AddItem "ROM"
    16.     .AddItem "Cache"
    17.     .AddItem "Motherboard"
    18.     .AddItem "Hard Disk"
    19.     .AddItem "Floppy Disk"
    20.     End With
    21. End Sub
    -= a peet post =-

  3. #3
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: Detect words in a listbox

    Originally posted by Nightwalker83
    Hi,

    I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.

    VB Code:
    1. Private Sub Command1_Click()
    2. For b = 0 To frmSetup.Lstblock.ListCount
    3. If Text1.Text = frmSetup.Lstblock.List(b) Then
    4. MsgBox ("Word is not allowed")
    5. Else
    6. If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
    7. Exit Sub
    8. End If
    9. End If
    10. Next b
    11. frmSetup.Show
    12. End Sub

    This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
    u can use API..

    VB Code:
    1. 'This project needs a ListBox, named List1 and a TextBox, named Text1
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    3. Const LB_FINDSTRING = &H18F
    4. Private Sub Form_Load()
    5.     'KPD-Team 1998
    6.     'URL: [url]http://www.allapi.net/[/url]
    7.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
    8.     'Add some items to the listbox
    9.     With List1
    10.         .AddItem "Computer"
    11.         .AddItem "Screen"
    12.         .AddItem "Modem"
    13.         .AddItem "Printer"
    14.         .AddItem "Scanner"
    15.         .AddItem "Sound Blaster"
    16.         .AddItem "Keyboard"
    17.         .AddItem "CD-Rom"
    18.         .AddItem "Mouse"
    19.     End With
    20. End Sub
    21. Private Sub Text1_Change()
    22.     'Retrieve the item's listindex
    23.     List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
    24. End Sub

  4. #4
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Re: Detect words in a listbox

    Originally posted by Nightwalker83
    Hi,

    I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.

    VB Code:
    1. Private Sub Command1_Click()
    2. For b = 0 To frmSetup.Lstblock.ListCount
    3. If Text1.Text = frmSetup.Lstblock.List(b) Then
    4. MsgBox ("Word is not allowed")
    5. Else
    6. If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
    7. Exit Sub
    8. End If
    9. End If
    10. Next b
    11. frmSetup.Show
    12. End Sub

    This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
    u can use API..

    VB Code:
    1. 'This project needs a ListBox, named List1 and a TextBox, named Text1
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
    3. Const LB_FINDSTRING = &H18F
    4. Private Sub Form_Load()
    5.     'KPD-Team 1998
    6.     'URL: [url]http://www.allapi.net/[/url]
    7.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
    8.     'Add some items to the listbox
    9.     With List1
    10.         .AddItem "Computer"
    11.         .AddItem "Screen"
    12.         .AddItem "Modem"
    13.         .AddItem "Printer"
    14.         .AddItem "Scanner"
    15.         .AddItem "Sound Blaster"
    16.         .AddItem "Keyboard"
    17.         .AddItem "CD-Rom"
    18.         .AddItem "Mouse"
    19.     End With
    20. End Sub
    21. Private Sub Text1_Change()
    22.     'Retrieve the item's listindex
    23.     List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
    24. End Sub

    Cheers...

  5. #5

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by peet
    you can either use InStr or the Like operator :

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim i As Integer
    5.     For i = 0 To List1.ListCount - 1
    6.         If UCase(List1.List(i)) Like UCase("*" & Text1.Text & "*") Then List1.ListIndex = i
    7.     Next i
    8. End Sub
    9.  
    10. Private Sub Form_Load()
    11.     With List1
    12.     .Clear
    13.     .AddItem "CPU"
    14.     .AddItem "RAM"
    15.     .AddItem "ROM"
    16.     .AddItem "Cache"
    17.     .AddItem "Motherboard"
    18.     .AddItem "Hard Disk"
    19.     .AddItem "Floppy Disk"
    20.     End With
    21. End Sub
    Thanx it works but it shows the msgbox I am using even if you just enter the letters that are in the listbox. How can I stop this so you can enter those letters without the msgbox appearing? I also want to know how I can stop it from happening when the user empties the textbox?

    Below is how I am using the code:

    VB Code:
    1. Private Sub txtSay_Change()
    2.  Dim i As Integer
    3.     For i = 0 To frmSetup.Lstblock.ListCount - 1
    4.         If UCase(frmSetup.Lstblock.List(i)) Like UCase("*" & txtSay.Text & "*") Or LCase(frmSetup.Lstblock.List(i)) Like LCase("*" & txtSay.Text & "*") Then
    5.         MsgBox ("This word is not allowed")
    6.     End If
    7.     Next i
    8. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by Nightwalker83
    Thanx it works but it shows the msgbox I am using even if you just enter the letters that are in the listbox. How can I stop this so you can enter those letters without the msgbox appearing? I also want to know how I can stop it from happening when the user empties the textbox?

    Below is how I am using the code:

    VB Code:
    1. Private Sub txtSay_Change()
    2.  Dim i As Integer
    3.     For i = 0 To frmSetup.Lstblock.ListCount - 1
    4.         If UCase(frmSetup.Lstblock.List(i)) Like UCase("*" & txtSay.Text & "*") Or LCase(frmSetup.Lstblock.List(i)) Like LCase("*" & txtSay.Text & "*") Then
    5.         MsgBox ("This word is not allowed")
    6.     End If
    7.     Next i
    8. End Sub
    it all depends on how you want it to work ...

    you want the search to be done when the user click a button, hit enter or something else ??



    in order to not do a search when the textbox is empty, you have to check the content of the textbox

    if txtSay.text = "" then exit sub
    -= a peet post =-

  7. #7

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by peet
    it all depends on how you want it to work ...

    you want the search to be done when the user click a button, hit enter or something else ??



    in order to not do a search when the textbox is empty, you have to check the content of the textbox

    if txtSay.text = "" then exit sub
    Peet,

    I want the program to tell me if a word that has been banned, if then word has been entered into the textbox. I am trying to make it check when I type in the textbox.

    I have changed this code of your by putting "a" instead of "i" but now it wont work.

    VB Code:
    1. Dim a As Integer
    2.  For a = 0 To frmSetup.Lstblock.ListCount - 1
    3.         If txtSay.Text = "" Then
    4.         Exit Sub
    5.         Else:
    6.         If UCase(frmSetup.Lstblock.List(i)) Like UCase("*" & txtSay.Text & "*") Then
    7.         MsgBox ("This word is not allowed")
    8.     End If
    9.     End If
    10.     Next a

    I actually put public "a" as integer in a module but is of in the form code but it still didn't work.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi again NW,
    you have made a couple of mistakes... first you do not use option explicit. I think that would have found the first problem. You use i instead of a in this line

    VB Code:
    1. If UCase(frmSetup.Lstblock.List(i)) Like UCase("*" & txtSay.Text & "*") Then

    it should have been


    VB Code:
    1. If UCase(frmSetup.Lstblock.List(a)) Like UCase("*" & txtSay.Text & "*") Then

    I would do something like this:

    VB Code:
    1. Private Sub txtSay_Change()
    2.     Dim a As Integer
    3.    
    4.     'any data at all ? if not exit
    5.     If txtSay.Text = "" Then
    6.         Lstblock.ListIndex = -1
    7.         Exit Sub
    8.     End If
    9.    
    10.     'check to see if there is data in the listbox that matches txtSay
    11.     For a = 0 To frmSetup.Lstblock.ListCount - 1
    12.         If UCase(frmSetup.Lstblock.List(a)) Like UCase("*" & txtSay.Text & "*") Then
    13.             'found one that match current crit.
    14.             'select it in the listbox, and then exit the loop
    15.             Lstblock.ListIndex = a
    16.             Exit For
    17.         Else
    18.             Lstblock.ListIndex = -1
    19.         End If
    20.     Next a
    21. End Sub

    a msgbox is no good in this case, because of the event you use.
    hope this is what you are looking for
    -= a peet post =-

  9. #9

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by peet
    Hi again NW,
    you have made a couple of mistakes... first you do not use option explicit. I think that would have found the first problem. You use i instead of a in this line

    VB Code:
    1. If UCase(frmSetup.Lstblock.List(i)) Like UCase("*" & txtSay.Text & "*") Then

    it should have been


    VB Code:
    1. If UCase(frmSetup.Lstblock.List(a)) Like UCase("*" & txtSay.Text & "*") Then

    I would do something like this:

    VB Code:
    1. Private Sub txtSay_Change()
    2.     Dim a As Integer
    3.    
    4.     'any data at all ? if not exit
    5.     If txtSay.Text = "" Then
    6.         Lstblock.ListIndex = -1
    7.         Exit Sub
    8.     End If
    9.    
    10.     'check to see if there is data in the listbox that matches txtSay
    11.     For a = 0 To frmSetup.Lstblock.ListCount - 1
    12.         If UCase(frmSetup.Lstblock.List(a)) Like UCase("*" & txtSay.Text & "*") Then
    13.             'found one that match current crit.
    14.             'select it in the listbox, and then exit the loop
    15.             Lstblock.ListIndex = a
    16.             Exit For
    17.         Else
    18.             Lstblock.ListIndex = -1
    19.         End If
    20.     Next a
    21. End Sub

    a msgbox is no good in this case, because of the event you use.
    hope this is what you are looking for
    Peet,

    I was actually hoping that I could get it so I could enter the whole word before the msgbox appears. Is this possible?

    I am only using the msgbox for testing my app.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    how do you know when an entire word is added to the text box?

    if you can answer that, Ï think you will find the solution

    I would suggest moving the routine from the changeevent to keyupevent and check to see if the keypressed = enterkey. If so, do a search.

    or move it to lost focus.

    how do you want it to be?
    -= a peet post =-

  11. #11

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by peet
    how do you know when an entire word is added to the text box?

    if you can answer that, Ï think you will find the solution

    I would suggest moving the routine from the changeevent to keyupevent and check to see if the keypressed = enterkey. If so, do a search.

    or move it to lost focus.

    how do you want it to be?
    I was think about checking a string is that possible? I am really wanting that code to detect the words that are been passed to it from the other chat app.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  12. #12
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Evening NightWalker,

    Can you 'trap' the unwanted word(s) before there loaded
    into the TextBox?

  13. #13

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    Evening NightWalker,

    Can you 'trap' the unwanted word(s) before there loaded
    into the TextBox?
    What I am trying to do is something on this forum how if your post has a swear word(s) in it the swear word gets replaced with ****.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  14. #14
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    How about just doing a relpace on the textbox string with each of the listbox entries once the user is finished typing?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  15. #15
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Originally posted by Nightwalker83
    I was think about checking a string is that possible? I am really wanting that code to detect the words that are been passed to it from the other chat app.
    Maybe Split the incomming String into and Array at the " " (prior to being placed into a Display TextBox).

    eg. arr = Split(sInputBuff, " ")

    Then run the arr data against the ListBox, and at a 'match' replace
    that array element with "****", then use:

    eg. TextBoxDisplay = Join(arr, " ")



    Bruce.

  16. #16

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    Maybe Split the incomming String into and Array at the " " (prior to being placed into a Display TextBox).

    eg. arr = Split(sInputBuff, " ")

    Then run the arr data against the ListBox, and at a 'match' replace
    that array element with "****", then use:

    eg. TextBoxDisplay = Join(arr, " ")



    Bruce.
    How would I do this?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  17. #17
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Originally posted by Nightwalker83
    How would I do this?
    Well.... first; confirm what the incomming text is in. ie is the
    chat text received in you app via a String?
    Which is then placed into a TextBox?


  18. #18
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    This is an example of what I mean. Place a ListBox on a Form.
    Assume the String Buffer sInputBuff is the incomming Text:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim sInputArr() As String
    5. Dim sInputBuff As String: sInputBuff = "This is a test to see if it works"
    6. Dim i As Integer
    7. Dim x As Integer
    8.  
    9.    'Add some of the unwanted words to a ListBox
    10.    With List1
    11.       .AddItem "Badword1"
    12.       .AddItem "Badword2"
    13.       .AddItem "test"
    14.       .AddItem "Badword4"
    15.    End With
    16.    
    17.    'Split up the String into the Array
    18.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    19.       sInputArr = Split(sInputBuff, " ")
    20.    Else
    21.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    22.       sInputArr(0) = sInputBuff
    23.    End If
    24.    
    25.    For x = 0 To UBound(sInputArr)
    26.       For i = 0 To List1.ListCount - 1
    27.          If LCase(List1.List(i)) = LCase(sInputArr(x)) Then sInputArr(x) = "*****"
    28.       Next
    29.    Next
    30.    
    31.    MsgBox Join(sInputArr) 'Join this in a TextBox
    32.  
    33. End Sub

  19. #19

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    This is an example of what I mean. Place a ListBox on a Form.
    Assume the String Buffer sInputBuff is the incomming Text:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim sInputArr() As String
    5. Dim sInputBuff As String: sInputBuff = "This is a test to see if it works"
    6. Dim i As Integer
    7. Dim x As Integer
    8.  
    9.    'Add some of the unwanted words to a ListBox
    10.    With List1
    11.       .AddItem "Badword1"
    12.       .AddItem "Badword2"
    13.       .AddItem "test"
    14.       .AddItem "Badword4"
    15.    End With
    16.    
    17.    'Split up the String into the Array
    18.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    19.       sInputArr = Split(sInputBuff, " ")
    20.    Else
    21.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    22.       sInputArr(0) = sInputBuff
    23.    End If
    24.    
    25.    For x = 0 To UBound(sInputArr)
    26.       For i = 0 To List1.ListCount - 1
    27.          If LCase(List1.List(i)) = LCase(sInputArr(x)) Then sInputArr(x) = "*****"
    28.       Next
    29.    Next
    30.    
    31.    MsgBox Join(sInputArr) 'Join this in a TextBox
    32.  
    33. End Sub
    I don't know what I am doing wrong this is the code I am using:

    VB Code:
    1. Private Sub Messlis_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2. Dim sInputArr() As String
    3. Dim sInputBuff As String: sInputBuff = "This is a test to see if it works"
    4. Messlis(intmax).GetData str
    5. 'Get the message string
    6. If InStr(1, str, "|MESSAGE|") <> 0 Then
    7.  mess = Mid$(str, 10, Len(str))
    8. Dim objFrmMain As New frmMain
    9. txtMess.SelStart = Len(mess)
    10. txtMess.SelText = mess
    11. End If
    12. 'check to see if there is data in the listbox that matches the mess string
    13.    'Split up the String into the Array
    14.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    15.       sInputArr = Split(sInputBuff, " ")
    16.    Else
    17.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    18.       sInputArr(0) = sInputBuff
    19.    End If
    20.    
    21.    For X = 0 To UBound(sInputArr)
    22.       For a = 0 To frmSetup.Lstblock.ListCount - 1
    23.          If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(X)) Then sInputArr(X) = "*****"
    24.       Next
    25.    Next
    26.    
    27.    txtMess.Text = Join(sInputArr)  'Join this in a TextBox
    28. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  20. #20
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Whats the error? What line is highlighted?

  21. #21
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    What does sInputBuffer =?????
    its just there by its self!


    maybe sInputBuffer should 'mess' (or replace it)

  22. #22

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    What does sInputBuffer =?????
    its just there by its self!


    maybe sInputBuffer should 'mess' (or replace it)
    VB Code:
    1. Dim sInputBuff As String: sInputBuff = mess 'mess being the string that was sent minus the instr part.

    Is that right? When I use the code from my previous post:

    VB Code:
    1. Dim sInputBuff As String: sInputBuff = "This is a test to see if it works"

    The only thing that appears it the other client window after the data is sent is what you put for sIntputBuff that is without the ****.
    Last edited by Nightwalker83; Sep 24th, 2002 at 11:29 PM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  23. #23
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    No, No, No

    I set sInputBuff to that string to demonstrate how it may work.

    You need to place the message text in there!

    Does that make sense.

    Bruce.

  24. #24

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    No, No, No

    I set sInputBuff to that string to demonstrate how it may work.

    You need to place the message text in there!

    Does that make sense.

    Bruce.
    Yes but when I put:

    VB Code:
    1. Dim sInputBuff As String: sInputBuff = mess 'mess being the string that was sent minus the instr part.

    The other client main window is empty when I send a message.

    OR

    do you mean:

    VB Code:
    1. Dim sInputBuff As String: sInputBuff = txtmess.text
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  25. #25
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Aaron,

    From you last post it would seem that you inadvertantly re-assigned the txtMess Box (if you did it the way u mentioned). Try this:

    Please note where I cut your code so u can put it back in the right spoy

    VB Code:
    1. [b]sInputBuff = mess    'Load the string buffer with the INCOMMING message (wich may contain swear words!)[/b]
    2. End If
    3. 'check to see if there is data in the listbox that matches the message string
    4.    'Split up the String into the Array
    5.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    6.       sInputArr = Split(sInputBuff, " ")
    7.    Else
    8.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    9.       sInputArr(0) = sInputBuff
    10.    End If
    11.    
    12.    For X = 0 To UBound(sInputArr)
    13.       For a = 0 To frmSetup.Lstblock.ListCount - 1
    14.          If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(X)) Then sInputArr(X) = "*****"
    15.       Next
    16.    Next
    17.    
    18.    [b]txtMess.Text = Join(sInputArr)  'Write out to the TextBox the 'corrected' message text. ie hashed out the swear words.[/b]
    19.    [b]txtMess.SelStart = Len(mess)[/b]
    20.    [b]txtMess.SetFocus[/b] 'I also added this.
    21.  
    22. End Sub


    Bruce.

  26. #26

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    VB Code:
    1. [b]sInputBuff = mess    'Load the string buffer with the INCOMMING message (wich may contain swear words!)<b>Aaron,
    2.  
    3. From you last post it would seem that you inadvertantly  re-assigned the txtMess Box (if you did it the way u mentioned). Try this:
    4.  
    5. Please note where I cut your code so u can put it back in the right spoy <img src="images/smilies/smile.gif" border="0" alt="" title="Smilie" class="inlineimg" />
    6.  
    7. </b>
    8. End If
    9. 'check to see if there is data in the listbox that matches the message string
    10.    'Split up the String into the Array
    11.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    12.       sInputArr = Split(sInputBuff, " ")
    13.    Else
    14.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    15.       sInputArr(0) = sInputBuff
    16.    End If
    17.    
    18.    For X = 0 To UBound(sInputArr)
    19.       For a = 0 To frmSetup.Lstblock.ListCount - 1
    20.          If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(X)) Then sInputArr(X) = "*****"
    21.       Next
    22.    Next
    23.    
    24.    [b]txtMess.Text = Join(sInputArr)  'Write out to the TextBox the 'corrected' message text. ie hashed out the swear words.[/b]
    25.    [b]txtMess.SelStart = Len(mess)[/b]
    26.    [b]txtMess.SetFocus[/b] 'I also added this.
    27.  
    28. End Sub


    Bruce. [/B]
    Thanx it worked but I am still having trouble if there is only one word being sent. I was wondering if a could get the number of * characters to match the word being blocked number of chacters?
    Last edited by Nightwalker83; Sep 26th, 2002 at 05:23 AM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  27. #27
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Hmmm,

    That was one of the tests I checked. Note how I commented the code
    to place a series of words, or one word into the Array......

    And I was going to assign the number of "*" to the lenght of each
    word... but I ran outa time ... - You give it ago, youll figure it out.

    Bruce.

  28. #28

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    Hmmm,

    That was one of the tests I checked. Note how I commented the code
    to place a series of words, or one word into the Array......

    And I was going to assign the number of "*" to the lenght of each
    word... but I ran outa time ... - You give it ago, youll figure it out.

    Bruce.
    I tried the REPLACE function but I couldn't figure out how to make the number of "*" to equal the len of the word.
    Last edited by Nightwalker83; Sep 26th, 2002 at 06:54 AM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  29. #29
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Originally posted by Nightwalker83
    I was wondering if a could get the number of * characters to match the word being blocked number of chacters?
    Use the String Function; like:
    VB Code:
    1. If LCase(List1.List(i)) = LCase(sInputArr(x)) Then sInputArr(x) = [b]String(Len(List1.List(i)), "*")[/b]



    Bruce.

  30. #30

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    VB Code:
    1. If LCase(List1.List(i)) = LCase(sInputArr(x)) Then sInputArr(x) = [b]String(Len(List1.List(i)), "*")<b>Use the <b>String</b> Function; like:
    2. </b>



    Bruce. [/B]
    Thanx it works great
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  31. #31

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Bruce,

    I am using this code to replace the words:

    VB Code:
    1. If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    2.       sInputArr = Split(sInputBuff, " ")
    3.    Else
    4.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    5.       sInputArr(0) = sInputBuff
    6.    End If
    7.    For x = 0 To UBound(sInputArr)
    8.       For a = 0 To frmSetup.Lstblock.ListCount
    9.          If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(x)) Then sInputArr(x) = String(Len(frmSetup.Lstblock.List(a)), "*")
    10.  
    11.       Next a
    12.    Next x
    13.    
    14.    txtMess.Text = Join(sInputArr)  'Write out to the TextBox the 'corrected' message text. ie hashed out the swear words.
    15.    txtMess.SelStart = Len(mess)
    16. End Sub

    I am have trouble because if I have one word or even two words in the listbox it works. If I have three or more words it the listbox it will not hash out all the words in the listbox. The program changes the words being hashed out each time which I don't want. I want all the words in the listbox to be hashed out.

    Could you please help me solve this problem.

    Thanx

    Aaron
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  32. #32

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    I have just about had it with this stupid thing. The code works fine in a test program I have made but it will not work in my chat app.

    VB Code:
    1. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2. Winsock1(intmax).GetData str
    3. If InStr(1, str, "|END|") <> 0 Then
    4. End
    5. End If
    6. Dim sInputArr() As String
    7. Dim sInputBuff As String
    8. 'Get the message string
    9. If InStr(1, str, "|MESSAGE|") <> 0 Then
    10.  mess = Mid$(str, 10, Len(str))
    11. sInputBuff = mess    'Load the string buffer with the INCOMMING message (wich may contain swear words!)
    12. End If
    13. 'Check to see if there is data in the listbox that matches the message string
    14.    'Split up the String into the Array
    15.    If InStr(sInputBuff, " ") Then   'More than 1 word, so split
    16.       sInputArr = Split(sInputBuff, " ")
    17.    Else
    18.       ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    19.       sInputArr(0) = sInputBuff
    20.    End If
    21.  
    22.    For x = 0 To UBound(sInputArr)
    23.       For a = 0 To frmSetup.Lstblock.ListCount - 1
    24.          If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(x)) Then sInputArr(x) = String(Len(frmSetup.Lstblock.List(a)), "*")
    25.      Next a
    26.       Next x
    27.       txtmess.Text = txtmess.Text & Join(sInputArr, " ")   'Write out to the TextBox the 'corrected' message text. ie hashed out the swear words.
    28.    txtmess.SelStart = Len(txtmess.Text)
    29.  
    30. End Sub
    Last edited by Nightwalker83; Dec 13th, 2007 at 07:45 PM.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  33. #33
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589

    try this

    What you first posted has an error I think
    Try this...May be this is the thing you are looking for


    For b = 0 To frmSetup.LstBlock.ListCount
    If Text1.Text = frmSetup.LstBlock.List(b) Then
    MsgBox ("Word is not allowed")
    Else
    If Text1.Text = "" or frmSetup.LstBlock.listcount=0 Then
    Exit Sub
    End If
    End If
    Next b
    frmSetup.Show
    End Sub

  34. #34
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Aaron,

    I unzipped both apps, and it ran fine!

    I was able to type a string like : "this is a test" in the
    Clien TYextBox, and the message appeared like "this is a ****"
    in the Server end????

    It worked great! whats it not doing your end?


    (I had to add the WindSock Component)


    Bruce.

  35. #35

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Originally posted by Bruce Fox
    Aaron,

    I unzipped both apps, and it ran fine!

    I was able to type a string like : "this is a test" in the
    Clien TYextBox, and the message appeared like "this is a ****"
    in the Server end????

    It worked great! whats it not doing your end?


    (I had to add the WindSock Component)


    Bruce.

    I can get the client/sever demo to work except when I copy and paste the code in to my chat app it doesn't work properly.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  36. #36
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Use Split Command to split the words then check them


    Array = split(String," ")
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  37. #37
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    Originally posted by BodwadUK
    Use Split Command to split the words then check them


    Array = split(String," ")
    Thanks BodwadUK, but thats what were doing

  38. #38
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Oh HEHE Sorry Didnt Bother reading all
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  39. #39

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344
    Thanx Bruce

    VB Code:
    1. 'Check to see if there is data in the listbox that matches the message string
    2.   'Split up the String into the Array
    3.  
    4.   sInputBuff = Replace(sInputBuff, "Aaron Says:", "")
    5.  
    6.   If InStr(sInputBuff, " ") > 0 Then   'More than 1 word, so split
    7.      sInputArr = Split(sInputBuff, " ")
    8.   Else
    9.      ReDim sInputArr(0)   'Only 1 word, so place it in the Array
    10.      sInputArr(0) = sInputBuff
    11.   End If
    12.  
    13.   For x = 0 To UBound(sInputArr)
    14.      For a = 0 To frmSetup.Lstblock.ListCount - 1
    15.         'The following line removes vbCrLf from the array
    16.         sInputArr(x) = Replace(sInputArr(x), vbCrLf, "")
    17.         If UCase(frmSetup.Lstblock.List(a)) = UCase(sInputArr(x)) Then sInputArr(x) = String(Len(frmSetup.Lstblock.List(a)), "*")
    18.      Next a
    19.   Next x
    20.  
    21.   txtMess.Text = txtMess.Text & Join(sInputArr, " ") & vbCrLf 'Write out to the TextBox the 'corrected' message text. ie hashed out the swear words.
    22.   txtMess.SelStart = Len(txtMess.Text)
    23.  
    24. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  40. #40
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,428
    WoooHooooo ,

    Baring the other minor 'bugs' (and future tweeking) its comming
    along well


    And.... If you use Option Explicit (at the top of each Forms code),
    you'll will find all the un-assigend variables too (you may want to
    keep that for another day tho ).




    Bruce.

Page 1 of 2 12 LastLast

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