Results 1 to 17 of 17

Thread: [RESOLVED] output data from files

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] output data from files

    I want the output should be like this

    1,840267.7,3170995,500
    1,840348.8,3170966,500
    1,840405.1,3170928,500
    1,840459.2,3170954,500
    1,840493.3,3170995,500
    2,839724.9,3170983,460
    2,839795.4,3170944,460
    2,839890.6,3170936,460
    2,839941.1,3170928,460



    But this what I got
    X Y Z
    840267.7 3170995 500
    840348.8 3170966 500
    840405.1 3170928 500
    840459.2 3170954 500
    840493.3 3170995 500
    839724.9 3170983 460
    839795.4 3170944 460
    839890.6 3170936 460
    839941.1 3170928 460

    Below is the code
    Print #3, "X", "Y", "Z"
    Print #3, p(no).x, p(no).y, p(no).z

    I want to class the z value with id . For example, All Z value contains same value will class starting from 1 untill finish. How to do that?
    Last edited by matrik02; Mar 22nd, 2008 at 09:49 AM.

  2. #2
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: output data from files

    in your expected output you need the line starting with 1 then after wards 2. How is that organised. I mean whats the requirement for that digit? paste the loop which you are using..

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    Here it is. Actually my expected output like this, those Z value with same value will be classed starting from 1. For example you see that for Z value for 500 I class starting from 1 and for 460 I class it as 2 and so on.
    Code:
    Open Text2 For Output As #3
     
    
    Base = a
    Interval = Val(Text3.Text)
    Dim biln As Double
    Dim noContour As Integer
    biln = (Zmax / Interval)
    Dim q As Integer
    q = 1
    noContour = (biln + Val(q))
    Dim c As Integer
    
     Print #3, "X", "Y", "Z"
     For c = 0 To noContour - 1
               
     Base = a
            no = 1
            For Base = a To Zmax - 1
               
                If Abs(div1) > 0.0001 Then
                    mu = -(XY(TIN.Node1, 2) - Base) / div1
    
    
                    If mu >= 0 And mu <= 1 Then
                        p(no).x = XY(TIN.Node1, 0) + mu * (XY(TIN.Node2, 0) - XY(TIN.Node1, 0))
                        p(no).y = XY(TIN.Node1, 1) + mu * (XY(TIN.Node2, 1) - XY(TIN.Node1, 1))
                        p(no).z = Base
                        Print #3, p(no).x, p(no).y, p(no).z
                        'Base = Base + Interval
                    Else
                        p(no).x = (XY(TIN.Node1, 0) + mu * (XY(TIN.Node2, 0) - XY(TIN.Node1, 0)))
                        p(no).y = XY(TIN.Node1, 1) + mu * (XY(TIN.Node2, 1) - XY(TIN.Node1, 1))
                        p(no).z = Base
                        Print #3, p(no).x, p(no).y, p(no).z
                        'Base = Base + Interval
                    End If
                End If
    
                   Base = (Base + Interval) - Val(1)
                   If Base = Zmax Then
                  
                   Print #3, p(no).x, p(no).y, p(no).z
                   Base = (Base + Interval)
                   no = no + Val(1) ' start line/end line
                   c = c + Val(1)
                   End If
                   no = no + Val(1) ' start line/end line
                        
                       
            Next Base
                 
                    c = c + Val(1)
                   
      Next c
          
       
       Close #3
      
      
      MsgBox " Contour Generated", vbOKOnly
    And this what I got


    X Y Z
    840267.7 3170995 500
    840348.8 3170966 500
    840405.1 3170928 500
    840459.2 3170954 500
    840493.3 3170995 500
    839724.9 3170983 460
    839795.4 3170944 460
    839890.6 3170936 460
    839941.1 3170928 460
    My expected result should be like this
    1,840267.7,3170995,500
    1,840348.8,3170966,500
    1,840405.1,3170928,500
    1,840459.2,3170954,500
    1,840493.3,3170995,500
    2,839724.9,3170983,460
    2,839795.4,3170944,460
    2,839890.6,3170936,460
    2,839941.1,3170928,460


  4. #4
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: output data from files

    Try like this
    Print #3, cstr(no)+","+cstr(p(no).x)+","+cstr(p(no).y)+","+cstr(p(no).z)
    Though i haven't executed the code but it shuld work.

    Ashish

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    I would like to know, What is cstr ? What it purpose in this code?

  6. #6
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: output data from files

    Quote Originally Posted by matrik02
    I want the output should be like this




    But this what I got



    Below is the code
    Print #3, "X", "Y", "Z"
    Print #3, p(no).x, p(no).y, p(no).z

    I want to class the z value with id . For example, All Z value contains same value will class starting from 1 untill finish. How to do that?

    You want to write "," instead of blank spaces and 1 and 2 in front of your strings. Where is 1 written and where is 2, depending on what, on last three numbers?

  7. #7
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: output data from files

    CSTR is used for type conversion. I just used for converting the data type of (no) to string. Incase the (no) is in number format then it might throw error while treating it as string. You can remove CSTR from other fields too.

    Ashish

  8. #8
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: output data from files

    Here

    Code:
    Private Sub Command1_Click()
        
        Dim myData As String
        Dim br As Integer
        
        Open "C:\MyFile.txt" For Input As #1
        Open "C:\MyFile2.txt" For Output As #2
        Do Until EOF(1)
            Line Input #1, myData
            If (Right$(myData, 3) = "500") Then myData = "1," + myData
            If (Right$(myData, 3) = "460") Then myData = "2," + myData
                For br = 1 To Len(myData)
                    If Mid$(myData, br, 1) = " " Then Mid$(myData, br, 1) = ","
                Next br
            Print #2, myData
        Loop
        Close #1, #2
        FileCopy "C:\MyFile2.txt", "C:\MyFile.txt"
        Kill "C:\MyFile2.txt"
    
    End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    Why there have a big space after between number and , ? There have big gaps.Can we make it closely?I also attach the files of my result
    Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z

    1 , 850938.076073618 , 3152812.34969325 , 244
    1 , 840411.771318958 , 3169369.8784581 , 244
    1 , 842681.790902708 , 3170903.51832759 , 244
    2 , 850448.106748464 , 3153583.05521473 , 254
    2 , 840368.448834554 , 3169438.02329129 , 254
    2 , 842544.299084797 , 3170906.54123744 , 254
    3 , 849958.137423311 , 3154353.7607362 , 264
    3 , 840325.126350149 , 3169506.16812449 , 264
    3 , 842406.807266886 , 3170909.56414729 , 264
    4 , 849468.168098158 , 3155124.46625767 , 274
    4 , 840281.803865745 , 3169574.31295769 , 274
    4 , 842269.315448974 , 3170912.58705714 , 274
    5 , 848978.198773004 , 3155895.17177914 , 284
    Attached Files Attached Files
    Last edited by matrik02; Mar 22nd, 2008 at 10:57 AM.

  10. #10
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: output data from files

    Quote Originally Posted by matrik02
    Why there have a big space after between number and , ? There have big gaps.Can we make it closely?I also attach the files of my result
    Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z
    Have you tried my example?

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    Yes,Nevermind I solved it, but the problem is that, the output have gap.. How to move the , so that it my look easy such as 1 , 850938.076073618 , 3152812.34969325 , 244


    Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z
    Attached Images Attached Images  

  12. #12
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: output data from files

    Ok, i made somethnig too

    Code:
    Private Sub Command1_Click()
        
        Dim myData As String
        Dim br, x As Integer
        
        Open "C:\MyFile.txt" For Input As #1
        Open "C:\MyFile2.txt" For Output As #2
        Do Until EOF(1)
            Line Input #1, myData
                y = 0
                For x = 244 To 614 Step 10
                    y = y + 1
                    b$ = Str(y)
                    If (Right$(myData, 3) = x) Then
                        MsgBox ("radi")
                        myData = b$ + "," + myData
                    End If
                Next x
            
                For br = 1 To Len(myData)
                    If Mid$(myData, br, 1) = " " Then Mid$(myData, br, 1) = ","
                Next br
            Print #2, myData
        Loop
        Close #1, #2
        FileCopy "C:\MyFile2.txt", "C:\MyFile.txt"
        Kill "C:\MyFile2.txt"
    
    End Sub

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    This what I get..hehehe

    Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z


    How to make the number and , to be like this without gap betwen number and ,

    1 , 850938.076073618 , 3152812.34969325 , 244
    Attached Images Attached Images  
    Attached Files Attached Files

  14. #14
    Hyperactive Member
    Join Date
    Oct 2007
    Location
    Indiana
    Posts
    295

    Re: output data from files

    When you convert numbers to a string, it will add spaces.

    Try this:

    Code:
    b$ = trim(Str(y))

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: output data from files

    How to make the the output where the number and , are closely without gap. I want to output files like the first two line for all records..How to do that? Here is my code to generate the output

    Code:
    Open Text2 For Output As #3
     
    
    Base = a
    Interval = Val(Text3.Text)
    Dim biln As Double
    Dim noContour As Integer
    biln = (Zmax / Interval)
    Dim q As Integer
    q = 1
    noContour = (biln + Val(q))
    
    
    
     Dim c As Integer
    
     'Print #3, "X", ",", "Y", ",", "Z"
     For c = 0 To noContour - 1
               
     Base = a
            no = 1
            For Base = a To Zmax - 1
               
                If Abs(div1) > 0.0001 Then
                    mu = -(XY(TIN.Node1, 2) - Base) / div1
    
    
                    If mu >= 0 And mu <= 1 Then
                        p(no).x = XY(TIN.Node1, 0) + mu * (XY(TIN.Node2, 0) - XY(TIN.Node1, 0))
                        p(no).y = XY(TIN.Node1, 1) + mu * (XY(TIN.Node2, 1) - XY(TIN.Node1, 1))
                        p(no).z = Base
                        Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z
                        'Base = Base + Interval
                    Else
                        p(no).x = (XY(TIN.Node1, 0) + mu * (XY(TIN.Node2, 0) - XY(TIN.Node1, 0)))
                        p(no).y = XY(TIN.Node1, 1) + mu * (XY(TIN.Node2, 1) - XY(TIN.Node1, 1))
                        p(no).z = Base
                        Print #3, no, ",", p(no).x, ",", p(no).y, ",", p(no).z
                        'Base = Base + Interval
                    End If
                End If
    
                   Base = (Base + Interval) - Val(1)
                   If Base = Zmax Then
                  
                   Print #3, p(no).x, p(no).y, p(no).z
                   Base = (Base + Interval)
                   no = no + Val(1) ' start line/end line
                   c = c + Val(1)
                   End If
                   no = no + Val(1) ' start line/end line
                        
                       
            Next Base
                 
                    c = c + Val(1)
                   
      Next c
          
       
       Close #3
    Attached Images Attached Images  

  16. #16
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: output data from files

    Use a semicolon rather than a comma when printing
    Code:
    Print #3, no; ","; p(no).x, ","; p(no).y, ","; p(no).z

  17. #17
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: output data from files

    Quote Originally Posted by Caskbill
    When you convert numbers to a string, it will add spaces.

    Try this:

    Code:
    b$ = trim(Str(y))
    I didnt know that, thanx. That is why i get that first ",".

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