|
-
Jan 16th, 2007, 05:17 AM
#1
Thread Starter
New Member
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:
Private Sub Form_Load()
With MSComm1
.CommPort = 1
.Handshaking = comNone
.Settings = "9600,n,8,1"
.PortOpen = True
End With
End Sub
Private Sub MSComm1_OnComm()
binnen = AscB(MSComm1.Input)
If binnen = 40 Then
display40.Visible = True
display41.Visible = False
display42.Visible = False
display43.Visible = False
display44.Visible = False
display45.Visible = False
display46.Visible = False
display47.Visible = False
display48.Visible = False
display49.Visible = False
End If
If binnen = 41 Then
display40.Visible = False
display41.Visible = True
End If
If binnen = 42 Then
display41.Visible = False
display42.Visible = True
End If
If binnen = 43 Then
display42.Visible = False
display43.Visible = True
End If
If binnen = 44 Then
display43.Visible = False
display44.Visible = True
End If
If binnen = 45 Then
display44.Visible = False
display45.Visible = True
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
-
Jan 17th, 2007, 03:49 PM
#2
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
-
Jan 17th, 2007, 05:11 PM
#3
Thread Starter
New Member
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.
-
Jan 18th, 2007, 03:03 PM
#4
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:
Dim s As String, binnen As Byte
s = MSComm1.Input
binnen = Val(s)
Select Case binnen
Case 40
display40.Visible = True
display41.Visible = False
display42.Visible = False
display43.Visible = False
display44.Visible = False
display45.Visible = False
display46.Visible = False
display47.Visible = False
display48.Visible = False
display49.Visible = False
Case 41
display40.Visible = False
display41.Visible = True
Case 42
display41.Visible = False
display42.Visible = True
Case 43
display42.Visible = False
display43.Visible = True
Case 44
display43.Visible = False
display44.Visible = True
Case 45
display44.Visible = False
display45.Visible = True
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|