Results 1 to 29 of 29

Thread: [RESOLVED] VBA error

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Resolved [RESOLVED] VBA error

    Hello,

    I am a new in VBA and I am facing the attached error. I would appreciate any help. Thanks in advance

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    This forum makes screen captures hard to read. Post the code (enclosed in code tags) and the text of the error message. Add a comment to the line causing the error so we can diagnose the issue.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Thank you for the prompt reply. I would like to inform you that the code is enough big. The error happens in 390 line

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    I forgot the file

  5. #5
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    I would like to inform you that the code is enough big. The error happens in 390 line.
    We have no idea what this means. Also, there are no line numbers in the screen capture, so 'line 390' is not helpful. We also still do not know what the error message you are getting is. Post at least the error message text and the line of code that is highlighted as the cause of the error.

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    For the first run, EPIC rewrite output
    Input #2, X, Y, DEM, Slope, Landuse, Soil, Climate, Country, FER, MaxIrr . 390 line of the code is appearing.

    Thank you.
    Last edited by getziatz; Nov 2nd, 2020 at 10:41 AM.

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Input #2, X, Y, DEM, Slope, Landuse, Soil, Climate, Country, FER, MaxIrr . 390 line of the code, the error is appearing.

    Thank you.
    Last edited by getziatz; Nov 2nd, 2020 at 10:41 AM.

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    I am really sorry.
    Input #2, X, Y, DEM, Slope, Landuse, Soil, Climate, Country, FER, MaxIrr (In 390 line of the code, this error is appearing)

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    I am really sorry.
    Input #2, X, Y, DEM, Slope, Landuse, Soil, Climate, Country, FER, MaxIrr (In 390 line of the code, this error is appearing)

  10. #10
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    OK, now we have the line of code where the error is occurring. That gives us some ideas as to what possible errors can occur. However, we still do not know exactly what the error message is. Post that information. It should be something like "run-time error 13 – Type mismatch". Once we know what the error message that YOU are getting is, we can suggest some ideas as to a possible cause.

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    run time error ''6" : Overflow

    Thank you

  12. #12

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    run time error ''6" : Overflow

    Thank you

  13. #13
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    An overflow error may indicate that you are attempting to store a value that is too large in one of the variables you have defined. Since we cannot see your "Dim" statements, it is hard to say which one. You should have some "Dim" statements in your code. If so, post them. If not, add "Option Explicit" as the first line of your code. You will then get different errors until you properly Dimension your variables.

  14. #14

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Thank you. I have a lot of Dim" statements in your code. This is the last "Dim" before the mistake but there are also plenty of "Dim" before the posted one

    Dim pProDlgFact As IProgressDialogFactory
    Dim pStepPro As IStepProgressor
    Dim pProDlg As IProgressDialog2
    Dim ptrkCan As ITrackCancel
    Set ptrkCan = New CancelTracker
    Set pProDlgFact = New ProgressDialogFactory
    Set pProDlg = pProDlgFact.Create(ptrkCan, Application.hWnd)
    pProDlg.CancelEnabled = True
    pProDlg.Title = "Prepare running for Each Grid..."
    pProDlg.Animation = esriProgressGlobe
    Set pStepPro = pProDlg

    pStepPro.MinRange = 1
    pStepPro.MaxRange = TotCellNo - 1
    pStepPro.StepValue = 1

  15. #15

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Thank you. I have a lot of Dim" statements in your code. This is the last "Dim" before the mistake but there are also plenty of "Dim" before the posted one

    Dim pProDlgFact As IProgressDialogFactory
    Dim pStepPro As IStepProgressor
    Dim pProDlg As IProgressDialog2
    Dim ptrkCan As ITrackCancel
    Set ptrkCan = New CancelTracker
    Set pProDlgFact = New ProgressDialogFactory
    Set pProDlg = pProDlgFact.Create(ptrkCan, Application.hWnd)
    pProDlg.CancelEnabled = True
    pProDlg.Title = "Prepare running for Each Grid..."
    pProDlg.Animation = esriProgressGlobe
    Set pStepPro = pProDlg

    pStepPro.MinRange = 1
    pStepPro.MaxRange = TotCellNo - 1
    pStepPro.StepValue = 1

  16. #16
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    The Dim statements we need to see are the ones for the variables in the line that is causing the error:

    Code:
    Dim X As ????
    Dim Y As ????
    Dim DEM As ????
    Dim Slope As ????
    Dim Landuse As ????
    Dim Soil As ????
    Dim Climate As ????
    Dim Country As ????
    Dim FER As ????
    Dim MaxIrr As ????

  17. #17

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Dim DEM As Integer
    Dim Slope As Integer
    Dim s As Single
    Dim Landuse As Integer
    Dim Soil As Integer
    Dim Climate As Long
    Dim IRR As Integer
    Dim Area As Integer
    Dim Country As Integer
    'Dim FER As Integer
    Dim MaxIrr As Integer
    Dim ColNo As Integer
    Dim RowNo As Integer

  18. #18

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Dim DEM As Integer
    Dim Slope As Integer
    Dim s As Single
    Dim Landuse As Integer
    Dim Soil As Integer
    Dim Climate As Long
    Dim IRR As Integer
    Dim Area As Integer
    Dim Country As Integer
    'Dim FER As Integer
    Dim MaxIrr As Integer
    Dim ColNo As Integer
    Dim RowNo As Integer

  19. #19
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    It looks like most of your variables are Integers. Those have a maximum value range of -32,768 to 32,767. If the values you are trying to Input into them are outside that range, you will get the error you are seeing. Try changing them to Long variables to see what happens.

  20. #20

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    I am putting values from 22.5052688843893 to 39.565108042713

  21. #21
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA error

    longs and integers can only hold whole numbers,
    looks like the values should be doubles, but variants would work too

    try to avoid double posting, it is a fault in the forum that has never been fixed, when you get the error page that says you have to wait 30 seconds, just click back to the thread or the forum, don't click to post again
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  22. #22

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    i do not understand this post

  23. #23
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,393

    Re: VBA error

    For the Dim issue:

    Example:
    Code:
    Dim IRR As Double
    For the double post issue, only click once on the Post Quick Reply, or click Go Advanced and then click Post.

  24. #24
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA error

    i do not understand this post
    which parts in particular?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  25. #25

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    this part looks like the values should be doubles, but variants would work too
    as well as the last note I do my best.........

  26. #26

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    this part looks like the values should be doubles, but variants would work too
    as well as the last part I do my best.........

  27. #27

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    sorry the double post now posted accidentally

  28. #28
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA error

    the first part indicates that the values returned from the file would most likely be doubles, so the variables to contain them should be a double, but that you could alternatively use a variant variable, which can contain any type of value, if you are unsure what type of value will be returned, you can use a variant, or when you know what type the variant contains, can later change to that type

    the second part is just in my signature, for when i post code samples, without showing the variable dimensions in the extract
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  29. #29

    Thread Starter
    Member
    Join Date
    Aug 2019
    Posts
    57

    Re: VBA error

    Changing Dim as Double seems to work. Thank you from the bottom of my heart for your help

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