how to read the coordinate (xyz) from text files and display in VB as point graphic???
Printable View
how to read the coordinate (xyz) from text files and display in VB as point graphic???
You mean just read some data in a textfile?
yup...about 100 data
it all depends on your data file structure. please post a sample here.
Change the numbers if its sensitive data but is it like a comma delimited file or just raw data all on a line?
my data do not have delimited comma,all data separated by space and what do you mean by sensitive data.tq for the reply
Sensitive data = data you don't want seen publicly (like corporate secrets or something).
Seeing a sample of the file structure helps greatly in developing a code that works. Also, if there is a picture of the final result of the very same sample, all the better.
If values are only separated with spaces then a simple Split will do the trick and the remaining problem is drawing the final result based on the values.
this is sample of my data...
X Y Z
627807.482 173582.422 135.091
627866.458 173516.968 125.675
627751.735 173598.406 134.672
627758.886 173607.705 135.808
can i read this data in VB and display as point graphic????
TQ....
Well, I bothered to code this:This outputs a string array which should be handled like this:Code:Public Sub LoadXYZ(ByRef Filename As String) As String()
Dim FF As Integer, lngA As Long, lngLen As Long
Dim bytBuffer() As Byte, strBuffer() As String
Dim strLine() As String, strOut() As String
' make sure the file exists
If LenB(Dir$(Filename, vbHidden)) Then
' make sure it has some data
lngLen = FileLen(Filename)
If lngLen Then
' read the file into a byte array
FF = FreeFile
Open Filename For Binary Access Read As #FF
ReDim bytBuffer(lngLen - 1)
Get #FF, , bytBuffer
Close #FF
' convert byte array to VB string format and split by line change
strBuffer = Split(StrConv(bytBuffer, vbUnicode), vbNewLine)
' memory cleanup
Erase bytBuffer
' see that this really is XYZ data
If strBuffer(0) = "X Y Z" And UBound(strBuffer) > 0 Then
' reserve enough space for output array
ReDim strOut(2, UBound(strBuffer) - 1)
' loop through all lines
For lngA = 1 To UBound(strBuffer)
' get line data
strLine = Split(strBuffer(lngA))
' number of items must be 3
If UBound(strLine) = 2 Then
' store into output array
strOut(0, lngA - 1) = strLine(0)
strOut(1, lngA - 1) = strLine(1)
strOut(2, lngA - 1) = strLine(2)
End If
Next lngA
' output final array
LoadXYZ = strOut
' we are done!
Exit Function
End If
End If
End If
' otherwise return an initialized empty array: UBound(LoadXYZ) = -1
LoadXYZ = Split(vbNullString)
End Sub
Now you should, for the least, have the data so that you can use it to get started with the drawing. I don't know how to do that in this case, I don't know what the final result should look like, so that is for someone else to answer...Code:' load file
strResult = LoadXYZ("c:\text.xyz")
' valid data?
If UBound(strResult) = 2 Then
' should output "1: 627807.482 173582.422 135.091"
Debug.Print "1:", strResult(0, 0), strResult(1, 0), strResult(2, 0)
' 627866.458 173516.968 125.675
Debug.Print "2:", strResult(0, 1), strResult(1, 1), strResult(2, 1)
End If
ok...TQ Merri...i will try this code....:D