Option ExplicitPrivate Type RecordData
ID As Long
X As Double
Y As Double
Height As Single
x1 As Double
y1 As Double
x2 As Double
y2 As DoubleEnd TypePrivate Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入正确的高程数据!", vbInformation, "友情提示"
Exit Sub
End If
On Error Resume Next
Dim strSource As String
Dim strDest As String
'窗体上放一个CommonDialog控件
With CommonDialog1
.DialogTitle = "选择源文件"
.CancelError = True
.Filter = "记事本(*.txt)|*.txt"
.ShowOpen
If Err.Number <> 0 Then Exit Sub
strSource = .FileName
End With
'strDest = "f:\cxp.txt" '这个文件也可以用上面的方法让用户选择
'选择保存目的地开始
With CommonDialog2
.DialogTitle = "文件保存为"
.CancelError = True
.Filter = "记事本(*.txt)|*.txt"
.ShowOpen
If Err.Number <> 0 Then Exit Sub
strDest = .FileName
End With
'选择保存目的地结束
BatchConvert strSource, strDest
End SubPrivate Function BatchConvert(ByVal strSourFile As String, ByVal strDestFile As String) As Boolean
Dim strTmp As String
Dim i As Long, j As Long
Dim f As Integer
Dim aryData() As RecordData, aryCon() As String, aryTmp() As String
Dim hh As Single
hh = Text1.Text BatchConvert = False
f = FreeFile
Open strSourFile For Input As #f
strTmp = StrConv(InputB(LOF(f), #f), vbUnicode)
Close #f
aryCon = Split(strTmp, vbCrLf)
j = 0
For i = 0 To UBound(aryCon)
If IsNumeric(Left(aryCon(i), 1)) Then '加上这一行判断
ReDim Preserve aryData(j)
aryTmp = Split(aryCon(i), " ")
With aryData(j)
.ID = Mid(aryCon(i), 1, 4)
.X = Mid(aryCon(i), 14, 14)
.Y = Mid(aryCon(i), 35, 18)
.Height = Mid(aryCon(i), 60, 13)
End With
j = j + 1
Erase aryTmp
End If
Next
Erase aryCon
'写入新文件 Open strDestFile For Output As #f
If Option1.Value = True Then
Print #f, "(坐标)点号 X Y 高程" '这一行是修改的
'读取X,Y,高程的值
'x1 = aryData(i).X
' y1 = aryData(i).Y
'x2 = 3400400.681 - 0.9441186539 * x1 - 0.329625979 * y1
' y2 = 0.329625979 * x1 - 0.9441186539 * y1 - 618116.9494
For i = 0 To UBound(aryData)
Print #f, aryData(i).ID & ", ," & aryData(i).X & " ," & aryData(i).X & " ," & hh - aryData(i).Height
Next
Else
Print #f, "(坐标)点号 X Y 高程"
For i = 0 To UBound(aryData)
Print #f, aryData(i).ID & ", ," & aryData(i).X & " ," & aryData(i).Y & " ," & hh - aryData(i).Height
Next
End If
Close #f
'调用记事本打开处理后的文件
Shell "notepad.exe " & strDestFile, vbNormalFocus
BatchConvert = True
End Function
-------------------------------------------------------
上面的程序是正确的,
但我把
'读取X,Y,高程的值
x1
y1
x2
y2
的注释去掉,
Print #f, aryData(i).ID & ", ," & x2 & " ," & y2 & " ," & hh - aryData(i).Height程序虽不提示出错,但无法运行输出新的目标文件。
感谢大家相助。
ID As Long
X As Double
Y As Double
Height As Single
x1 As Double
y1 As Double
x2 As Double
y2 As DoubleEnd TypePrivate Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox "请输入正确的高程数据!", vbInformation, "友情提示"
Exit Sub
End If
On Error Resume Next
Dim strSource As String
Dim strDest As String
'窗体上放一个CommonDialog控件
With CommonDialog1
.DialogTitle = "选择源文件"
.CancelError = True
.Filter = "记事本(*.txt)|*.txt"
.ShowOpen
If Err.Number <> 0 Then Exit Sub
strSource = .FileName
End With
'strDest = "f:\cxp.txt" '这个文件也可以用上面的方法让用户选择
'选择保存目的地开始
With CommonDialog2
.DialogTitle = "文件保存为"
.CancelError = True
.Filter = "记事本(*.txt)|*.txt"
.ShowOpen
If Err.Number <> 0 Then Exit Sub
strDest = .FileName
End With
'选择保存目的地结束
BatchConvert strSource, strDest
End SubPrivate Function BatchConvert(ByVal strSourFile As String, ByVal strDestFile As String) As Boolean
Dim strTmp As String
Dim i As Long, j As Long
Dim f As Integer
Dim aryData() As RecordData, aryCon() As String, aryTmp() As String
Dim hh As Single
hh = Text1.Text BatchConvert = False
f = FreeFile
Open strSourFile For Input As #f
strTmp = StrConv(InputB(LOF(f), #f), vbUnicode)
Close #f
aryCon = Split(strTmp, vbCrLf)
j = 0
For i = 0 To UBound(aryCon)
If IsNumeric(Left(aryCon(i), 1)) Then '加上这一行判断
ReDim Preserve aryData(j)
aryTmp = Split(aryCon(i), " ")
With aryData(j)
.ID = Mid(aryCon(i), 1, 4)
.X = Mid(aryCon(i), 14, 14)
.Y = Mid(aryCon(i), 35, 18)
.Height = Mid(aryCon(i), 60, 13)
End With
j = j + 1
Erase aryTmp
End If
Next
Erase aryCon
'写入新文件 Open strDestFile For Output As #f
If Option1.Value = True Then
Print #f, "(坐标)点号 X Y 高程" '这一行是修改的
'读取X,Y,高程的值
'x1 = aryData(i).X
' y1 = aryData(i).Y
'x2 = 3400400.681 - 0.9441186539 * x1 - 0.329625979 * y1
' y2 = 0.329625979 * x1 - 0.9441186539 * y1 - 618116.9494
For i = 0 To UBound(aryData)
Print #f, aryData(i).ID & ", ," & aryData(i).X & " ," & aryData(i).X & " ," & hh - aryData(i).Height
Next
Else
Print #f, "(坐标)点号 X Y 高程"
For i = 0 To UBound(aryData)
Print #f, aryData(i).ID & ", ," & aryData(i).X & " ," & aryData(i).Y & " ," & hh - aryData(i).Height
Next
End If
Close #f
'调用记事本打开处理后的文件
Shell "notepad.exe " & strDestFile, vbNormalFocus
BatchConvert = True
End Function
-------------------------------------------------------
上面的程序是正确的,
但我把
'读取X,Y,高程的值
x1
y1
x2
y2
的注释去掉,
Print #f, aryData(i).ID & ", ," & x2 & " ," & y2 & " ," & hh - aryData(i).Height程序虽不提示出错,但无法运行输出新的目标文件。
感谢大家相助。
谢谢。