Results 1 to 5 of 5

Thread: cut, copy, paste and control array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Post

    Hi,

    I've discovered a snippet of code that will enable me to prevent people cutting, copying and pasting text from my textbox. It works fine with a text box, but I can't figure out how to work it if I have an array of boxes. I keep getting a runtime error 13 - Type mismatch.

    I'd be grateful if you could help me out because I've tried lots of ways, and just can't do it.

    It involves a module, a form and a textbox (text1). In the module:

    Option Explicit

    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


    Public Const GWL_WNDPROC = (-4)
    Public Const WM_RBUTTONDOWN = &H204
    Public Const WM_CUT = &H300
    Public Const WM_COPY = &H301
    Public Const WM_PASTE = &H302


    Public lpPrevWndFunc As Long

    Sub Hook(ctlthis As Control)
    lpPrevWndFunc = SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, AddressOf WndProc)
    End Sub


    Sub UnHook(ctlthis As Control)
    Call SetWindowLong(ctlthis.hwnd, GWL_WNDPROC, lpPrevWndFunc)
    End Sub


    Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case Msg
    Case WM_RBUTTONDOWN, WM_CUT, WM_COPY, WM_PASTE
    WndProc = 0
    Case Else
    WndProc = CallWindowProc(lpPrevWndFunc, hwnd, Msg, wParam, lParam)
    End Select
    End Function


    And in the form:

    Private Sub Form_Load()
    Call Hook(Text1)
    End Sub

    Now it works fine if I just have one Text1. But the way my program will be, I have to have four text1s, a control array.

    Whenever I run my program I get that runtime error - type mismatch, and in the form load 'Call Hook(Text1)' turns out in yellow.

    I've tried Call Hook(text1(index)) and lots of others, but had no luck.

    Thanks for any help!

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    try this:
    change Hook(text1)
    to whatever the name of the other object
    hook(text2) etc.

    ------------------
    DiGiTaIErRoR

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Post

    Okay, I've figured out a way:

    Private Sub Form_Load()
    Call Hook(Txtordanswers(0))
    Call Hook(Txtordanswers(1))
    Call Hook(Txtordanswers(2))
    Call Hook(Txtordanswers(3))
    Call Hook(Txtordanswers(4))
    End Sub

    Is there a better way, though? How can I sum it up in one line, instead of going line by line? I'd really love to know.

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

    Post

    Try this:
    Code:
    Dim txtCounter As Long
    For txtCounter = 0 To Txtordanswers.Count - 1
        Call Hook(Txtordanswers(txtCounter))
    Next
    This is untested but if I doesn't work it should at least give you the idea.

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

    [This message has been edited by Compwiz (edited 10-31-1999).]

  5. #5
    Lively Member Bios's Avatar
    Join Date
    Nov 1999
    Location
    Richton Park, IL, USA
    Posts
    71

    Post

    I belive the best and most simple way to do this would be:

    for a = text1.lbound to text1.ubound
    hook(text1(a))
    next a



    ------------------
    Bios
    Age: 16
    VB, C, Perl, Java (Script), HTML, ASP Programer

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