- - PR -
全角半角混在データについて
投稿者 | 投稿内容 | ||||
---|---|---|---|---|---|
|
投稿日時: 2008-11-25 16:35
VB初心者です。
VB2005にて、固定長テキストファイルを読み込み、Oracleテーブルを 更新するアプリを作成してます。 全角半角が混在している為、構造体をバイト型で定義し、構造体に 読み込んだデータをエンコードしてから、Oracleテーブルを更新する ように組んでみたのですが、桁ズレを起こしてしまいます。 ソースを載せますので、何かアドバイスを頂ければ幸いです。 【ソース】 Option Explicit On Imports System.IO Module MainModule '構造体宣言 Private Structure MyRecord <VBFixedArray(> Public a() As Byte ←半角 <VBFixedArray(64)> Public b() As Byte ←全角半角混在 <VBFixedArray(20)> Public c() As Byte ←全角半角混在 <VBFixedArray(40)> Public d() As Byte ←全角半角混在 <VBFixedArray(40)> Public e() As Byte ←全角半角混在 <VBFixedArray(301)> Public f() As Byte ←半角 <VBFixedArray(1)> Public crlf() As Byte ←改行コード End Structure Sub Main() Dim accessDB_ As AccessDB Dim i_FileNo2 As Short Dim i_RecNo2 As Short Dim res As Integer Dim ngflg As Integer Dim passwd As String Dim name1 As String Dim name2 As String Dim name3 As String Dim data1 As String Dim data2 As String Dim mTyp_MyRecord As New MyRecord i_FileNo2 = FreeFile() FileOpen(i_FileNo2, "D:\YAKUZAI\RIYOUDL\RIYO.DAT", OpenMode.Random, OpenAccess.Read, OpenShare.Default, Len(mTyp_MyRecord)) i_RecNo2 = 0 Do Until EOF(i_FileNo2) i_RecNo2 = i_RecNo2 + 1 FileGet(i_FileNo2, mTyp_MyRecord, i_RecNo2) data1 = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.a) ← data1を覗くと桁ズレしている passwd = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.b) ← passwdを覗くと桁ズレしている name1 = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.c) ← name1を覗くと桁ズレしている name2 = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.d) ← name2を覗くと桁ズレしている name3 = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.e) ← name3を覗くと桁ズレしている data2 = System.Text.Encoding.GetEncoding("Shift-JIS").GetString(mTyp_MyRecord.f) ← data2を覗くと桁ズレしている res = accessDB_.RIYO_SELECT(data1) If res = 0 Then res = accessDB_.RIYO_INSERT(data1, passwd, name1, name2, name3, data2) Else If res > 0 Then res = accessDB_.RIYO_UPDATE(data1, passwd, name1, name2, name3, data2) If res < 0 Then ngflg = 1 End If Else ngflg = 1 End If End If Loop accessDB_.ExitDB(ngflg) End Sub End Module | ||||
|
投稿日時: 2008-11-25 16:42
構造体が一部文字化けしておりました。
正しくは、以下の通りです。 構造体宣言 Private Structure MyRecord <VBFixedArray(> Public a() As Byte ←半角 <VBFixedArray(64)> Public b() As Byte ←全角半角混在 <VBFixedArray(20)> Public c() As Byte ←全角半角混在 <VBFixedArray(40)> Public d() As Byte ←全角半角混在 <VBFixedArray(40)> Public e() As Byte ←全角半角混在 <VBFixedArray(301)> Public f() As Byte ←半角 <VBFixedArray(1)> Public crlf() As Byte ←改行コード End Structure | ||||
|
投稿日時: 2008-11-25 16:44
再度文字化けしておりました。
すみません。 構造体が一部文字化けしておりました。 正しくは、以下の通りです。 構造体宣言 Private Structure MyRecord <VBFixedArray(> Public a() As Byte ←半角 <VBFixedArray(64)> Public b() As Byte ←全角半角混在 <VBFixedArray(20)> Public c() As Byte ←全角半角混在 <VBFixedArray(40)> Public d() As Byte ←全角半角混在 <VBFixedArray(40)> Public e() As Byte ←全角半角混在 <VBFixedArray(301)> Public f() As Byte ←半角 <VBFixedArray(1)> Public crlf() As Byte ←改行コード End Structure | ||||
|
投稿日時: 2008-11-25 16:47
度々すみません。
再度訂正いたします。 '構造体宣言 Private Structure MyRecord <VBFixedArray(> Public a() As Byte <VBFixedArray(64)> Public b() As Byte <VBFixedArray(20)> Public c() As Byte <VBFixedArray(40)> Public d() As Byte <VBFixedArray(40)> Public e() As Byte <VBFixedArray(301)> Public f() As Byte <VBFixedArray(1)> Public crlf() As Byte End Structure | ||||
|
投稿日時: 2008-11-25 16:48
「この投稿で 顔文字(スマイリー) を使わない」にチェックして投稿すると幸せになれるかも…。 | ||||
|
投稿日時: 2008-11-25 16:49
度々すみません。
何度直しても文字化けしてしまうので、 説明追記します。 構造体の一番目の項目について、 「VBFixedArray(」です。 | ||||
|
投稿日時: 2008-11-25 16:50
再度追記いたします。
VBFixedArrayの()の中は、数字の8です。 | ||||
|
投稿日時: 2008-11-25 18:32
試しに書いてみましたが、桁ズレのようなものは発生しませんでした。
結果を見ると、ちゃんと9バイト(0〜8)読んでいるように見えます。 それはそれとして、↓のような方法を使ったほうがいいんじゃないでしょうか。 http://msdn.microsoft.com/ja-jp/library/zezabash(VS.80).aspx |