PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Auto Complete Problem-VBForums
Results 1 to 11 of 11

Thread: Auto Complete Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Auto Complete Problem

    I AM DOING PROJECT IN VB 6.0 AND USING RICHTEXTBOX
    WHEN WE Type in “vo” IN RICHTEXTBOX and press “Ctrl + Enter”. The word “void” must be compeleted.LIKE THAT I HAVE TO DO SAME FOR ALL KEYWORDS CAN ANYONE SUGGEST

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Auto Complete Problem

    You will have to store the words being looked up somewhere (vo could have been vocabulary or some other word)... you could return a subset of those words in a floating listbox (your other thread) for word completion... if only one word matches then complete the word.

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Re: Auto Complete Problem

    instead of all words,we need auto completion for only keywords.so,"for example,if we type v and press ctrl+enter,then void should be completed.otherwise we can go on with our word.no need of auto completion then"is there any possibility for this without use of listbox

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Auto Complete Problem

    exactly, how will the computer know that void is one of the possible words when competed? where does the list of words that will be autocompleted reside?

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Auto Complete Problem

    As leinad31 posted, you'll need to store the list of keywords somewhere and paste them in the RTB when matching word found.

    If you don't want to show a floating listbox, then there is a problem. If user types very few letters then how will you decide which one to paste ?

    Run the code below.
    there are 3 keywords that starts wih "d" - double, default and do.
    But if user just types "d" and Ctrl+Enter, the searching code will always pickup the first match ("double").
    Similarly, if you type "do", then it can't decide between "double" and "do".
    So, give the user a floating listbox like VB IDE (similar to the code posted in your other thread) to choose form.


    vb Code:
    1. ' add a RichTextBox in a form and paste this code
    2. Option Explicit
    3. Private Declare Function LockWindowUpdate Lib "user32" ( _
    4.    ByVal hwndLock As Long) As Long
    5.  
    6. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    7.    ByVal hwnd As Long, _
    8.    ByVal wMsg As Long, _
    9.    ByVal wParam As Long, _
    10.    ByRef lParam As Any) As Long
    11.    
    12. Private Const EM_LINEINDEX As Long = &HBB
    13. Private KeyWords() As String
    14.  
    15. Private Sub Form_Load()
    16.     KeyWords = Split("auto,const,double,float,int,short,struct,unsigned,break,continue,else,for,long,signed,switch,case,default,enum,void,goto,register,sizeof,typedef,volatile,char,do,extern,if,return,static,union,while", ",")
    17. End Sub
    18.  
    19. Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    20.     Dim CtrlDown As Boolean
    21.     Dim LastSpace As Long
    22.     Dim FindString As String
    23.     Dim NewString As String
    24.     Dim LineStart As Long
    25.     CtrlDown = (Shift And vbCtrlMask) > 0
    26.     If CtrlDown And KeyCode = 13 Then
    27.         If RichTextBox1.SelStart > 0 Then
    28.             ' get first character of line -->
    29.             LineStart = SendMessage(RichTextBox1.hwnd, EM_LINEINDEX, RichTextBox1.GetLineFromChar(RichTextBox1.SelStart), 0&)
    30.             If LineStart = RichTextBox1.SelStart - 1 Then
    31.                 LastSpace = LineStart
    32.             Else
    33.                 ' YOU NEED TO ADD CHECK FOR MORE TERMINAL CHARACTERS HERE -->
    34.                 LastSpace = InStrRev(RichTextBox1.Text, " ", RichTextBox1.SelStart)
    35.             End If
    36.             If LastSpace >= 0 Then
    37.                 FindString = Mid$(RichTextBox1.Text, LastSpace + 1, RichTextBox1.SelStart - LastSpace)
    38.                 If FindString <> "" Then
    39.                     NewString = GetAutoCompleteText(FindString)
    40.                     If NewString <> "" Then
    41.                         LockWindowUpdate RichTextBox1.hwnd
    42.                         RichTextBox1.SelStart = LastSpace
    43.                         RichTextBox1.SelLength = Len(FindString)
    44.                         RichTextBox1.SelText = NewString
    45.                         LockWindowUpdate 0
    46.                     End If
    47.                 End If
    48.             End If
    49.         End If
    50.         KeyCode = 0
    51.     End If
    52. End Sub
    53.  
    54. Private Function GetAutoCompleteText(FindString As String) As String
    55.     Dim i As Long
    56.     For i = 0 To UBound(KeyWords)
    57.         If Left$(KeyWords(i), Len(FindString)) = FindString Then
    58.             GetAutoCompleteText = KeyWords(i)
    59.             Exit Function
    60.         End If
    61.     Next
    62.     GetAutoCompleteText = ""
    63. End Function
    Last edited by iPrank; Mar 11th, 2007 at 04:36 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Auto Complete Problem

    If you decide to use a ListBox, see this thread (uses LB_FINDSTRING message).

    There is another Message, LB_FINDSTRINGEXACT, that will give you exact match.

    My idea is, (like VB)
    1. Load the list of keywords in the listbox. keep it in sorted order and keep it hidden.
    2. Detect Ctrl+Enter and get text to search (using above code)
    3. Search the listview using LB_FINDSTRINGEXACT.
    4. If match found, paste the string in RTB.
    5. If exact match not found, show the listbox like your other thread.
    6. find/highlight the matching text using LB_FINDSTRING
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Re: Auto Complete Problem

    your code written in post 5 is working properly.but we have encountered a small problem.if we want to perform auto complete at the starting of line i.e (no space is prezent in that line yet),then that code can't work as we are checking for " " in richtextbox using instrrev.

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Auto Complete Problem

    Quote Originally Posted by RAKESHTATI
    your code written in post 5 is working properly.but we have encountered a small problem.if we want to perform auto complete at the starting of line i.e (no space is prezent in that line yet),then that code can't work as we are checking for " " in richtextbox using instrrev.
    Yes. That code is not complete.

    In addition to space (" "), you'll need to add check for puntuation marks, vbNewLine, first-word-of-document etc 'word-termination-characters'.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Re: Auto Complete Problem

    GUD MRNG.
    if we check for the first word of the document,how can we get autocomplete when we press ctrl+enter after "in" instead of after "i".
    how can we overcome this?

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Auto Complete Problem

    I've edited my previous code. try this time. Solves first-char-of-document problem.

    The "in"/"i" problem is causing because we are only searching for space (" ").
    Add search for vbLf, then it will not happen,
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    35

    Re: Auto Complete Problem

    ok thanks a lot mr.iprank it is working as we need

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width