Results 1 to 10 of 10

Thread: read *.xyz file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    7

    read *.xyz file

    how to read the coordinate (xyz) from text files and display in VB as point graphic???

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: read *.xyz file

    You mean just read some data in a textfile?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    7

    Re: read *.xyz file

    yup...about 100 data

  4. #4
    Lively Member
    Join Date
    Nov 2007
    Posts
    98

    Re: read *.xyz file

    it all depends on your data file structure. please post a sample here.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: read *.xyz file

    Change the numbers if its sensitive data but is it like a comma delimited file or just raw data all on a line?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    7

    Re: read *.xyz file

    my data do not have delimited comma,all data separated by space and what do you mean by sensitive data.tq for the reply

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: read *.xyz file

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    7

    Re: read *.xyz file

    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....

  9. #9
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: read *.xyz file

    Well, I bothered to code 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
    This outputs a string array which should be handled like this:

    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
    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...

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    7

    Re: read *.xyz file

    ok...TQ Merri...i will try this code....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width