Results 1 to 8 of 8

Thread: Have a look at my code pls

  1. #1

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342

    Talking Have a look at my code pls

    Take a peek
    Can anybody tell me how hopeless my attempt at this is? Is my code even close to doing what I want it to? I'm trying to graph a single line ( latitude vs. time ) the (x,y) coordinates are stored in two very large text files. Here is my code:



    code:--------------------------------------------------------------------------------
    Private Sub cmdGraphB_Click()
    Dim tmp1 As String
    Dim tmp2 As String
    Dim timeCtr As Long
    dim i as Long
    Dim the_time As Double
    Dim the_latitude As Double
    Dim Values() As Single
    Dim NumPoints As Integer

    Open "C:\Unzip Next Step\R1 Files\R1Time.txt" For Input As #1
    Open "C:\Unzip Next Step\R1 Files\R1Latitude.txt" For Input As #2

    timeCtr = 0

    Do While Not EOF(1)

    Line Input #1, tmp1
    tmp1 = CLng(tmp1)
    timeCtr = timeCtr + 1

    Line Input #2, tmp2
    tmp2 = CLng(tmp2)
    the_latitude = tmp2

    Values(i, 1) = timeCtr
    Values(i, 2) = the_latitude

    Loop
    Close #2
    Close #1

    MSChart1.chartType = VtChChartType2dXY
    MSChart1.ColumnCount = 2
    MSChart1.ChartData = Values

    End Sub

    --------------------------------------------------------------------------------


    Thanks

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    There are a few problems. First, your array (Values() ) needs to
    be dimensioned to a size. The size would be the number of
    values you read from the file. It sounds like you don't know that
    in advance, but that is not a big problem. Also the array is Single
    yet you are storing two Longs in it (CLng(tmp1) and CLng(tmp2)).
    It should be one or the other. With a Sinlge you get digits to the
    right of the decimal, with a Long you don't.


    When you store values in the array, the first part - 'i' - never
    changes in your code (Values(i, 2) = the_latitude ), however,
    timeCtr does, so you should be using that (Values(2, timeCtr) =
    the_latitude )


    If you want numbers to the right change Clng to CSng

    Code:
    Private Sub cmdGraphB_Click()
        Dim sTemp As String
        Dim lCounter As Long
        Dim Values() As Single
        
        Open "C:\Unzip Next Step\R1 Files\R1Time.txt" For Input As #1
        Open "C:\Unzip Next Step\R1 Files\R1Latitude.txt" For Input As #2
        
        lCounter = 0
        
        Do While Not EOF(1)
            If lCounter = 0 Then
                ReDim Values(2, 25)
            ElseIf lCounter Mod 25 = 0 Then
                ReDim Preserve Values(2, UBound(Values, 2) + 25)
            End If
    
            Line Input #1, sTemp
            Values(1, lCounter) = CLng(sTemp)
            
            Line Input #2, sTemp
            Values(2, lCounter) = CLng(sTemp)
            
            lCounter = lCounter + 1
        Loop
        Close #2
        Close #1
        
        MSChart1.chartType = VtChChartType2dXY
        MSChart1.ColumnCount = 2
        MSChart1.ChartData = Values
        
    End Sub
    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    Thanks a lot for the reply Greg. Do you know how many (x, y) sets this can handle.... I think my files may be much to large (I've run into that a lot with this app ). I'm looking at about 1.5 million (x,y) sets . Is this do-able?

  4. #4
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    The real question I would think, would be what can you discern from looking at a graph with 1.5 million lines on it. That is a lot of data to view at one time. I don't know what the limitations of MSChart are, but it is my understanding that arrays are limited to the amount of memory available to them.

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  5. #5

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    Hello,

    I'm getting a runtime error '13' "type mismatch"
    on the line in bold in this code. I have cropped the input files
    considerably, as my main concern right now is just getting a graph up. Files contain about 10% of the (x,y) points to be plotted as before (I know this is still a lot... ablout 100k points).

    Here is the code:

    Private Sub cmdGraphB_Click()
    Dim sTemp As String
    Dim lCounter As Long
    Dim Values() As Single

    Open "C:\Unzip Next Step\R1 Files\R1Time.txt" For Input As #1
    Open "C:\Unzip Next Step\R1 Files\R1Latitude.txt" For Input As #2

    lCounter = 0

    Do While Not EOF(1)
    If lCounter = 0 Then
    ReDim Values(2, 25)
    ElseIf lCounter Mod 25 = 0 Then
    ReDim Preserve Values(2, UBound(Values, 2) + 25)
    End If

    Line Input #1, sTemp
    Values(1, lCounter) = CLng(sTemp)

    Line Input #2, sTemp
    Values(2, lCounter) = CLng(sTemp)

    lCounter = lCounter + 1
    Loop
    Close #2
    Close #1

    MSChart1.chartType = VtChChartType2dXY
    MSChart1.ColumnCount = 2
    MSChart1.ChartData = Values

    End Sub



    Thank you for your time,

    Paul Grimes

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Wouldn't you need CSng()
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Hyperactive Member pgrimes's Avatar
    Join Date
    Aug 2001
    Location
    sacramento
    Posts
    342
    It gives the same error msg using CLng() or CSng().

    thx,

    Paul

  8. #8
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    That should be

    Code:
    Line Input #1, sTemp 
    Values(0, lCounter) = CLng(sTemp) 
    
    Line Input #2, sTemp 
    Values(1, lCounter) = CLng(sTemp)
    My bad...sorry.

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

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