Type Mismatch error

Hello,

I am actually programming this in Visual Basic EmBedded for a handheld PC.  I am trying to communicate over a comm port to a scale.  For some reason i am getting a type mismatch error.  Any ideas? here is the code...   Thank You


Private Sub btnvalider_Click()

Dim pds As String

Dim buffer As String

 

MsComm1.CommPort = 1

MsComm1.Settings = "1200,O,7,1"

MsComm1.Handshaking = comRTS

MsComm1.InputLen = 1

MsComm1.InBufferCount = 8192

MsComm1.RThreshold = 1

MsComm1.SThreshold = 1

MsComm1.DTREnable = True

MsComm1.PortOpen = True

MsComm1.Output = Chr(27)

MsComm1.Output = "T"

Sleep (2000)

MsComm1.Output = Chr(27)

MsComm1.Output = "P"

buffer = ""

Do

    buffer = buffer & CStr(MsComm1.Input)

Loop Until Len(buffer) = 16

 

pds = Mid(buffer(5, 8))

 

If pds = "   0.0 g" Then

    frmpeseeoeuf.shox vbModal

    Me.Hide

End If

 

MsComm1.PortOpen = False

End Sub
LVL 7
NavicertsAsked:
Who is Participating?
 
EDDYKTConnect With a Mentor Commented:
May be on this line


pds = Mid(buffer(5, 8))


should be

pds = Mid(buffer, 5, 8)
0
 
vinnyd79Commented:
Probably a typo but I think you meant show on this line:

frmpeseeoeuf.shox vbModal

i.e.
frmpeseeoeuf.show vbModal

0
 
Ioannis ParaskevopoulosCommented:
Where do you get this error?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
NavicertsAuthor Commented:
well, someone emailed me the problem and the code and said the error was when they executed.  I have the handheld and the digital scale and the connection here and i am trying to replicate what he is trying to do.  While i was trying to set it up i figured i would post.

Now that i am setting up i run the program and never get the error.  I think this is because i am not entering the ...
If pds = "   0.0 g" Then

    frmpeseeoeuf.shox vbModal

    Me.Hide

End If


Reason being because he is in France i probally need to change it to If pds = " 0.0kg" or something, working on that now, ill keep you all updated

Thanks

-Navicerts
0
 
NavicertsAuthor Commented:
I am asking for the rest of the code so i can get a better idea of what the "real" problem is, ill let you know when i recive it...  If i never do ill split the points :)

-Navicerts
0
 
IThemaCommented:
otherwise u'd get a compiler error.. not a type mismatch...
Could u tell us where the error occurs? There's also a debug option in VBE. Can u tell us what class the variable MsComm1 is an instance of?

Note that you have an 'O' as in 'Option' in:
MsComm1.Settings = "1200,O,7,1"
Maybe it needs a 0 as in Zero.
0
 
NavicertsAuthor Commented:
The Comm is the settings for using the communications port (Com1, Com2, exc.).  I added "Microsoft CE Comm Control 3.0" to be able to use these.  I think this is what you were asking (I am not a VB prgrammer tbh )


-Navicerts
0
 
NavicertsAuthor Commented:
just loooked it up the O is correct, it refers to the parity for the Comm port...

I am still trying to get the rest of the code so i can be more clear (having trouble filling in the blanks myself).

I will post it as soon as i get it

Thank You


Setting  Description
E Even
M Mark
N (default) None
O Odd
S Space


-Navicerts
0
 
IThemaCommented:
I think EDDYKT is right; you SHOULD change Mid(Buffer(5,8)) into Mid(Buffer, 5, 8) as the parenthesis for the Mid-funtion is:
Mid(String, Start As Long, Optional Length As Long)

By stating Buffer(5, 8) you're actually saying that Buffer is a variable of type Array. A two-dimensional array to be exact. This would indeed cause a type mismatch, because Buffer is declared as a string. The rest of the code treats 'Buffer' correctly, namely as a string.

Cheers
0
 
NavicertsAuthor Commented:
Thank you EDDYKT once i got the program they sent me running and replicated thier error, your soultion solved it

-Navicerts
0
All Courses

From novice to tech pro — start learning today.