type mismatch with the MID function

Posted on 2006-04-03
Last Modified: 2008-03-10
I cannot figure this out.

I have a string called mmsg. I want to test to see if I have a CRLF as the char and have the code as follows:

dim i
dim mmsg

mmsg = request.form("message")

for i = 1 to len(mmsg)
       if asc(mid(mmsg,i,1)) = 13 then
            response.write blah,blah,blah"
       end if

I keep getting a type mismatch on the line that has the mid(mmsg,i,1) and I know that there is data in mmsg and the len(mmsg) is working correctly because I am able to write out it's contents before I get into the loop.

Any one know why? I am stumped.
Question by:samic400
    LVL 95

    Expert Comment

    by:Lee W, MVP
    Why not just use instr?

    If Instr(Request.form("message"), vbCrLf) > 0 Then
        'A CRLF character was found
    End If

    If you JUST want the CR character, use vbCr
    LVL 13

    Author Comment

    The problem is I need to read the data and if there is a vbCR found, then I need to substitute it with a <br><br> because I am going to store it in a database and if it needs to be read in the future, then I need to have the breaks in the string.
    LVL 95

    Accepted Solution

    No problem... use replace.

    When storing it in the database, reference it as Replace(Request.Form("message"), VbCrLf, "<br><br>")
    LVL 13

    Author Comment

    Thank you. The REPLACE worked great. I appreciate your help. Always is nice to have another person's point of view :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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