Save A File As Unicode - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Save A File As Unicode

sad.boysad.boy Posts: 90Member
i want to write some ascii codes to a .txt file and i opened
"c:
eo.txt" for it ,it was working fine but there is a problem:
some ascii charactars like ☺ ☻ ♥ ♦ ♣ ◘ are presented with ???with a little
aquare instead of these! i noticed it's because i save the file as Ansi,
i know in the saving dialog i can change it to Unicode but how can i do this in Vb?
check this code out:
[code]
Private Sub Command1_Click()
Open "c:
eo.txt" For Output As #1

For i = 1 To 255


If Chr(i) <> "" And i <> 160 Then Print #1, Chr(i)

Next i
close(1)
End Sub
[/code]
as you see there is now saving dialog and all the saving process is done
by clicking on command1. now what should i do to save it as unicode?

Comments

  • infidelinfidel Posts: 2,900Member
    : i want to write some ascii codes to a .txt file and i opened
    : "c:
    eo.txt" for it ,it was working fine but there is a problem:
    : some ascii charactars like ☺ ☻ ♥ ♦ ♣ ◘ are presented with with a little
    : aquare instead of these! i noticed it's because i save the file as Ansi,
    : i know in the saving dialog i can change it to Unicode but how can i do this in Vb?
    : check this code out:
    : [code]
    : Private Sub Command1_Click()
    : Open "c:
    eo.txt" For Output As #1
    :
    : For i = 1 To 255
    :
    :
    : If Chr(i) <> "" And i <> 160 Then Print #1, Chr(i)
    :
    : Next i
    : close(1)
    : End Sub
    : [/code]
    : as you see there is now saving dialog and all the saving process is done
    : by clicking on command1. now what should i do to save it as unicode?

    Well, first off, those characters *aren't* ascii characters. ASCII only goes up to 128. I suppose that if you opened the file in binary mode you could write the unicode bytes to it yourself, but that seems like it would be fairly complicated. I think you can use ADODB Stream objects to store unicode-encoded streams and write them to files, but I'm not positive on that.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • sad.boysad.boy Posts: 90Member
    : : i want to write some ascii codes to a .txt file and i opened
    : : "c:
    eo.txt" for it ,it was working fine but there is a problem:
    : : some ascii charactars like ☺ ☻ ♥ ♦ ♣ ◘ are presented with ??? with a little
    : : aquare instead of these! i noticed it's because i save the file as Ansi,
    : : i know in the saving dialog i can change it to Unicode but how can i do this in Vb?
    : : check this code out:
    : : [code]
    : : Private Sub Command1_Click()
    : : Open "c:
    eo.txt" For Output As #1
    : :
    : : For i = 1 To 255
    : :
    : :
    : : If Chr(i) <> "" And i <> 160 Then Print #1, Chr(i)
    : :
    : : Next i
    : : close(1)
    : : End Sub
    : : [/code]
    : : as you see there is now saving dialog and all the saving process is done
    : : by clicking on command1. now what should i do to save it as unicode?
    :
    : Well, first off, those characters *aren't* ascii characters. ASCII only goes up to 128. I suppose that if you opened the file in binary mode you could write the unicode bytes to it yourself, but that seems like it would be fairly complicated. I think you can use ADODB Stream objects to store unicode-encoded streams and write them to files, but I'm not positive on that.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :
    what's the easiest way i can do this?whith any character saving (utf8,unicode) no matter,i just want all of my characters get saved!
    any ideas?
  • BarkeeperBarkeeper Posts: 335Member
    : : : i want to write some ascii codes to a .txt file and i opened
    : : : "c:
    eo.txt" for it ,it was working fine but there is a problem:
    : : : some ascii charactars like ☺ ☻ ♥ ♦ ♣ ◘ are presented with ??? with a little
    : : : aquare instead of these! i noticed it's because i save the file as Ansi,
    : : : i know in the saving dialog i can change it to Unicode but how can i do this in Vb?
    : : : check this code out:
    : : : [code]
    : : : Private Sub Command1_Click()
    : : : Open "c:
    eo.txt" For Output As #1
    : : :
    : : : For i = 1 To 255
    : : :
    : : :
    : : : If Chr(i) <> "" And i <> 160 Then Print #1, Chr(i)
    : : :
    : : : Next i
    : : : close(1)
    : : : End Sub
    : : : [/code]
    : : : as you see there is now saving dialog and all the saving process is done
    : : : by clicking on command1. now what should i do to save it as unicode?
    : :
    : : Well, first off, those characters *aren't* ascii characters. ASCII only goes up to 128. I suppose that if you opened the file in binary mode you could write the unicode bytes to it yourself, but that seems like it would be fairly complicated. I think you can use ADODB Stream objects to store unicode-encoded streams and write them to files, but I'm not positive on that.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    : :
    : what's the easiest way i can do this?whith any character saving (utf8,unicode) no matter,i just want all of my characters get saved!
    : any ideas?
    :
    i remember a function called StrConv(MyString, vbUnicode/vbToUnicode) or something like that.......

    but maybe that's either my imagination or it was in Bruce McKinney's HArdcore VB-TypeLib.....
    ------------------------------------------
    Only stupidity of mankind and the universe
    are infinite, but i'm not sure concerning
    the universe. A. Einstein

  • sad.boysad.boy Posts: 90Member
    : : : : i want to write some ascii codes to a .txt file and i opened
    : : : : "c:
    eo.txt" for it ,it was working fine but there is a problem:
    : : : : some ascii charactars like ☺ ☻ ♥ ♦ ♣ ◘ are presented with ???with a little
    : : : : aquare instead of these! i noticed it's because i save the file as Ansi,
    : : : : i know in the saving dialog i can change it to Unicode but how can i do this in Vb?
    : : : : check this code out:
    : : : : [code]
    : : : : Private Sub Command1_Click()
    : : : : Open "c:
    eo.txt" For Output As #1
    : : : :
    : : : : For i = 1 To 255
    : : : :
    : : : :
    : : : : If Chr(i) <> "" And i <> 160 Then Print #1, Chr(i)
    : : : :
    : : : : Next i
    : : : : close(1)
    : : : : End Sub
    : : : : [/code]
    : : : : as you see there is now saving dialog and all the saving process is done
    : : : : by clicking on command1. now what should i do to save it as unicode?
    : : :
    : : : Well, first off, those characters *aren't* ascii characters. ASCII only goes up to 128. I suppose that if you opened the file in binary mode you could write the unicode bytes to it yourself, but that seems like it would be fairly complicated. I think you can use ADODB Stream objects to store unicode-encoded streams and write them to files, but I'm not positive on that.
    : : :
    : : :
    : : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : : :
    : : : [code]
    : : : $ select * from users where clue > 0
    : : : no rows returned
    : : : [/code]
    : : :
    : : :
    : : what's the easiest way i can do this?whith any character saving (utf8,unicode) no matter,i just want all of my characters get saved!
    : : any ideas?
    : :
    : i remember a function called StrConv(MyString, vbUnicode/vbToUnicode) or something like that.......
    :
    : but maybe that's either my imagination or it was in Bruce McKinney's HArdcore VB-TypeLib.....
    : ------------------------------------------
    : Only stupidity of mankind and the universe
    : are infinite, but i'm not sure concerning
    : the universe. A. Einstein
    :
    :
    ----
    SO What You Do To Save Some Special Characters To A .Txt File???
    not as unicode ,with any algorithm!just a one that uses Vb6

  • infidelinfidel Posts: 2,900Member
    : SO What You Do To Save Some Special Characters To A .Txt File???
    : not as unicode ,with any algorithm!just a one that uses Vb6

    What "special characters" are you talking about? I thought you were showing unicode characters. I figured out how you can read and write unicode in VB using the Microsoft Scripting Runtime reference:

    [code]
    Dim objFileSystem As FileSystemObject
    Dim objStream As TextStream
    Dim strUnicode As String

    Set objFileSystem = New FileSystemObject

    'opening a file with format = TristateTrue opens it as unicode
    Set objStream = objFileSystem.OpenTextFile("C:TEMPunicode.txt", ForReading, False, TristateTrue)
    strUnicode = objStream.ReadAll()
    Call objStream.Close

    'now you can write to a unicode file too
    Set objStream = objFileSystem.OpenTextFile("C:TEMPunicode2.txt", ForAppending, False, TristateTrue)
    Call objStream.Write(strUnicode)
    Call objStream.Close

    Set objStream = Nothing
    Set objFileSystem = Nothing
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • ElroyElroy HoustonPosts: 1Member

    Here, full unicode support in both design mode and during runtime for VB6.
    Complete source code.

    OptionButton
    Checkbox
    Label
    CommandButton
    File I/O
    Clipboard I/O

    Other routines for putting Unicode into the caption of any VB control with a hWnd,
    including forms.

    Just download from here and you're all set:

    http://motionlabresources.org/Unicode%20&%20RTF%20for%20VB6.zip

Sign In or Register to comment.