Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Urgent Help on VB6 chr$() to C#

Posted on 2004-10-15
7
Medium Priority
?
2,451 Views
Last Modified: 2012-06-21
Dear all,

I'm using VB6 need to convert to C# for printing. In VB6 I will send some printer command into the printer as below:-

Printer.Print "TESTING LINE 1"
Printer.Print "TESTING LINE 2"
Printer.Print Chr$(&H1C); "(L"; Chr$(66); Chr$(49);
Printer.Print Chr$(&H1D); "V"; Chr$(49);
Printer.Print Chr$(&H1C); "(L"; Chr$(67); Chr$(50);

In C# I'm writing a text file and open LPT1 to print some lines, the problem is how to convert those VB6 codes into C# ?

I've try using some sample code as below :-

writer.WriteLine ("TESTING LINE 1" + ((char) 13));
writer.WriteLine ("TESTING LINE 2" + ((char) 13));
writer.WriteLine( ((char)&H1C) + "(L" + ((char)66) +  ((char)49));
writer.WriteLine( ((char)&H1D) + "V" + ((char)49));
writer.WriteLine( ((char)&H1C) + "(L" + ((char)66) +  ((char)49));


But there are errors on '&H1C', '&H1D' on the above codes.

If I use VB6 to print it will print the "(L" character out when I'm using VB6 to print. How to resolve this as well ?

Please provide solutions and examples.


Thanks in advance


Cheers,
yymae
0
Comment
Question by:yymae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:Tasneem
ID: 12317409
Casting does not work in all cases as C# uses Unicode! You need to be aware of this when using strings that were created in VB. Fortunately, MS included Microsoft.VisualBasic.Strings, which has the Chr() and Asc() function calls.
Something like
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            e.Handled = False
            MsgBox("You pressed Enter.")
            Exit Sub
        End If

OR
Chr System.Char.GetNumericValue(char)
Asc System.Char.Parse(String)
 
 
0
 
LVL 10

Expert Comment

by:smegghead
ID: 12318606
Hello,

I wouldn't use the VisualBasic namespace, when C# can deal with this in it's own way.

Use

      Console.WriteLine("Hello\x41There");

This will produce the results

HelloAThere

Becuase hex 41='A'

\x is the escape sequence for hex

Smg.
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12321774
&H1C is a hex constant in basic. 0x1C would be the same hex constant in C#. Just replace &H with 0x.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 12339486
writer.WriteLine("TESTING LINE 1");
writer.WriteLine("TESTING LINE 2");
writer.WriteLine(Chr(28) + "(L" + Chr(66) + Chr(49));
writer.WriteLine(Chr(29) + "V" + Chr(49));
writer.WriteLine(Chr(28) + "(L" + Chr(67) + Chr(50));

Bob
0
 
LVL 10

Accepted Solution

by:
smegghead earned 300 total points
ID: 12339591
Or.. (without using the VB compatibility)

writer.WriteLine ("TESTING LINE 1\x0d");
writer.WriteLine ("TESTING LINE 2\x0d");
writer.WriteLine("\x1c(L\x42\x31");
writer.WriteLine("\x1dV\x31");
writer.WriteLine("\x1c(L\x42\x31");
0
 
LVL 10

Expert Comment

by:smegghead
ID: 12419558
Thanks for accepting my answer, but why just a grade 'C' ?? was the answer missing something ?

Smg.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

705 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