いつもお世話になっております。VB超初心者です。
現在VB6にてオシロ測定DATAの解析プログラムを作成しています。
DATAは電圧-時間の正弦波が約100サイクル続くDATAです。
この正弦波の各位相0°に相当するポイント(-→+へ移る際の0ポイント)をピックアップしていきたいのですが+-の境目で数値がバタつき、
うまく0°の場所を拾えず180°も拾ってしまいます。
数値の並びは-→+の境目は下記のかんじで
-0.16
-0.16
0
-0.08
-0.08
-0.16
-0.08
-0.08
-0.08
-0.08
0
0
-0.08
-0.08
-0.08
-0.08
-0.08
0
-0.08
-0.08
-0.08
0
-0.16
-0.08
-0.08
0
とここから0が増えて+が現れる感じです。バタつきの幅や並びの傾向
から下記のプログラムをとりあえず作ったのですが結果は180°も
一緒に拾ってしまいます。カウント10で1ポイント拾うものなので
20で拾わずにカウント0に戻せばいいのでしょうか?
というよりSGN関数使うとかすべきなのでしょうか?何かいいやり方
ありませんか?
Private Sub StartCommand_Click()
Dim rs, r:
Dim ws, w:
Dim rLine As String
Dim wLine As String
Dim nowVolt As Double
Dim beforeVolt As Double
Dim start As Integer
Dim counter As Integer
Dim point As Integer
Dim LineX
'事前準備
Set rs = CreateObject("Scripting.FileSystemObject")
Set r = rs.OpenTextFile(ReadFile.Text, 1)
Set ws = CreateObject("Scripting.FileSystemObject")
Set w = _
ws.CreateTextFile(WriteFile.Text, True)
counter = 0
point = 0
nowVolt = 0
beforeVolt = 0
start = 0
Last = 0
'実際の計算
Do Until r.AtEndOfStream
'電圧値取得
rLine = r.readLine
LineX = Split(rLine & ",,,,,,,", ",")
nowVolt = Val(LineX(4))
'ゼロ点検出用カウンタ処理
If (beforeVolt < 0) Then
If (nowVolt >= 0) Then
counter = counter + 1
End If
End If
'ゼロ点検出処理
If counter = 1 Then
start = point
End If
If counter = 10 Then
Last = LineX(3)
wLine = Last
w.WriteLine (wLine)
counter = 0
End If
'次処理
beforeVolt = nowVolt
Loop
'事後処理
r.Close:
w.Close:
End Sub
いつもお世話になっております。VB超初心者です。
現在VB6にてオシロ測定DATAの解析プログラムを作成しています。
DATAは電圧-時間の正弦波が約100サイクル続くDATAです。
この正弦波の各位相0°に相当するポイント(-→+へ移る際の0ポイント)をピックアップしていきたいのですが+-の境目で数値がバタつき、
うまく0°の場所を拾えず180°も拾ってしまいます。
数値の並びは-→+の境目は下記のかんじで
-0.16
-0.16
0
-0.08
-0.08
-0.16
-0.08
-0.08
-0.08
-0.08
0
0
-0.08
-0.08
-0.08
-0.08
-0.08
0
-0.08
-0.08
-0.08
0
-0.16
-0.08
-0.08
0
とここから0が増えて+が現れる感じです。バタつきの幅や並びの傾向
から下記のプログラムをとりあえず作ったのですが結果は180°も
一緒に拾ってしまいます。カウント10で1ポイント拾うものなので
20で拾わずにカウント0に戻せばいいのでしょうか?
というよりSGN関数使うとかすべきなのでしょうか?何かいいやり方
ありませんか?
Private Sub StartCommand_Click()
Dim rs, r:
Dim ws, w:
Dim rLine As String
Dim wLine As String
Dim nowVolt As Double
Dim beforeVolt As Double
Dim start As Integer
Dim counter As Integer
Dim point As Integer
Dim LineX
'事前準備
Set rs = CreateObject("Scripting.FileSystemObject")
Set r = rs.OpenTextFile(ReadFile.Text, 1)
Set ws = CreateObject("Scripting.FileSystemObject")
Set w = _
ws.CreateTextFile(WriteFile.Text, True)
counter = 0
point = 0
nowVolt = 0
beforeVolt = 0
start = 0
Last = 0
'実際の計算
Do Until r.AtEndOfStream
'電圧値取得
rLine = r.readLine
LineX = Split(rLine & ",,,,,,,", ",")
nowVolt = Val(LineX(4))
'ゼロ点検出用カウンタ処理
If (beforeVolt < 0) Then
If (nowVolt >= 0) Then
counter = counter + 1
End If
End If
'ゼロ点検出処理
If counter = 1 Then
start = point
End If
If counter = 10 Then
Last = LineX(3)
wLine = Last
w.WriteLine (wLine)
counter = 0
End If
'次処理
beforeVolt = nowVolt
Loop
'事後処理
r.Close:
w.Close:
End Sub
いつもお世話になっております。VB超初心者です。
現在VB6にてオシロ測定DATAの解析プログラムを作成しています。
DATAは電圧-時間の正弦波が約100サイクル続くDATAです。
この正弦波の各位相0°に相当するポイント(-→+へ移る際の0ポイント)をピックアップしていきたいのですが+-の境目で数値がバタつき、
うまく0°の場所を拾えず180°も拾ってしまいます。
数値の並びは-→+の境目は下記のかんじで
-0.16
-0.16
0
-0.08
-0.08
-0.16
-0.08
-0.08
-0.08
-0.08
0
0
-0.08
-0.08
-0.08
-0.08
-0.08
0
-0.08
-0.08
-0.08
0
-0.16
-0.08
-0.08
0
とここから0が増えて+が現れる感じです。バタつきの幅や並びの傾向
から下記のプログラムをとりあえず作ったのですが結果は180°も
一緒に拾ってしまいます。カウント10で1ポイント拾うものなので
20で拾わずにカウント0に戻せばいいのでしょうか?
というよりSGN関数使うとかすべきなのでしょうか?何かいいやり方
ありませんか?
Private Sub StartCommand_Click()
Dim rs, r:
Dim ws, w:
Dim rLine As String
Dim wLine As String
Dim nowVolt As Double
Dim beforeVolt As Double
Dim start As Integer
Dim counter As Integer
Dim point As Integer
Dim LineX
'事前準備
Set rs = CreateObject("Scripting.FileSystemObject")
Set r = rs.OpenTextFile(ReadFile.Text, 1)
Set ws = CreateObject("Scripting.FileSystemObject")
Set w = _
ws.CreateTextFile(WriteFile.Text, True)
counter = 0
point = 0
nowVolt = 0
beforeVolt = 0
start = 0
Last = 0
'実際の計算
Do Until r.AtEndOfStream
'電圧値取得
rLine = r.readLine
LineX = Split(rLine & ",,,,,,,", ",")
nowVolt = Val(LineX(4))
'ゼロ点検出用カウンタ処理
If (beforeVolt < 0) Then
If (nowVolt >= 0) Then
counter = counter + 1
End If
End If
'ゼロ点検出処理
If counter = 1 Then
start = point
End If
If counter = 10 Then
Last = LineX(3)
wLine = Last
w.WriteLine (wLine)
counter = 0
End If
'次処理
beforeVolt = nowVolt
Loop
'事後処理
r.Close:
w.Close:
End Sub
いつもお世話になっております。VB超初心者です。
現在VB6にてオシロ測定DATAの解析プログラムを作成しています。
DATAは電圧-時間の正弦波が約100サイクル続くDATAです。
この正弦波の各位相0°に相当するポイント(-→+へ移る際の0ポイント)をピックアップしていきたいのですが+-の境目で数値がバタつき、
うまく0°の場所を拾えず180°も拾ってしまいます。
数値の並びは-→+の境目は下記のかんじで
-0.16
-0.16
0
-0.08
-0.08
-0.16
-0.08
-0.08
-0.08
-0.08
0
0
-0.08
-0.08
-0.08
-0.08
-0.08
0
-0.08
-0.08
-0.08
0
-0.16
-0.08
-0.08
0
とここから0が増えて+が現れる感じです。バタつきの幅や並びの傾向
から下記のプログラムをとりあえず作ったのですが結果は180°も
一緒に拾ってしまいます。カウント10で1ポイント拾うものなので
20で拾わずにカウント0に戻せばいいのでしょうか?
というよりSGN関数使うとかすべきなのでしょうか?何かいいやり方
ありませんか?
Private Sub StartCommand_Click()
Dim rs, r:
Dim ws, w:
Dim rLine As String
Dim wLine As String
Dim nowVolt As Double
Dim beforeVolt As Double
Dim start As Integer
Dim counter As Integer
Dim point As Integer
Dim LineX
'事前準備
Set rs = CreateObject("Scripting.FileSystemObject")
Set r = rs.OpenTextFile(ReadFile.Text, 1)
Set ws = CreateObject("Scripting.FileSystemObject")
Set w = _
ws.CreateTextFile(WriteFile.Text, True)
counter = 0
point = 0
nowVolt = 0
beforeVolt = 0
start = 0
Last = 0
'実際の計算
Do Until r.AtEndOfStream
'電圧値取得
rLine = r.readLine
LineX = Split(rLine & ",,,,,,,", ",")
nowVolt = Val(LineX(4))
'ゼロ点検出用カウンタ処理
If (beforeVolt < 0) Then
If (nowVolt >= 0) Then
counter = counter + 1
End If
End If
'ゼロ点検出処理
If counter = 1 Then
start = point
End If
If counter = 10 Then
Last = LineX(3)
wLine = Last
w.WriteLine (wLine)
counter = 0
End If
'次処理
beforeVolt = nowVolt
Loop
'事後処理
r.Close:
w.Close:
End Sub
CR,LF,CRLFが混在しているテキストで難儀しております。
VB.NETでReadLine()を使えば、どんな改行コードでも削除した文字列を取得できますが、同じ内容を書き込む場合にどのような改行コードわからないと同じファイルができません。
安直にNewLineやWriteLine()を使うと、どんな改行コードでWindowsの場合はCRLFになります。
ReadLine()で取得した文字列+改行コードがわかる方法がありますか?
以下、例です。
dim s as String
Dim sr As New System.IO.StreamReader("yomu", "ISO-2022-JP")
Dim sw As New System.IO.StreamWriter("kaku", false, "ISO-2022-JP")
While sr.Peek() > -1
s = sr.ReadLine() '改行文字を取り除いた文字列
sw.Write(s) '書き込む
end While
sr.close()
sw.close()