I have some russian strings in Access (2000 Version and no way to upgrade, sorry, and VBA isn't my biggest strength)
Exporting those tables to excel works fine, but I can't manage to export in a script to a flat text file, instead I get the dreaded ??????????.
Is there a way to do it?
Although I developed the following code, I could not get it to work as required for the simple reason that VBA doesn't handle storing the data - even though it can be stored in a Memo field as your database shows : - Option Compare Database
-
Option Explicit
-
-
Private lngFilePos As Long
-
-
Public Function ExportUTF()
-
Dim strFileName As String, strOut As String
-
Dim intFileNo As Integer
-
Dim cdb As DAO.Database
-
Dim cField As DAO.Field
-
-
Set cdb = CurrentDb()
-
strFileName = "C:\output.txt"
-
intFileNo = FreeFile()
-
Open strFileName For Binary Access Read Write Lock Write As #intFileNo
-
With cdb.OpenRecordset("TextIdSubLand")
-
' loop thorugh each record in the table
-
Call .MoveFirst
-
lngFilePos = 1
-
Do Until .EOF
-
' loop through each field in each record
-
varOut = ""
-
For Each cField In .Fields
-
varOut = varOut & ";" & cField
-
Next cField
-
varOut = Mid(varOut, 2) & vbNewLine
-
Call WriteString(intFileNo, varOut)
-
Call .MoveNext
-
Loop
-
Call .Close
-
End With
-
Close #intFileNo
-
End Function
-
-
Private Sub WriteString(intFileNo As Integer, varData As Variant)
-
Dim intIx As Integer, intData As Integer
-
-
For intIx = 1 To Len(varData)
-
intData = Asc(Mid(varData, intIx))
-
Put #intFileNo, lngFilePos, intData
-
lngFilePos = lngFilePos + 2
-
Next intIx
-
End Sub
Other than the fact that it doesn't have the data to work with though, the code works perfectly. It produces a correctly formatted Unicode file as long as no characters requiring Unicode are included in the output - LoL.
All that said, the job is quite easily accomplished by doing a simple export to text. Simply select the ";" as a delimiter char and set the Code Page to Unicode in the Advanced section. The file it creates appears to be exactly what you want.
15 6774 NeoPa 32,556
Expert Mod 16PB
Excuse my ignorance, but doesn't ?????????? indicate that the data is in Unicode but the application or system doesn't recognise it?
Yes, I can export my data to xls and get the right characters, so data is unicode.
It's just exporting to a text file with VBA that causes trouble.
NeoPa 32,556
Expert Mod 16PB
Let me try to put this in simpler terms as you don't seem to be following what I'm trying to say :
What is it that makes you think the trouble is with the outputting of the data from VBA and not the interpreting of the data in the file by whatever you are using to view the data afterwards?
Ah, I get your point.
in the current minimum script I just read out the contents of all fields in all rows of a table and write that to a text file.
The result is ANSI, with multibyte characters as hexvalue 3F.
NeoPa 32,556
Expert Mod 16PB havanna:
The result is ANSI, with multibyte characters as hexvalue 3F.
The result is actually a file with a sequence of bits. How those bits are interpreted depends on the application you choose to view them with. Are you using NotePad?
I haven't really used Unicode much I must admit, but I did have a look and found that when I saved the same data ("22 ") as both ANSI and Unicode, the only difference was the data saved. When I took out the extra Unicode-specific data with a hex editor the file was recognised as simple ANSI. NeoPa 32,556
Expert Mod 16PB
Maybe we need to have a look at your code if it's not too large. Please post what you have for the Excel export as well as that for the Text export and we'll see if we can spot any problems.
I'm using scite for viewing, that can handle both codings and checked with a hex editor.
Access exports tables as excel directly, there are no options to set.
For text export I use the Cinergy Script attached.
There are several conversions made here wich may have extra effects, but I have tried with the simplest possible (just pseudocode)
Then Open testfile.txt For Output As #5
with mytable
loop through rows
loop trhough fields
print #5, table.row.field.value
endloop
endloop
close #5
It just writes standard ANSI, ? (0x32) , one byte, no multibite characters.
NeoPa 32,556
Expert Mod 16PB
I'm sorry, but as an Access expert I don't provide support for third party software (I'm not able to as my expertise is in Access). If you want help using Cynergi code then you may be better advised to look for a specific Cynergi forum somewhere. I do not propose to debug and test 680 lines of code for you without even the benefit of your original environment.
As for the actual VBA code you are referring to (in your pseudo-code I think), I can't see it as you posted something else instead (I have no idea why as I asked to see your code). Please refer back to post #7 as that still stands. I can check for problems in VBA code, but I couldn't possibly do that with pseudo-code could I?
By the way, it may be a good idea for you to put your current database aside for now and create a new (very small/basic) one solely for the purpose of getting a good grip on the Unicode issue. That way, instead of needing to send hundreds of lines of code if we need to share code, you can send only the relevant code and save loads of time and effort.
Sorry, didn't mean to ask 3rd party support - and thanks for your being willing to help at all!
I've done that, mdb with just one table containing minimum data including some udf strings (russian).
I've reduced the script to just read fields and put contents into a file.
The mdb is attached as zip, also the output.txt file made by the vba module
maybe you know how to make the script deal with unicode: - Public Function exportutf()
-
-
Dim ctablename As String
-
Dim cfieldix As Integer, cfieldname As String
-
Dim fieldlst As String, sqlcode As String
-
Dim crs As DAO.Recordset
-
Dim cdb As database
-
Dim Output As String
-
-
Set cdb = CurrentDb()
-
Open "C:\output.txt" For Output As #1
-
Set crs = cdb.OpenRecordset("TextIdSubLand")
-
' loop thorugh each record in the table
-
crs.MoveFirst
-
Do Until crs.EOF
-
' loop through each field in each record
-
For cfieldix = 0 To crs.Fields.Count - 1
-
Output = Output & crs.Fields(cfieldix).Value & ";"
-
Next cfieldix
-
-
Output = Output & "\n"
-
-
Print #1, Output
-
crs.MoveNext
-
Output = ""
-
Loop
-
Close #1
-
cdb.Close
-
End Function
-
-
Output = Output & "\n"
-
-
Print #1, Output
-
crs.MoveNext
-
Output = ""
-
Loop
-
-
Close #1
-
-
cdb.Close
-
-
End Function
NeoPa 32,556
Expert Mod 16PB
That's a good response Havanna. There appears to be some strange extra code at the end of (after) your procedure, but I expect that was an oversight. CODE tags are required here and they may have made that more obvious when you posted but never mind this time.
Actually, if you are trying to create C:\output.txt as a Unicode file, then I think I can help you. It may not be today as you just missed the window (I need to go and play football shortly and get prepared before that), but this approach is perfectly viable, although will probably require some advanced and detailed understanding of working directly with Binary files from VBA (Luckily I have that understanding and some experience in that area). We won't be using Print#, but Put# instead. More to follow.
NeoPa 32,556
Expert Mod 16PB
Although I developed the following code, I could not get it to work as required for the simple reason that VBA doesn't handle storing the data - even though it can be stored in a Memo field as your database shows : - Option Compare Database
-
Option Explicit
-
-
Private lngFilePos As Long
-
-
Public Function ExportUTF()
-
Dim strFileName As String, strOut As String
-
Dim intFileNo As Integer
-
Dim cdb As DAO.Database
-
Dim cField As DAO.Field
-
-
Set cdb = CurrentDb()
-
strFileName = "C:\output.txt"
-
intFileNo = FreeFile()
-
Open strFileName For Binary Access Read Write Lock Write As #intFileNo
-
With cdb.OpenRecordset("TextIdSubLand")
-
' loop thorugh each record in the table
-
Call .MoveFirst
-
lngFilePos = 1
-
Do Until .EOF
-
' loop through each field in each record
-
varOut = ""
-
For Each cField In .Fields
-
varOut = varOut & ";" & cField
-
Next cField
-
varOut = Mid(varOut, 2) & vbNewLine
-
Call WriteString(intFileNo, varOut)
-
Call .MoveNext
-
Loop
-
Call .Close
-
End With
-
Close #intFileNo
-
End Function
-
-
Private Sub WriteString(intFileNo As Integer, varData As Variant)
-
Dim intIx As Integer, intData As Integer
-
-
For intIx = 1 To Len(varData)
-
intData = Asc(Mid(varData, intIx))
-
Put #intFileNo, lngFilePos, intData
-
lngFilePos = lngFilePos + 2
-
Next intIx
-
End Sub
Other than the fact that it doesn't have the data to work with though, the code works perfectly. It produces a correctly formatted Unicode file as long as no characters requiring Unicode are included in the output - LoL.
All that said, the job is quite easily accomplished by doing a simple export to text. Simply select the ";" as a delimiter char and set the Code Page to Unicode in the Advanced section. The file it creates appears to be exactly what you want.
That indeed produced a unicode file (I don't understand your statemend: I could not get it to work as required for the simple reason that VBA doesn't handle storing the data).
It works perfectly with my data - and delivers unicode-formatted "?"
But of course the last hint, text export with correct codepage is what really does it, thanks a lot :-)
NeoPa 32,556
Expert Mod 16PB Havanna:
It works perfectly with my data - and delivers unicode-formatted "?"
Indeed. That's what I got too.
The code produces a correctly formatted file, but the unicode data that is stored in the Memo field is translated to non-unicode compatible characters as soon as it's assigned to a string variable (I also tried with a Variant variable by the way which gave the same results). The code sort of works, but the results are useless because VBA can't store the data.
I figured the Export to text would do the trick though. I assume you know all about how to automate that? If not then let me know. It's easily handled.
Yes, thank you. Automating my export with DoCmd.TransferText is no problem. Further Processing I can handle at the receiving end, ti's just some extra code I hoped to avoid.
NeoPa 32,556
Expert Mod 16PB Havanna:
Further Processing I can handle at the receiving end, it's just some extra code I hoped to avoid.
I don't follow. I was only aware of wanting to produce the file. If there is more required for the whole process why not post another question for it and we'll see if we can't help with that too.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jonathon Blake |
last post by:
All:
Question
Python is currently Unicode Compliant.
What happens when strings are read in from text files that were
created using GB 2312-1980, or KPS 9566-2003, or other, equally...
|
by: Andrew L |
last post by:
Hello all,
What strategy should I use in solving the following problem? I have a list
of unicode strings which I would like to compare with its English language
'equivalent.' eg
"reykjavík"...
|
by: Neil Schemenauer |
last post by:
python-dev@python.org.]
The PEP has been rewritten based on a suggestion by Guido to change
str() rather than adding a new built-in function. Based on my
testing, I believe the idea is...
|
by: Jamie |
last post by:
I have a file that was written using Java and the file has unicode
strings. What is the best way to deal with these in C? The file
definition reads:
Data Field Description
CHAR File...
|
by: srikant |
last post by:
I am writing a client in C# that needs to communicate over the network to a legacy C++ application that uses Unicode strings. I realize that C# strings are already in Unicode, however, how do I...
|
by: Fuzzyman |
last post by:
Hello all,
Can someone confirm that compiled regular expressions from ascii
strings will always (and safely) yield unicode values when matched
against unicode strings ?
I've tested it and it...
|
by: Dennis Benzinger |
last post by:
Hi!
The following program in an UTF-8 encoded file:
# -*- coding: UTF-8 -*-
FIELDS = ("Fächer", )
FROZEN_FIELDS = frozenset(FIELDS)
FIELDS_SET = set(FIELDS)
|
by: Tom Plunket |
last post by:
I am building a file with the help of the struct module.
I would like to be able to put Unicode strings into this file, but I'm
not sure how to do it.
The format I'm trying to write is...
|
by: Anthony Baxter |
last post by:
SECURITY ADVISORY
Buffer overrun in repr() for UCS-4 encoded unicode strings
http://www.python.org/news/security/PSF-2006-001/
Advisory ID: PSF-2006-001
Issue Date: October 12, 2006...
|
by: Alexey Moskvin |
last post by:
Hi!
I have a set of strings (all letters are capitalized) at utf-8,
russian language. I need to lower it, but
my_string.lower(). Doesn't work.
See sample script:
# -*- coding: utf-8 -*-
s1 =...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |