Results 1 to 6 of 6

Thread: Invalid Procedure or Call error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    Leicester, England (City of Kings)
    Posts
    156

    Invalid Procedure or Call error

    Hello

    I've set up an address book in VB. It has a control array of command buttons labeled a-z, that move the recordset to the first surname beginning with the letter on the button. This enables people to move quickly through thousands of addresses.

    This was working well, Until I had to add clients with no surnames (businesses, for example). However, when this happens, I get an Invalid procedure or call arguement.

    My code is below.

    Can anyone suggest a quick fix?

    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2.  
    3. rec3ClientDetails.MoveFirst
    4.  
    5. Do Until Asc(Left(rec3ClientDetails("Surname"), 1)) = Index + 65
    6.    If Asc(Left(rec3ClientDetails("Surname"), 1)) > Index + 65 Then Stop
    7.      
    8.      rec3ClientDetails.MoveNext
    9.      
    10. Loop

    Thanks

    Sam
    Last edited by Samibouni; Dec 3rd, 2002 at 12:31 AM.

  2. #2
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    Consider using :

    VB Code:
    1. "" & rec3ClientDetails("Surname").Value
    instead. Moreover why not not test for blank surname field instead of ASCII values?
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Better still, change your Do loop structure. If a field is null, your loop will most certainly fail. To use the idea suggested earlier means you will have to use it in all the statements that accesses the field. A better idea would be to use a loop that goes on forever, break it manually, and inside the loop, use a string variable to store the value in the field.

    VB Code:
    1. 'Your Code, with null validation
    2. Private Sub Command1_Click(Index As Integer)
    3.  
    4. rec3ClientDetails.MoveFirst
    5.  
    6. Do Until Asc(Left(rec3ClientDetails("Surname") & "", 1)) = Index + 65
    7.    If Asc(Left(rec3ClientDetails("Surname") & "", 1)) > Index + 65 Then Stop
    8.      
    9.      rec3ClientDetails.MoveNext
    10.      
    11. Loop

    It needs to have the & "" part in every statement that accesses the field. Instead you could re-write the code as:
    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2. Dim tmpStr As String
    3. rec3ClientDetails.MoveFirst
    4.  
    5. Do While True
    6. tmpStr = rec3ClientDetails("Surname") & ""
    7. If Asc(Left(tmpStr, 1)) <> Index + 65 Then
    8.     Exit Do
    9. Else
    10.     If Asc(Left(tmpStr, 1)) > Index + 65 Then
    11.         Exit Do
    12.     End If
    13. End If
    14. rec3ClientDetails.MoveNext
    15. Loop
    16. End Sub

    Also I hope you know what the "Stop" statement does in the code. When you are running the code through the VB IDE, the Stop statement will break the code or act as a breakpoint. However in a compiled EXE, it will simply terminate the app.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    Leicester, England (City of Kings)
    Posts
    156
    Thanks for your comments, they are most insightful.

    However, I am still getting the same error. This time, however, VB's debugger highlights the:

    VB Code:
    1. If Asc(Left(tmpStr, 1)) <> Index + 65 Then

    piece of code. Is there another reason for this besides the blank string or is that it?

  5. #5
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Why not simply test it yourself, by putting a non-empty string in there????



    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    Leicester, England (City of Kings)
    Posts
    156
    Thanks for your reply.

    Although I was panicking a bit, I decided to look at the problem once more. I was getting the invalid procedure or call error (5) which said that the value of one of my inputs was greater than allowed.

    This confused me. It led me to wonder how vb interprets a null string. So, instead of getting it to look at one of those I put a space in the recordset. " " instead of "".

    In this way, I took your code version of my code with the null validation:

    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2.  
    3. rec3ClientDetails.MoveFirst
    4.  
    5. Do Until Asc(Left(rec3ClientDetails("Surname") & "", 1)) = Index + 65
    6.    If Asc(Left(rec3ClientDetails("Surname") & "", 1)) > Index + 65 Then Stop
    7.      
    8.      rec3ClientDetails.MoveNext
    9.      
    10. Loop
    and changed it to:
    VB Code:
    1. rec3ClientDetails.MoveFirst
    2.  
    3. Do Until Asc(Left(rec3ClientDetails("Surname") & " ", 1)) = Index + 65
    4.    If Asc(Left(rec3ClientDetails("Surname") & " ", 1)) > Index + 65 Then Exit Do
    5.      
    6.      rec3ClientDetails.MoveNext
    7.      
    8. Loop

    & whaddya know? By luck, perhaps rather than judgement, it began to work.

    Did I do good?

    Sam

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