2012/08/31 : 更新了我的帖子
在整个网络上搜索它,找到了一些碎片,但没有任何帮助,所以我求助于你。
环境的相关资料:
编程语言是 VBA / Access 2003
将从现有的“.ini”文件中读取数据
数据应插入 Access 数据库
现在我的问题:
我有一个 ini 文件,其中包含 ini 文件中的信息。该文件看起来像这样:
[product_details]
product_description=my product description
product_name=my product
product_price=11.0
product_sku=myproduct2012
这些信息保存在“products.ini”中,当在记事本或记事本++中打开时,它将正确显示并可以插入到我的访问数据库中,我可以在我的表单中显示这些信息
但现在有人想要这样的东西:
[product_details]
product_description=мое описание продукта
product_name=мой продукт
product_price=11.0
product_sku=произведение2012
当通过 GetINIValue 加载这些信息时,值将作为不可读的文本保存到数据库中。
编辑:也在记事本/记事本++中显示正确,因此西里尔字符被正确传输到ini文件中
我真的尝试了很多东西(使用 UNICODE 版本的 GetINIValue,获取字符代码等,检查西里尔文文本)没有任何帮助。
它应该做什么:无论是什么语言,我都需要帮助才能从这个 ini 条目中获取值(在这种情况下,英语、德语、法语、俄语就足够了)
希望有人可以帮助我。
编辑:我已经尝试了 Remou 的测试,通过以下代码和平打开它:
Dim SQL As String
Dim strValue As String
strValue = GetValueOf("product_details","product_description","C:\cyrillic.txt")
SQL = "UPDATE [products] SET [product_description]='" & strValue & "' WHERE [product_id]=23;"
CurrentDb.Execute SQL,dbseechanges
这是我的函数代码,用于读出我需要的特定行:
Public Function GetValueOf(ByVal Section As String, ByVal Entry As String, ByVal File As String)
Dim fs As New FileSystemObject
Dim ts As TextStream
Dim temp As String
Dim response As String
Dim intresponses As String
Dim SectionFoundBegin As Boolean
Dim SectionFoundEnd As Boolean
Dim DoNext As Boolean
Dim Parse() As String
Dim Finished As Boolean
SectionFoundBegin = False
SectionFoundEnd = False
Set ts = fs.OpenTextFile(File, ForReading, , TristateTrue)
response = ""
intresponses = 1
Finished = False
Do
DoNext = False
temp = ts.ReadLine
If (Not Finished) Then
If (temp = "[" & Section & "]") And Not DoNext Then
SectionFoundBegin = True
DoNext = True
End If
If ((InStr(1, temp, "[") > 0) And (SectionFoundBegin)) And Not DoNext Then
SectionFoundEnd = True
DoNext = True
End If
If (SectionFoundBegin And Not SectionFoundEnd) And Not DoNext Then
If (InStr(1, temp, "=") > 0) Then
Parse = Split(temp, "=")
If (Parse(0) = Entry) Then
While (intresponses <= UBound(Parse))
response = response + Parse(intresponses)
intresponses = intresponses + 1
Wend
DoNext = True
Else
DoNext = True
End If
Else
DoNext = True
End If
End If
End If
Loop Until ts.AtEndOfStream
GetValueOf = response
End Function
我需要什么:像:
"UPDATE [products] SET [product_description]='мое описание продукта' WHERE [product_id]=23;"
我得到什么:
"UPDATE [products] SET [product_description]='??? ???????? ????????' WHERE [product_id]=23;"
更新:现在我真的是你的帮助:
我已插入以下代码:
Public Function GetUnicodeValueOf(ByVal Section As String, ByVal Entry As String, ByVal File As String)
Dim fs As Object
Dim ts As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim temp As String
Dim strResponse As String
Dim intResponses As Integer
Dim SectionFoundBegin As Boolean
Dim SectionFoundEnd As Boolean
Dim DoNext As Boolean
Dim Parse() As String
Dim Finished As Boolean
On Error GoTo Error_GetUnicodeValueOf
SectionFoundBegin = False
SectionFoundEnd = False
Set ts = fs.OpenTextFile(File, ForReading, , TristateTrue)
strResponse = ""
intResponses = 1
Finished = False
Do
DoNext = False
temp = ts.ReadLine
If (Not Finished) Then
If (temp = "[" & Section & "]") And Not DoNext Then
SectionFoundBegin = True
DoNext = True
End If
If ((InStr(1, temp, "[") > 0) And (SectionFoundBegin)) And Not DoNext Then
SectionFoundEnd = True
DoNext = True
End If
If (SectionFoundBegin And Not SectionFoundEnd) And Not DoNext Then
If (InStr(1, temp, "=") > 0) Then
Parse = Split(temp, "=")
If (Parse(0) = Entry) Then
While (intResponses <= UBound(Parse))
strResponse = strResponse + Parse(intResponses)
intResponses = intResponses + 1
Finished = True
Wend
DoNext = True
Else
DoNext = True
End If
Else
DoNext = True
End If
End If
End If
Loop Until ts.AtEndOfStream
Exit_GetUnicodeValueOf:
GetUnicodeValueOf = strResponse
Exit Function
Error_GetUnicodeValueOf:
ActionLogging "Fehler beim Parsen der Datei '" & File & "'"
Resume Exit_GetUnicodeValueOf
End Function
通过在我的硬盘上使用这个文件(保存为 UTF-8 没有 BOM):
[product_details]
manufacturer_name=
product_id=50
sku=BU-01722
set=4
type=simple
type_id=simple
color=11
ean=
name=Колесникова
description=[LANGTEXT] Колесникова Е.В Я считаю до двадцати [Рабочая тетрадь] 6-7л
short_description=[KURZTEXT] Колесникова Е.В
old_id=
weight=1.0000
news_from_date=
news_to_date=
status=1
url_key=kolesnikova
url_path=kolesnikova.html
visibility=4
gift_message_available=2
required_options=0
has_options=0
image_label=
small_image_label=
thumbnail_label=
created_at=2012-06-25 07:58:29
updated_at=2012-07-27 09:06:24
price=2.0000
special_price=
special_from_date=
special_to_date=
cost=
tax_class_id=2
minimal_price=
enable_googlecheckout=1
meta_title=
meta_keyword=
meta_description=
is_recurring=0
recurring_profile=
custom_design=
custom_design_from=
custom_design_to=
custom_layout_update=
page_layout=
options_container=container2
我需要:
[LANGTEXT] Колесникова Е.В Я считаю до двадцати [Рабочая тетрадь] 6-7л
来自 INI 键:描述
进入我的访问数据库。
首先它可以正常工作,但现在当我加载一个用“TriStateTrue”保存的文件时,一切都结束了:???????????????????????? ????????????????????? 在一行中。
使用 TriStateMixed,除了像 КолеÑникова Е.Ð' Я Ñчитаю до двадца ти [Ð Ð°Ð±Ð¾Ñ‡Ð°Ñ Ñ‚ÐµÑ‚Ñ€Ð°Ð´ÑŒ] 6-7л
我搜索了源代码并没有发现错误。
FILE is UTF-8 without BOM (coming from selfwritten Web API for Magento)
Using Access 2003
Need to get Cyrillic Text into my Database where also German / English Texts could be inside the File