Results 1 to 9 of 9

Thread: Passing foreign language strings to a C# program

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    433

    Passing foreign language strings to a C# program

    I have a VB6-C# related issue.

    I have an VB6 program and an C# program.

    My C# program have to take over several strings, which is foreign language, from VB6 program.

    I want to use some file but cannot use text file because it doesn't keep the original foreign language text.

    Which format do I use to transfer string between VB6 and C# program?
    If I explain in detail, it'll be like following.
    --------------------------------------------------
    VB6 program have following table.
    English German(or other foreign language)
    ------- ------------
    Setting Einstellung
    Close Zu Schließen
    Cancel Rückgängig Machen
    This window will be closed Das Fenster wird geschlossen
    . .
    . .

    I want to send these English-Foreign language pair to the C# so that C# can use it.
    --------------------------------------------------
    Last edited by jdy0803; Mar 12th, 2015 at 07:20 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Passing foreign language strings to a C# program

    Can you not have a table in the C# program that has the translations so the VB6 app sends "This window will be closed" and the C# app will look that up in a table and find the German translation "Das Fenster wird geschlossen"


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: Passing foreign language strings to a C# program

    Quote Originally Posted by jdy0803 View Post
    Which format do I use to transfer string between VB6 and C# program?
    It appears that VB6's String data type and .NET's String Class are both using UTF-16 encoding, so it's probably not necessary to convert anything. The only thing left you'll have to worry about is how to retrieve the string's data. In a previous thread of yours, I suggested a link to a VB6 CodeBank thread that offered a rather simple solution using the WM_SETTEXT message. If you do decide to try it out, just make sure that you use the Unicode version of the SendMessage function (i.e. SendMessageW).

    Quote Originally Posted by jdy0803 View Post
    I want to use some file but cannot use text file because it doesn't keep the original foreign language text.
    That's probably because the text file isn't encoded in any of the possible Unicode formats (e.g. UTF-16 LE, UTF-8, etc.).
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,436

    Re: Passing foreign language strings to a C# program

    If text file I/O meets your needs then you merely need to get slightly creative. VB6's native text I/O also performs conversion to and from ANSI, so you'd probably want to use UTF-16/UCS-2, the normal Windows "Unicode."

    I can think of at least 3 easy ways to do this. But be aware that on a Windows system such "Unicode" text is normally presumed to have a Byte Order mark header to identify the encoding as such. Here is a dump of the beginning of such a file that shows this header:

    Name:  dump.jpg
Views: 102
Size:  18.6 KB

    Blurring (dis)courtesy of VBForums' banal conversion to JPEG


    The attached demo program uses InkEdit controls as a handy Unicode-aware VB6 TextBox. This means the demo requires Windows Vista or later (or Windows XP with Tablet PC Platform Software Development Kit (SDK) v1.5 installed).

    The demo loads a Unicode resource into the upper InkEdit control when it starts. This can be edited as desired, and then via the menu you can save the text to disk in Unicode any of 3 ways. Once saved, you can load the text back from disk into the lower InkEdit control in any of 3 ways:

    Name:  sshot.png
Views: 129
Size:  8.9 KB


    Beyond that you could resort to file I/O API calls or use any of a multitude of 3rd party I/O libraries. But VB6 and Windows already offer some pretty easily used tools that have been around for a very long time.
    Attached Files Attached Files

  5. #5
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,057

    Re: Passing foreign language strings to a C# program

    Quote Originally Posted by dilettante View Post
    Blurring (dis)courtesy of VBForums' banal conversion to JPEG
    (Off-topic!)

    There is a workaround to prevent VBForums from down-sizing and converting image attachments wider than 600 pixels to JPEGs - see Re: Image Test - Using [IMG] tags WITH inline attachments!

    The idea is to change the desired image's file extension to something that the forum allows and attach it to a post inline. After the image has been successfully attached, it can now be referenced via the [IMG]<Insert URL of image attachment here>[/IMG] tag. Note that this can only be done by going to the advanced editor mode.
    Last edited by Bonnie West; Mar 13th, 2015 at 06:15 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,436

    Re: Passing foreign language strings to a C# program

    Thanks for the input.

    I'd rather see them fix the broken forum software than keep trying to jump spinning into the air with a finger in one ear and another up my nose and then landing balanced on one elbow.

    We put up with far too much inconvenience here already.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    433

    Re: Passing foreign language strings to a C# program

    The reason why I want to have VB6 save and C# read is that VB6 has 2000line of english-foreign language table and C# needs only 10~15 lines of the original language table.
    I thought it's not good to read 1000~2000 lines of string to use 10~15 line of string.
    So I want to have VB6 extract only lines C# needs and save as some file format and invoke C# program, and C# read that table, parse it and use the corresponding foreign language text.
    This is my scenario.
    When storing strings to disk-either to text or binary files-VB6 automatically converts them from Unicode to ANSI.
    My point of question is how to save as unbroken format(Unicode format)
    Last edited by jdy0803; Mar 13th, 2015 at 11:24 AM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2012
    Posts
    433

    Re: Passing foreign language strings to a C# program

    OK I decided to use EXCEL file.
    VB6 app read page1(sheet1), extract texts which will be used in the C# app, save it to sheet2.
    C# will read sheet2.
    This will solve my problem.

    Thanks,

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,436

    Re: Passing foreign language strings to a C# program

    Seriously, if you can't figure out how to use one of the three ways I already showed you for reading and writing Unicode text files you're in pretty bad shape.

    I can't imagine how running everything through automated instances of Excel makes any sense as a solution. You might as well charter a 50-seat bus to go shop at the corner store.

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