Results 1 to 4 of 4

Thread: Run time error 5

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    2

    Run time error 5

    Hello,

    i've made a program in visual basic using the mscomm.

    The program works good on Windows 2000 And Windows XP(sp1)
    But when I try it on Win xp Sp2 then the program does'nt work.

    The problem is this code:
    binnen = AscB(MSComm1.Input)

    I can't use AscB in winxp sp2
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.    With MSComm1
    4.       .CommPort = 1
    5.       .Handshaking = comNone
    6.       .Settings = "9600,n,8,1"
    7.       .PortOpen = True
    8.    End With
    9.    
    10.  
    11. End Sub
    12.  
    13. Private Sub MSComm1_OnComm()
    14. binnen = AscB(MSComm1.Input)
    15.  
    16. If binnen = 40 Then
    17. display40.Visible = True
    18. display41.Visible = False
    19. display42.Visible = False
    20. display43.Visible = False
    21. display44.Visible = False
    22. display45.Visible = False
    23. display46.Visible = False
    24. display47.Visible = False
    25. display48.Visible = False
    26. display49.Visible = False
    27. End If
    28.  
    29. If binnen = 41 Then
    30. display40.Visible = False
    31. display41.Visible = True
    32. End If
    33.  
    34. If binnen = 42 Then
    35. display41.Visible = False
    36. display42.Visible = True
    37. End If
    38.  
    39. If binnen = 43 Then
    40. display42.Visible = False
    41. display43.Visible = True
    42. End If
    43.  
    44. If binnen = 44 Then
    45. display43.Visible = False
    46. display44.Visible = True
    47.  
    48. End If
    49.  
    50. If binnen = 45 Then
    51. display44.Visible = False
    52. display45.Visible = True
    53. End If

    Maby someone know how to fix this problem, or know how to convert a string to byte so that I don't have to use The ASC function ?

    Thnx for any help

    Ronald
    Last edited by si_the_geek; Jan 16th, 2007 at 01:12 PM. Reason: corrected tags

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Run time error 5

    You're not defining binnen. Always declare all variables.

    You can't convert a string (an array of bytes) to a byte, each character is a byte.

    What does the string you're receiving look like and what are you trying to do with it? The code isn't exactly self-documenting.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    2

    Re: Run time error 5

    Sorry this is not the whole code.
    Binnen is defined as a byte

    The pc is connected with a microcontroller.
    And that microcontroller sents a value.

    I receve that value with the command mscomm1.input and convert the string it has receved in a byte and then put in in the variable binnen.

    When it has done that it's checking if variable is 40, 41 enz and then with picture it needs to show.

    The variable always has a value bigger then 0.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Run time error 5

    Is it being sent as a binary value or an ASCII string? If it's being sent as "40", it's two bytes, a "4" and a "0". If that's the case
    VB Code:
    1. Dim s As String, binnen As Byte
    2.   s = MSComm1.Input
    3.   binnen = Val(s)
    4.  
    5.   Select Case binnen
    6.     Case 40
    7.       display40.Visible = True
    8.       display41.Visible = False
    9.       display42.Visible = False
    10.       display43.Visible = False
    11.       display44.Visible = False
    12.       display45.Visible = False
    13.       display46.Visible = False
    14.       display47.Visible = False
    15.       display48.Visible = False
    16.       display49.Visible = False
    17.     Case 41
    18.       display40.Visible = False
    19.       display41.Visible = True
    20.     Case 42
    21.       display41.Visible = False
    22.       display42.Visible = True
    23.     Case 43
    24.       display42.Visible = False
    25.       display43.Visible = True
    26.     Case 44
    27.       display43.Visible = False
    28.       display44.Visible = True
    29.     Case 45
    30.       display44.Visible = False
    31.       display45.Visible = True
    32.   End Select
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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