Announcement

Collapse
No announcement yet.

Visual Basic Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Visual Basic Problem

    Hi guys, ive got a friend who is writing a program in VB for a geophysical application. Im a FORTRAN90 and IDL boy myself, so i dont know what the problem is. If anyone can give some help on this it would be greatly appreciated. Thanks. Here it is:

    i am writing an auto-correlation program for short dicrete signals.
    i am having a problem where i am getting an error saying the subscript is out of range. my code is below with the problem line starting:
    sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop)



    Code:
    Private sngAlldata(1 To 100) As Single, intSamples As Integer
    Private Sub butload_Click()
    'declare some varibales
    Dim sngdata As Single, strtest As String
    Dim intFree As Integer
    'set some variables
    intFree = FreeFile
    
    
    'set a dialog box allowing the user to search for his/her data
    CommonDialog1.ShowOpen
    strtest = CommonDialog1.FileName
    
    'read in a file of data
    Open strtest For Input As #intFree
    intSamples = 1
    'print some headings
    
    ' set up a loop that runs till the end of file
    Do While Not EOF(intFree)
    Input #intFree, sngdata
        sngAlldata(intSamples) = sngdata
        Text1.SelText = Str(sngdata) & vbCrLf
        intSamples = intSamples + 1
    Loop
    intSamples = intSamples - 1
    Text1.SelText = "no of samples = " & Str(intSamples) & vbCrLf
    End Sub
    Private Sub butproautocor_click()
    Dim intCount As Integer, intLoop As Integer, sngAns(1 To 199) As Single, intCount1 As Integer, intN As Integer, intM As Integer
    For intCount1 = 1 To 199
    sngAns(intCount1) = 0
    Next intCount1
    intN = intSamples
    intM = intSamples
    'no samples of a and b is n and m respectively
    'set loopcounter for tau values to increment difference between them
    For intLoop = -(intM - 1) To intN - 1
    'to increment staring values to multiply
    For intCount = 1 To intN
        'to multiply then add them up
        sngAns(intLoop) = sngAns(intLoop) + sngAlldata(intCount) * sngAlldata(intCount - intLoop)
    Next intCount
    Text1.SelText = Str(sngAns(intLoop)) & vbTab & Str(intLoop) & vbCrLf
    Next intLoop
    End Sub
    any help or suggestion will be greatly appreciated
    thanks
    I hate flankers...

  • #2
    Only use VBA, not full VB, but with a problem like this I would set a pause point just before the for loops start, and then step through the code (F8). Then hover the mouse over the line and check that IntCount and IntLoop are what you expect them to be, and also that sngAns(xx) and sngAllData(xx) are what you expect...

    I'm no good at just looking at code and saying "that's the problem!"
    DM says: Crunch with Matrox Users@ClimatePrediction.net

    Comment


    • #3
      he says:

      the sngans(xx) is givving the subscript out of range error so it does not loop through the calculation. thus putting a watch won't help. but the other part of the calculation i.e.
      sngAlldata(intCount) * sngAlldata(intCount - intLoop)
      seems to be producing the right values. the problem seems to lie in sngAns(xxx)
      I hate flankers...

      Comment


      • #4
        are sngAns and SngAllData the same variable type? If not you may need to convert sngAllData to SngAns' type.
        DM says: Crunch with Matrox Users@ClimatePrediction.net

        Comment


        • #5
          he says:

          both of them are single precision variables and i also have tried making them the same length with no result. the arrays are 1-D arrays.
          I hate flankers...

          Comment


          • #6
            well your starting value for intLoop in that for loop is <0. that may be your problem? sngAns(-x) is likely not valid I think (should start at either sngAns(0) or sngAns(1) I can't remember with VB)
            DM says: Crunch with Matrox Users@ClimatePrediction.net

            Comment


            • #7
              Re: Visual Basic Problem

              Originally posted by jonnylane

              For intLoop = -(intM - 1) To intN - 1
              Next intLoop
              End Sub[/code]
              I've got the impression that sngAlldata(intCount) is causing the problem (running out of bounds?), and why does he start with a negative value to start the loop?
              Main: Dual Xeon LV2.4Ghz@3.1Ghz | 3X21" | NVidia 6800 | 2Gb DDR | SCSI
              Second: Dual PIII 1GHz | 21" Monitor | G200MMS + Quadro 2 Pro | 512MB ECC SDRAM | SCSI
              Third: Apple G4 450Mhz | 21" Monitor | Radeon 8500 | 1,5Gb SDRAM | SCSI

              Comment


              • #8
                thanks guys.

                he says:

                i did not set the boundaries for sngans for negative numbers so when i did it worked. but there are still some problems but since i know what they are i should be alright.
                thanks alot
                I hate flankers...

                Comment


                • #9
                  No probs - just helping you work it out really
                  DM says: Crunch with Matrox Users@ClimatePrediction.net

                  Comment


                  • #10
                    Woah!! VB?
                    am learning that in Uni rite now..its gaga!~
                    can someone explain to me how to use functions and subroutines??

                    Comment

                    Working...
                    X