Re: Converting a string

Hugh Brown <[email protected]> Wed, 5 Sep 2007 07:18:25 -0700
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
Encode the entire command string in the database as hexadecimal. Then this:
    Chr(27) P  Chr(13) Chr(10)
becomes:
    1B 50 0D 0A
and everything is representable in simple ASCII.

"Knowlton, Gerald F." <[email protected]> wrote: Good morning everyone.

      Here is the problem that I have. I have this application which
will control weighing scales through a commport. There are many
different scales at this facility so I can't hard code into the
application the parameters of the currently attached scale.

So in an Oracle (we use Oracle here) table, I have the commands for the
many different type of scales we have and there is no problem for us to
automatically identify the type of scale. Thus we have the ability to be
able to get from the database, the commands needed to tare, standardize,
weigh and etc functions.

The problem is that for the most part, each command (but not all)
require some type of unprintable character(s) in the command string.
Most are the ESC key - ASCII 27. So in the database, we have the
following command  "CHR(27) & ""P"" & CHR(13) & CHR(10)" for one type of
scale. This command  will cause the scale to transmit the value on the
scale's display back to the application.

So if I hard code the command into the application such as:

Public Sub SendWeighCommand()
        Dim ScaleCommand as string = chr(27) & "P" & chr(13) & chr(10)
        Dim Weight as string
      Weight = ReadScale(ScaleCommand)
End sub

Public function ReadScale(Command) as Double

        'Return scale value

End function

This will work us fine because the chr(27),10 and 13 get translated into
unprintable characters. They look something like a square.

But since I am getting the command string from the Oracle database,
everything is enclosed in quotes and the chr 27, 10 , and 13 do not
convert to the unprintable characters.

Public Sub SendWeighCommand()
        Dim ScaleCommand as string =
        Dim Weight as string
      Weight = ReadScale(ScaleCommand)
End sub

Public function ReadScale(Command) as Double

        'Return scale value

End function

Hence the ScaleCommand would pass the following string " chr(27) & ""P""
& chr(13) & chr(10)" instead of the "P" along with the unprintable
characters.

I thought I could use the CallByName function so the string would
translate but it appears that this is not so.

Are there any other solutions to this problem of getting the translation
of an Oracle string value?

Please embarrass me with a really simple solution!!!

Best regards,


Jerry Knowlton