Results 1 to 18 of 18

Thread: Reversing text in a text box????????

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    I am looking to do an incremental search in a listview. I know it is possible to do it with an API and a listbox but I really would like to use a listview.

    Is it possible and how ?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    What do you mean by Incremental search?

    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819



    [This message has been edited by Serge (edited 11-23-1999).]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    I mean that as you type in a text box, the list selects the nearest match...

    (sorry I should have been more specific)

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this:
    Code:
    Private Type LV_FINDINFO
        flags As Long
        psz As String
        lParam As Long
        pt As Long
        vkDirection As Long
    End Type
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LVFI_STRING = &H2
    Private Const LVFI_PARTIAL = &H8
    Private Const LVM_FINDITEM = LVM_FIRST + 13
    
    Private Sub ListView1_KeyPress(KeyAscii As Integer)
        Static sWord As String
        Dim iIndex As Long
        Dim tLVFI As LV_FINDINFO
        sWord = sWord & Chr(KeyAscii)
        tLVFI.flags = LVFI_PARTIAL Or LVFI_STRING
        tLVFI.psz = sWord
        iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
        If iIndex < 0 Then
            sWord = Chr(KeyAscii)
            tLVFI.psz = sWord
            iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
        End If
        If iIndex < 0 Then
            sWord = ""
        Else
            Set ListView1.SelectedItem = ListView1.ListItems(iIndex + 1)
        End If
        KeyAscii = 0
    End Sub
    This acceptes Typing directly into the Listview, just move the Code to a Textbox if you want to do it from there.

    This code example I've put together assumes the Listview is Sorted.


    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


    [This message has been edited by Aaron Young (edited 11-23-1999).]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Thank you Aaron...

    There is one constant that is not declared in your code and (hehehe) I REALLY don't know what to do with it...

    at the line: Public Const LVM_FINDITEM = LVM_FIRST + 13

    VB tells me that LVM_FIRST is not declared...

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Sorry about that, I have no Idea how I missed it, anyway, here's the Constant:

    Private Const LVM_FIRST = &H1000

    Just add it in above LVM_FINDITEM

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Cool thanks a lot

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Still i little problem .... I have put your code in the keypress event of my textbox and when I type in it, nothing happens...

    Any ideas??

  9. #9
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Make sure the ListViews HideSelection Property is False, then use this slightly Modified version of my code:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Static sWord As String
        Dim iIndex As Long
        Dim tLVFI As LV_FINDINFO
        Dim iPos As Integer
        
        sWord = sWord & Chr(KeyAscii)
        tLVFI.flags = LVFI_PARTIAL Or LVFI_STRING
        tLVFI.psz = sWord
        iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
        If iIndex < 0 Then
            sWord = Chr(KeyAscii)
            tLVFI.psz = sWord
            iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
        End If
        If iIndex < 0 Then
            sWord = ""
        Else
            Set ListView1.SelectedItem = ListView1.ListItems(iIndex + 1)
        End If
        iPos = Text1.SelStart
        Text1 = sWord
        Text1.SelStart = iPos + 1
        KeyAscii = 0
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Ok the code works fine but my list has more items than can be shown... and as it searches, the focus goes out of sight... (the list doesn't "slide" to the selected item) is there a way to do it?

    And also the selection is in grey, is there a way to make it blue (as usual)?

    Thanks for your help Aaron!

  11. #11
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    This post goes on much longer, we'll have to start discussing my consultation fees..

    To make sure the Item Highlighted can be seen, add this line after Set ListVew1.SelectedItem = ..

    ListView1.SelectedItem.EnsureVisible

    The only way you're going to be able to change the Highlight color is to Subclass the Control and Draw the Control yourself.
    Not really worth the hassle for the sake of just changing the Color.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    You know what? I found this little method called FINDITEM which does the same thing as your code does...

    I have this line on the keyup of my textbox:
    lstRecherche.SelectedItem = lstRecherche.FindItem(txtRechercher, lvwText, , lvwPartial)

    and it does the trick (sorry for the hassle )

    as for the MakeSureVisible thing.... didn't know that and will try it right now! Thanks again ( A LOT ! )

    You're the best!

    p.s.: just to know... How long have you been programming ? (any language)

  13. #13
    New Member
    Join Date
    Oct 1999
    Location
    Leeds,Yorkshire,England
    Posts
    5

    Post

    Hi,

    I am writing a program so when you write text in a text box it displays the same text in a label but backwards eg.
    text box = Jason
    label = nosaJ
    Can someone please help me???
    Thanks in advance.

  14. #14
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post

    Thry this, it works..

    Word = Text1.Text
    L = Len(Word)
    Temp = String$(L, 32)

    For x = 1 To L
    a = Mid$(Word, x, 1)
    Mid$(Temp, (L - x) + 1, 1) = a
    Next x

    Label1.Caption = Temp

  15. #15
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    If you have VB6, then you can use the StrReverse function like this:

    Code:
    Private Sub Command1_Click()
         Text1.Text = StrReverse(Text1.Text)
    End Sub
    Remember, that only works with VB6.

    ------------------
    Tom Young, 14 Year Old
    [email protected]
    ICQ: 15743470 Add Me ICQ Me
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  16. #16
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    I did not know that... Learn somthing new here every day!!!

  17. #17
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    If you don't have VB6, add two labels on your form

    Code:
    Private Sub Form_Load()
        Dim sstring As String
        Dim iposition As Integer
        
        Label1.Caption = "VB PROGRAMMER"
        
        sstring = Label1.Caption
        
        For iposition = Len(sstring) To 1 Step -1
            Label2.Caption = Label2.Caption & Mid$(sstring, iposition, 1)
        Next
    End Sub
    Hope this works for you

    Ruchi

  18. #18
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    Just try formatting your string on the text click event, (in vb5) automatically reverses it.

    txtEntry.Click()
    txtEntry = UCASE(txtEntry)

    Just add whatever code you want to use for this weird happening, e.g label = UCASE(txtEntry)

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