Re: Converting a string
"Knowlton, Gerald F." <[email protected]> Wed, 5 Sep 2007 10:43:59 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <[email protected]> |
Thank you both Len and Hugh. Good solutions.
While waiting for replies to the post, I did some experimation and
discover that if I did the following, it would solve my problem
Remembering that ScaleCommand is equal to a Oracle string
ScaleCommand = " chr(27) & ""P"" & chr(13) & chr(10)"
Then declare another variable
X = string
We can do the following
X = ScaleCommand.Replace("Chr(27)", chr(27))
X = X.Replace("Chr(13)",chr(13)
And so forth for each unprintable.
The result will be what is needed.
I am now going to look at patterns for a simpler solution. For purposes
of the people who will come after me, Hugh solution might just throw
them for a loop although it is better then the one I presently have
developed.
Thank you once again Gentlemen for coming through for me.
Best regards,
Jerry
-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Hugh Brown
Sent: Wednesday, September 05, 2007 10:18 AM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Converting a string
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