Results 1 to 3 of 3

Thread: System.Text.Encoding.ASCII not declared

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    System.Text.Encoding.ASCII not declared

    Hi,

    I've used a sample code to create an RS232 connection in my application.

    My problem is with this line:
    m_CommPort.Write(Encoding.ASCII.GetBytes(Me.cbGPSSentence.Text & Chr(13)))

    The Encoding (underlined) is coming up as undeclared. I know where the namespace is, but not too sure how to declare it?

    It works fine without any visible declaration in the original app.

    Any pointers?

    Thanks
    RudeYute

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: System.Text.Encoding.ASCII not declared

    Encoding is in the Text namespace (which is off of system)

    You really answered your own question in your thread title..

    simply use "System.Text.Encoding.ASCII" and not just "Encoding.ASCII"

    If you want to shorten your code a bit, you can use an imports at the very top (above the class declaration)
    VB Code:
    1. 'at top
    2. Imports System.Text.Encoding
    3.  
    4. 'in code
    5. m_CommPort.Write(ASCII.GetBytes(Me.cbGPSSentence.Text & Chr(13)))

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: System.Text.Encoding.ASCII not declared

    Hmm, I tried importing it at the top but that didn't work.
    But your method did work (I'm sure I read that somewhere before too - I'm such an idiot!)

    Cheers
    RudeYute

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width