Solved

Type Mismatch error

Posted on 2004-10-22
277 Views
Last Modified: 2010-05-18
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
0
Question by:Navicerts
    10 Comments
     
    LVL 28

    Expert Comment

    by:vinnyd79
    Probably a typo but I think you meant show on this line:

    frmpeseeoeuf.shox vbModal

    i.e.
    frmpeseeoeuf.show vbModal

    0
     
    LVL 26

    Accepted Solution

    by:
    May be on this line


    pds = Mid(buffer(5, 8))


    should be

    pds = Mid(buffer, 5, 8)
    0
     
    LVL 23

    Expert Comment

    by:Ioannis Paraskevopoulos
    Where do you get this error?
    0
     
    LVL 7

    Author Comment

    by:Navicerts
    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
     
    LVL 7

    Author Comment

    by:Navicerts
    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
     
    LVL 5

    Expert Comment

    by:IThema
    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
     
    LVL 7

    Author Comment

    by:Navicerts
    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
     
    LVL 7

    Author Comment

    by:Navicerts
    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
     
    LVL 5

    Expert Comment

    by:IThema
    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
     
    LVL 7

    Author Comment

    by:Navicerts
    Thank you EDDYKT once i got the program they sent me running and replicated thier error, your soultion solved it

    -Navicerts
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: MongoDB Object-Document Mapper for NodeJS

    NodeJS (JavaScript on the server) is awesome, but some developers get confused about NoSQL when it comes to working in Node with MongoDB (NoSQL database). Do you need a better explanation of how to use Node.js with MongoDB? The most popular choice is the Mongoose library.

    Suggested Solutions

    Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

    845 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now