PDA

Click to See Complete Forum and Search --> : Run time error 5


rgerrit
Jan 16th, 2007, 05:17 AM
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

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

Al42
Jan 17th, 2007, 03:49 PM
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.

rgerrit
Jan 17th, 2007, 05:11 PM
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.

Al42
Jan 18th, 2007, 03:03 PM
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 caseDim 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