+ Reply to Thread
Results 1 to 23 of 23

How to make error handle for mis-typed variable?

Hybrid View

  1. #1
    RB Smissaert
    Guest

    Re: How to make error handle for mis-typed variable?

    Do I conclude then that there is just no solution for this?

    RBS

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > Have the following situation:
    > An .xla file will import a Sub from a text file and then run it like this:
    >
    > Dim strSub as String
    >
    > 'some code here to get the Sub imported
    > Application.Run strSub
    >
    > Now it is possible that in this imported Sub are variables that are not
    > defined publicly, so there
    > will be a compile error, variable not defined.
    > As this is not a runtime error I am not sure this error can be handled
    > gracefully, but I would be interested
    > in any suggestions how this could be done.
    >
    >
    > RBS
    >



  2. #2
    Dave Peterson
    Guest

    Re: How to make error handle for mis-typed variable?

    If they're public variables, maybe you could put them in the same module so that
    their declaratations get imported, too.

    But I think I would try to rewrite the sub so that any variables that it needs
    are passed as parameters.

    Then I could just pass the parms I need in the line that calls the sub.

    RB Smissaert wrote:
    >
    > Do I conclude then that there is just no solution for this?
    >
    > RBS
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > > Have the following situation:
    > > An .xla file will import a Sub from a text file and then run it like this:
    > >
    > > Dim strSub as String
    > >
    > > 'some code here to get the Sub imported
    > > Application.Run strSub
    > >
    > > Now it is possible that in this imported Sub are variables that are not
    > > defined publicly, so there
    > > will be a compile error, variable not defined.
    > > As this is not a runtime error I am not sure this error can be handled
    > > gracefully, but I would be interested
    > > in any suggestions how this could be done.
    > >
    > >
    > > RBS
    > >


    --

    Dave Peterson

  3. #3
    RB Smissaert
    Guest

    Re: How to make error handle for mis-typed variable?

    I am not sure how that would work.
    In it's most simple form this is how the situation is:

    In Add-in:

    Public VarABC as String

    Sub RunImportedSub()
    Application.Run strImportedSub
    End Sub

    In text file:

    Sub strImportedSub()
    VarABZ = "test"
    End Sub

    Then VarABZ is nowhere declared in the add-in and the compile error occurs.
    I can't alter the text files as they are with different people in different
    places.
    All I can do is alter the add-in to deal with this.


    RBS



    "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > If they're public variables, maybe you could put them in the same module
    > so that
    > their declaratations get imported, too.
    >
    > But I think I would try to rewrite the sub so that any variables that it
    > needs
    > are passed as parameters.
    >
    > Then I could just pass the parms I need in the line that calls the sub.
    >
    > RB Smissaert wrote:
    >>
    >> Do I conclude then that there is just no solution for this?
    >>
    >> RBS
    >>
    >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    >> > Have the following situation:
    >> > An .xla file will import a Sub from a text file and then run it like
    >> > this:
    >> >
    >> > Dim strSub as String
    >> >
    >> > 'some code here to get the Sub imported
    >> > Application.Run strSub
    >> >
    >> > Now it is possible that in this imported Sub are variables that are
    >> > not
    >> > defined publicly, so there
    >> > will be a compile error, variable not defined.
    >> > As this is not a runtime error I am not sure this error can be handled
    >> > gracefully, but I would be interested
    >> > in any suggestions how this could be done.
    >> >
    >> >
    >> > RBS
    >> >

    >
    > --
    >
    > Dave Peterson



  4. #4
    Dave Peterson
    Guest

    Re: How to make error handle for mis-typed variable?

    I don't understand this sentence:

    "Then VarABZ is nowhere declared in the add-in and the compile error occurs."
    Because you said you had this in the addin:

    In Add-in:
    Public VarABC as String

    ==
    In my simple test, I had this in a text file:

    Option Explicit
    Sub test01A()
    VarABC = "hi"
    MsgBox VarABC
    End Sub

    In my other workbook, I had this in module1:

    Option Explicit
    Public VarABC As String
    Sub ImportTheTextFile()
    Dim myFileName As String
    myFileName = "C:\my documents\excel\test1.bas"
    ThisWorkbook.VBProject.VBComponents.Import myFileName
    Application.Run ThisWorkbook.Name & "!test01a"
    End Sub

    And it worked fine (xl2003).

    RB Smissaert wrote:
    >
    > I am not sure how that would work.
    > In it's most simple form this is how the situation is:
    >
    > In Add-in:
    >
    > Public VarABC as String
    >
    > Sub RunImportedSub()
    > Application.Run strImportedSub
    > End Sub
    >
    > In text file:
    >
    > Sub strImportedSub()
    > VarABZ = "test"
    > End Sub
    >
    > Then VarABZ is nowhere declared in the add-in and the compile error occurs.
    > I can't alter the text files as they are with different people in different
    > places.
    > All I can do is alter the add-in to deal with this.
    >
    > RBS
    >
    > "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > > If they're public variables, maybe you could put them in the same module
    > > so that
    > > their declaratations get imported, too.
    > >
    > > But I think I would try to rewrite the sub so that any variables that it
    > > needs
    > > are passed as parameters.
    > >
    > > Then I could just pass the parms I need in the line that calls the sub.
    > >
    > > RB Smissaert wrote:
    > >>
    > >> Do I conclude then that there is just no solution for this?
    > >>
    > >> RBS
    > >>
    > >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > >> > Have the following situation:
    > >> > An .xla file will import a Sub from a text file and then run it like
    > >> > this:
    > >> >
    > >> > Dim strSub as String
    > >> >
    > >> > 'some code here to get the Sub imported
    > >> > Application.Run strSub
    > >> >
    > >> > Now it is possible that in this imported Sub are variables that are
    > >> > not
    > >> > defined publicly, so there
    > >> > will be a compile error, variable not defined.
    > >> > As this is not a runtime error I am not sure this error can be handled
    > >> > gracefully, but I would be interested
    > >> > in any suggestions how this could be done.
    > >> >
    > >> >
    > >> > RBS
    > >> >

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

  5. #5
    RB Smissaert
    Guest

    Re: How to make error handle for mis-typed variable?

    OK, I have an add-in with a public variable:
    Dim VarABC as string

    Now a Sub gets imported into the VBE from a text file. This textfile is just
    completely unrelated to the add-in,
    so the variables can be anything.
    Now in this Sub in the textfile is a variable VarABZ. This really should be
    VarABC, but it isn't.
    Now when this Sub is imported the variable VarABZ isn't declared anywhere
    (as the variable should be VarABC)
    and there will be a compile error.

    Can't make it any clearer. The more I think about it, the more I think there
    is no solution for this other than
    somehow scanning the whole textfile before importing it in the VBE.


    RBS

    "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    news:42751BD7.E206F66C@netscapeXSPAM.com...
    >I don't understand this sentence:
    >
    > "Then VarABZ is nowhere declared in the add-in and the compile error
    > occurs."
    > Because you said you had this in the addin:
    >
    > In Add-in:
    > Public VarABC as String
    >
    > ==
    > In my simple test, I had this in a text file:
    >
    > Option Explicit
    > Sub test01A()
    > VarABC = "hi"
    > MsgBox VarABC
    > End Sub
    >
    > In my other workbook, I had this in module1:
    >
    > Option Explicit
    > Public VarABC As String
    > Sub ImportTheTextFile()
    > Dim myFileName As String
    > myFileName = "C:\my documents\excel\test1.bas"
    > ThisWorkbook.VBProject.VBComponents.Import myFileName
    > Application.Run ThisWorkbook.Name & "!test01a"
    > End Sub
    >
    > And it worked fine (xl2003).
    >
    > RB Smissaert wrote:
    >>
    >> I am not sure how that would work.
    >> In it's most simple form this is how the situation is:
    >>
    >> In Add-in:
    >>
    >> Public VarABC as String
    >>
    >> Sub RunImportedSub()
    >> Application.Run strImportedSub
    >> End Sub
    >>
    >> In text file:
    >>
    >> Sub strImportedSub()
    >> VarABZ = "test"
    >> End Sub
    >>
    >> Then VarABZ is nowhere declared in the add-in and the compile error
    >> occurs.
    >> I can't alter the text files as they are with different people in
    >> different
    >> places.
    >> All I can do is alter the add-in to deal with this.
    >>
    >> RBS
    >>
    >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    >> > If they're public variables, maybe you could put them in the same
    >> > module
    >> > so that
    >> > their declaratations get imported, too.
    >> >
    >> > But I think I would try to rewrite the sub so that any variables that
    >> > it
    >> > needs
    >> > are passed as parameters.
    >> >
    >> > Then I could just pass the parms I need in the line that calls the sub.
    >> >
    >> > RB Smissaert wrote:
    >> >>
    >> >> Do I conclude then that there is just no solution for this?
    >> >>
    >> >> RBS
    >> >>
    >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    >> >> > Have the following situation:
    >> >> > An .xla file will import a Sub from a text file and then run it like
    >> >> > this:
    >> >> >
    >> >> > Dim strSub as String
    >> >> >
    >> >> > 'some code here to get the Sub imported
    >> >> > Application.Run strSub
    >> >> >
    >> >> > Now it is possible that in this imported Sub are variables that are
    >> >> > not
    >> >> > defined publicly, so there
    >> >> > will be a compile error, variable not defined.
    >> >> > As this is not a runtime error I am not sure this error can be
    >> >> > handled
    >> >> > gracefully, but I would be interested
    >> >> > in any suggestions how this could be done.
    >> >> >
    >> >> >
    >> >> > RBS
    >> >> >
    >> >
    >> > --
    >> >
    >> > Dave Peterson

    >
    > --
    >
    > Dave Peterson



  6. #6
    Vasant Nanavati
    Guest

    Re: How to make error handle for mis-typed variable?

    Hi RBS:

    I guess the only way would be to search for the string VarABC in the text
    file, and not run the sub if it is not found but throw up your own graceful
    error message . But I'm assuming that this is a simplified case and the
    real-life scenario is more complex.

    Regards,

    Vasant

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:eyWCbunTFHA.3696@TK2MSFTNGP15.phx.gbl...
    > OK, I have an add-in with a public variable:
    > Dim VarABC as string
    >
    > Now a Sub gets imported into the VBE from a text file. This textfile is

    just
    > completely unrelated to the add-in,
    > so the variables can be anything.
    > Now in this Sub in the textfile is a variable VarABZ. This really should

    be
    > VarABC, but it isn't.
    > Now when this Sub is imported the variable VarABZ isn't declared anywhere
    > (as the variable should be VarABC)
    > and there will be a compile error.
    >
    > Can't make it any clearer. The more I think about it, the more I think

    there
    > is no solution for this other than
    > somehow scanning the whole textfile before importing it in the VBE.
    >
    >
    > RBS
    >
    > "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > news:42751BD7.E206F66C@netscapeXSPAM.com...
    > >I don't understand this sentence:
    > >
    > > "Then VarABZ is nowhere declared in the add-in and the compile error
    > > occurs."
    > > Because you said you had this in the addin:
    > >
    > > In Add-in:
    > > Public VarABC as String
    > >
    > > ==
    > > In my simple test, I had this in a text file:
    > >
    > > Option Explicit
    > > Sub test01A()
    > > VarABC = "hi"
    > > MsgBox VarABC
    > > End Sub
    > >
    > > In my other workbook, I had this in module1:
    > >
    > > Option Explicit
    > > Public VarABC As String
    > > Sub ImportTheTextFile()
    > > Dim myFileName As String
    > > myFileName = "C:\my documents\excel\test1.bas"
    > > ThisWorkbook.VBProject.VBComponents.Import myFileName
    > > Application.Run ThisWorkbook.Name & "!test01a"
    > > End Sub
    > >
    > > And it worked fine (xl2003).
    > >
    > > RB Smissaert wrote:
    > >>
    > >> I am not sure how that would work.
    > >> In it's most simple form this is how the situation is:
    > >>
    > >> In Add-in:
    > >>
    > >> Public VarABC as String
    > >>
    > >> Sub RunImportedSub()
    > >> Application.Run strImportedSub
    > >> End Sub
    > >>
    > >> In text file:
    > >>
    > >> Sub strImportedSub()
    > >> VarABZ = "test"
    > >> End Sub
    > >>
    > >> Then VarABZ is nowhere declared in the add-in and the compile error
    > >> occurs.
    > >> I can't alter the text files as they are with different people in
    > >> different
    > >> places.
    > >> All I can do is alter the add-in to deal with this.
    > >>
    > >> RBS
    > >>
    > >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > >> > If they're public variables, maybe you could put them in the same
    > >> > module
    > >> > so that
    > >> > their declaratations get imported, too.
    > >> >
    > >> > But I think I would try to rewrite the sub so that any variables that
    > >> > it
    > >> > needs
    > >> > are passed as parameters.
    > >> >
    > >> > Then I could just pass the parms I need in the line that calls the

    sub.
    > >> >
    > >> > RB Smissaert wrote:
    > >> >>
    > >> >> Do I conclude then that there is just no solution for this?
    > >> >>
    > >> >> RBS
    > >> >>
    > >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > >> >> > Have the following situation:
    > >> >> > An .xla file will import a Sub from a text file and then run it

    like
    > >> >> > this:
    > >> >> >
    > >> >> > Dim strSub as String
    > >> >> >
    > >> >> > 'some code here to get the Sub imported
    > >> >> > Application.Run strSub
    > >> >> >
    > >> >> > Now it is possible that in this imported Sub are variables that

    are
    > >> >> > not
    > >> >> > defined publicly, so there
    > >> >> > will be a compile error, variable not defined.
    > >> >> > As this is not a runtime error I am not sure this error can be
    > >> >> > handled
    > >> >> > gracefully, but I would be interested
    > >> >> > in any suggestions how this could be done.
    > >> >> >
    > >> >> >
    > >> >> > RBS
    > >> >> >
    > >> >
    > >> > --
    > >> >
    > >> > Dave Peterson

    > >
    > > --
    > >
    > > Dave Peterson

    >




  7. #7
    RB Smissaert
    Guest

    Re: How to make error handle for mis-typed variable?

    His Vasant,

    Yes, it is a very much simplified example.
    On the other hand this is doable as there is only a limited number of
    variables
    that could be missing. All the textfiles are written by myself (up to now)
    so I know
    what to expect.
    I was just hoping for some elegant, simple solution, but it seems there
    isn't.
    I suppose the solution to avoid this problem in the future is to give every
    text file Sub
    a unique identifier, like a version number or a GUID, so you can check
    easily that you
    are dealing with the right text.

    RBS


    "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    news:Ozusw5nTFHA.2420@TK2MSFTNGP12.phx.gbl...
    > Hi RBS:
    >
    > I guess the only way would be to search for the string VarABC in the text
    > file, and not run the sub if it is not found but throw up your own
    > graceful
    > error message . But I'm assuming that this is a simplified case and the
    > real-life scenario is more complex.
    >
    > Regards,
    >
    > Vasant
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:eyWCbunTFHA.3696@TK2MSFTNGP15.phx.gbl...
    >> OK, I have an add-in with a public variable:
    >> Dim VarABC as string
    >>
    >> Now a Sub gets imported into the VBE from a text file. This textfile is

    > just
    >> completely unrelated to the add-in,
    >> so the variables can be anything.
    >> Now in this Sub in the textfile is a variable VarABZ. This really should

    > be
    >> VarABC, but it isn't.
    >> Now when this Sub is imported the variable VarABZ isn't declared anywhere
    >> (as the variable should be VarABC)
    >> and there will be a compile error.
    >>
    >> Can't make it any clearer. The more I think about it, the more I think

    > there
    >> is no solution for this other than
    >> somehow scanning the whole textfile before importing it in the VBE.
    >>
    >>
    >> RBS
    >>
    >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    >> news:42751BD7.E206F66C@netscapeXSPAM.com...
    >> >I don't understand this sentence:
    >> >
    >> > "Then VarABZ is nowhere declared in the add-in and the compile error
    >> > occurs."
    >> > Because you said you had this in the addin:
    >> >
    >> > In Add-in:
    >> > Public VarABC as String
    >> >
    >> > ==
    >> > In my simple test, I had this in a text file:
    >> >
    >> > Option Explicit
    >> > Sub test01A()
    >> > VarABC = "hi"
    >> > MsgBox VarABC
    >> > End Sub
    >> >
    >> > In my other workbook, I had this in module1:
    >> >
    >> > Option Explicit
    >> > Public VarABC As String
    >> > Sub ImportTheTextFile()
    >> > Dim myFileName As String
    >> > myFileName = "C:\my documents\excel\test1.bas"
    >> > ThisWorkbook.VBProject.VBComponents.Import myFileName
    >> > Application.Run ThisWorkbook.Name & "!test01a"
    >> > End Sub
    >> >
    >> > And it worked fine (xl2003).
    >> >
    >> > RB Smissaert wrote:
    >> >>
    >> >> I am not sure how that would work.
    >> >> In it's most simple form this is how the situation is:
    >> >>
    >> >> In Add-in:
    >> >>
    >> >> Public VarABC as String
    >> >>
    >> >> Sub RunImportedSub()
    >> >> Application.Run strImportedSub
    >> >> End Sub
    >> >>
    >> >> In text file:
    >> >>
    >> >> Sub strImportedSub()
    >> >> VarABZ = "test"
    >> >> End Sub
    >> >>
    >> >> Then VarABZ is nowhere declared in the add-in and the compile error
    >> >> occurs.
    >> >> I can't alter the text files as they are with different people in
    >> >> different
    >> >> places.
    >> >> All I can do is alter the add-in to deal with this.
    >> >>
    >> >> RBS
    >> >>
    >> >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    >> >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    >> >> > If they're public variables, maybe you could put them in the same
    >> >> > module
    >> >> > so that
    >> >> > their declaratations get imported, too.
    >> >> >
    >> >> > But I think I would try to rewrite the sub so that any variables
    >> >> > that
    >> >> > it
    >> >> > needs
    >> >> > are passed as parameters.
    >> >> >
    >> >> > Then I could just pass the parms I need in the line that calls the

    > sub.
    >> >> >
    >> >> > RB Smissaert wrote:
    >> >> >>
    >> >> >> Do I conclude then that there is just no solution for this?
    >> >> >>
    >> >> >> RBS
    >> >> >>
    >> >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    >> >> >> > Have the following situation:
    >> >> >> > An .xla file will import a Sub from a text file and then run it

    > like
    >> >> >> > this:
    >> >> >> >
    >> >> >> > Dim strSub as String
    >> >> >> >
    >> >> >> > 'some code here to get the Sub imported
    >> >> >> > Application.Run strSub
    >> >> >> >
    >> >> >> > Now it is possible that in this imported Sub are variables that

    > are
    >> >> >> > not
    >> >> >> > defined publicly, so there
    >> >> >> > will be a compile error, variable not defined.
    >> >> >> > As this is not a runtime error I am not sure this error can be
    >> >> >> > handled
    >> >> >> > gracefully, but I would be interested
    >> >> >> > in any suggestions how this could be done.
    >> >> >> >
    >> >> >> >
    >> >> >> > RBS
    >> >> >> >
    >> >> >
    >> >> > --
    >> >> >
    >> >> > Dave Peterson
    >> >
    >> > --
    >> >
    >> > Dave Peterson

    >>

    >
    >



  8. #8
    Dave Peterson
    Guest

    Re: How to make error handle for mis-typed variable?

    Do you have "option explicit" in your text file?

    If yes, try removing it. Again, that variable won't be initialized.



    RB Smissaert wrote:
    >
    > OK, I have an add-in with a public variable:
    > Dim VarABC as string
    >
    > Now a Sub gets imported into the VBE from a text file. This textfile is just
    > completely unrelated to the add-in,
    > so the variables can be anything.
    > Now in this Sub in the textfile is a variable VarABZ. This really should be
    > VarABC, but it isn't.
    > Now when this Sub is imported the variable VarABZ isn't declared anywhere
    > (as the variable should be VarABC)
    > and there will be a compile error.
    >
    > Can't make it any clearer. The more I think about it, the more I think there
    > is no solution for this other than
    > somehow scanning the whole textfile before importing it in the VBE.
    >
    > RBS
    >
    > "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > news:42751BD7.E206F66C@netscapeXSPAM.com...
    > >I don't understand this sentence:
    > >
    > > "Then VarABZ is nowhere declared in the add-in and the compile error
    > > occurs."
    > > Because you said you had this in the addin:
    > >
    > > In Add-in:
    > > Public VarABC as String
    > >
    > > ==
    > > In my simple test, I had this in a text file:
    > >
    > > Option Explicit
    > > Sub test01A()
    > > VarABC = "hi"
    > > MsgBox VarABC
    > > End Sub
    > >
    > > In my other workbook, I had this in module1:
    > >
    > > Option Explicit
    > > Public VarABC As String
    > > Sub ImportTheTextFile()
    > > Dim myFileName As String
    > > myFileName = "C:\my documents\excel\test1.bas"
    > > ThisWorkbook.VBProject.VBComponents.Import myFileName
    > > Application.Run ThisWorkbook.Name & "!test01a"
    > > End Sub
    > >
    > > And it worked fine (xl2003).
    > >
    > > RB Smissaert wrote:
    > >>
    > >> I am not sure how that would work.
    > >> In it's most simple form this is how the situation is:
    > >>
    > >> In Add-in:
    > >>
    > >> Public VarABC as String
    > >>
    > >> Sub RunImportedSub()
    > >> Application.Run strImportedSub
    > >> End Sub
    > >>
    > >> In text file:
    > >>
    > >> Sub strImportedSub()
    > >> VarABZ = "test"
    > >> End Sub
    > >>
    > >> Then VarABZ is nowhere declared in the add-in and the compile error
    > >> occurs.
    > >> I can't alter the text files as they are with different people in
    > >> different
    > >> places.
    > >> All I can do is alter the add-in to deal with this.
    > >>
    > >> RBS
    > >>
    > >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > >> > If they're public variables, maybe you could put them in the same
    > >> > module
    > >> > so that
    > >> > their declaratations get imported, too.
    > >> >
    > >> > But I think I would try to rewrite the sub so that any variables that
    > >> > it
    > >> > needs
    > >> > are passed as parameters.
    > >> >
    > >> > Then I could just pass the parms I need in the line that calls the sub.
    > >> >
    > >> > RB Smissaert wrote:
    > >> >>
    > >> >> Do I conclude then that there is just no solution for this?
    > >> >>
    > >> >> RBS
    > >> >>
    > >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > >> >> > Have the following situation:
    > >> >> > An .xla file will import a Sub from a text file and then run it like
    > >> >> > this:
    > >> >> >
    > >> >> > Dim strSub as String
    > >> >> >
    > >> >> > 'some code here to get the Sub imported
    > >> >> > Application.Run strSub
    > >> >> >
    > >> >> > Now it is possible that in this imported Sub are variables that are
    > >> >> > not
    > >> >> > defined publicly, so there
    > >> >> > will be a compile error, variable not defined.
    > >> >> > As this is not a runtime error I am not sure this error can be
    > >> >> > handled
    > >> >> > gracefully, but I would be interested
    > >> >> > in any suggestions how this could be done.
    > >> >> >
    > >> >> >
    > >> >> > RBS
    > >> >> >
    > >> >
    > >> > --
    > >> >
    > >> > Dave Peterson

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

  9. #9
    Dave Peterson
    Guest

    Re: How to make error handle for mis-typed variable?

    Ps. Inside the VBE, I have tools|options|editor tab|"require variable
    declaration" checked.

    But when I imported the text file manually into its own module, I didn't get the
    "Option Explicit" at the top--unless it was part of the text file.

    I tried importing it via code and that matched, too.

    ===
    The only way I've seen that undeclared variable message is when I have "option
    explicit" at the top of the module. Turn it off and no problem. (Well, except
    for what the code is really doing!)

    RB Smissaert wrote:
    >
    > OK, I have an add-in with a public variable:
    > Dim VarABC as string
    >
    > Now a Sub gets imported into the VBE from a text file. This textfile is just
    > completely unrelated to the add-in,
    > so the variables can be anything.
    > Now in this Sub in the textfile is a variable VarABZ. This really should be
    > VarABC, but it isn't.
    > Now when this Sub is imported the variable VarABZ isn't declared anywhere
    > (as the variable should be VarABC)
    > and there will be a compile error.
    >
    > Can't make it any clearer. The more I think about it, the more I think there
    > is no solution for this other than
    > somehow scanning the whole textfile before importing it in the VBE.
    >
    > RBS
    >
    > "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > news:42751BD7.E206F66C@netscapeXSPAM.com...
    > >I don't understand this sentence:
    > >
    > > "Then VarABZ is nowhere declared in the add-in and the compile error
    > > occurs."
    > > Because you said you had this in the addin:
    > >
    > > In Add-in:
    > > Public VarABC as String
    > >
    > > ==
    > > In my simple test, I had this in a text file:
    > >
    > > Option Explicit
    > > Sub test01A()
    > > VarABC = "hi"
    > > MsgBox VarABC
    > > End Sub
    > >
    > > In my other workbook, I had this in module1:
    > >
    > > Option Explicit
    > > Public VarABC As String
    > > Sub ImportTheTextFile()
    > > Dim myFileName As String
    > > myFileName = "C:\my documents\excel\test1.bas"
    > > ThisWorkbook.VBProject.VBComponents.Import myFileName
    > > Application.Run ThisWorkbook.Name & "!test01a"
    > > End Sub
    > >
    > > And it worked fine (xl2003).
    > >
    > > RB Smissaert wrote:
    > >>
    > >> I am not sure how that would work.
    > >> In it's most simple form this is how the situation is:
    > >>
    > >> In Add-in:
    > >>
    > >> Public VarABC as String
    > >>
    > >> Sub RunImportedSub()
    > >> Application.Run strImportedSub
    > >> End Sub
    > >>
    > >> In text file:
    > >>
    > >> Sub strImportedSub()
    > >> VarABZ = "test"
    > >> End Sub
    > >>
    > >> Then VarABZ is nowhere declared in the add-in and the compile error
    > >> occurs.
    > >> I can't alter the text files as they are with different people in
    > >> different
    > >> places.
    > >> All I can do is alter the add-in to deal with this.
    > >>
    > >> RBS
    > >>
    > >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > >> > If they're public variables, maybe you could put them in the same
    > >> > module
    > >> > so that
    > >> > their declaratations get imported, too.
    > >> >
    > >> > But I think I would try to rewrite the sub so that any variables that
    > >> > it
    > >> > needs
    > >> > are passed as parameters.
    > >> >
    > >> > Then I could just pass the parms I need in the line that calls the sub.
    > >> >
    > >> > RB Smissaert wrote:
    > >> >>
    > >> >> Do I conclude then that there is just no solution for this?
    > >> >>
    > >> >> RBS
    > >> >>
    > >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > >> >> > Have the following situation:
    > >> >> > An .xla file will import a Sub from a text file and then run it like
    > >> >> > this:
    > >> >> >
    > >> >> > Dim strSub as String
    > >> >> >
    > >> >> > 'some code here to get the Sub imported
    > >> >> > Application.Run strSub
    > >> >> >
    > >> >> > Now it is possible that in this imported Sub are variables that are
    > >> >> > not
    > >> >> > defined publicly, so there
    > >> >> > will be a compile error, variable not defined.
    > >> >> > As this is not a runtime error I am not sure this error can be
    > >> >> > handled
    > >> >> > gracefully, but I would be interested
    > >> >> > in any suggestions how this could be done.
    > >> >> >
    > >> >> >
    > >> >> > RBS
    > >> >> >
    > >> >
    > >> > --
    > >> >
    > >> > Dave Peterson

    > >
    > > --
    > >
    > > Dave Peterson


    --

    Dave Peterson

  10. #10
    Peter T
    Guest

    Re: How to make error handle for mis-typed variable?

    Does the code fail due to Option Explicit, either in an existing module if
    the macro is imported line by line, or top of the text if imported as a new
    module (per Dave's example). If so the solution seems obvious.

    Or, is the compile problem due to some attempted usage of the variable, and
    if so in the imported proc or when passed elsewhere in the project.

    Regards,
    Peter T

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:eyWCbunTFHA.3696@TK2MSFTNGP15.phx.gbl...
    > OK, I have an add-in with a public variable:
    > Dim VarABC as string
    >
    > Now a Sub gets imported into the VBE from a text file. This textfile is

    just
    > completely unrelated to the add-in,
    > so the variables can be anything.
    > Now in this Sub in the textfile is a variable VarABZ. This really should

    be
    > VarABC, but it isn't.
    > Now when this Sub is imported the variable VarABZ isn't declared anywhere
    > (as the variable should be VarABC)
    > and there will be a compile error.
    >
    > Can't make it any clearer. The more I think about it, the more I think

    there
    > is no solution for this other than
    > somehow scanning the whole textfile before importing it in the VBE.
    >
    >
    > RBS
    >
    > "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > news:42751BD7.E206F66C@netscapeXSPAM.com...
    > >I don't understand this sentence:
    > >
    > > "Then VarABZ is nowhere declared in the add-in and the compile error
    > > occurs."
    > > Because you said you had this in the addin:
    > >
    > > In Add-in:
    > > Public VarABC as String
    > >
    > > ==
    > > In my simple test, I had this in a text file:
    > >
    > > Option Explicit
    > > Sub test01A()
    > > VarABC = "hi"
    > > MsgBox VarABC
    > > End Sub
    > >
    > > In my other workbook, I had this in module1:
    > >
    > > Option Explicit
    > > Public VarABC As String
    > > Sub ImportTheTextFile()
    > > Dim myFileName As String
    > > myFileName = "C:\my documents\excel\test1.bas"
    > > ThisWorkbook.VBProject.VBComponents.Import myFileName
    > > Application.Run ThisWorkbook.Name & "!test01a"
    > > End Sub
    > >
    > > And it worked fine (xl2003).
    > >
    > > RB Smissaert wrote:
    > >>
    > >> I am not sure how that would work.
    > >> In it's most simple form this is how the situation is:
    > >>
    > >> In Add-in:
    > >>
    > >> Public VarABC as String
    > >>
    > >> Sub RunImportedSub()
    > >> Application.Run strImportedSub
    > >> End Sub
    > >>
    > >> In text file:
    > >>
    > >> Sub strImportedSub()
    > >> VarABZ = "test"
    > >> End Sub
    > >>
    > >> Then VarABZ is nowhere declared in the add-in and the compile error
    > >> occurs.
    > >> I can't alter the text files as they are with different people in
    > >> different
    > >> places.
    > >> All I can do is alter the add-in to deal with this.
    > >>
    > >> RBS
    > >>
    > >> "Dave Peterson" <ec35720@netscapeXSPAM.com> wrote in message
    > >> news:4274C20B.439BA9EB@netscapeXSPAM.com...
    > >> > If they're public variables, maybe you could put them in the same
    > >> > module
    > >> > so that
    > >> > their declaratations get imported, too.
    > >> >
    > >> > But I think I would try to rewrite the sub so that any variables that
    > >> > it
    > >> > needs
    > >> > are passed as parameters.
    > >> >
    > >> > Then I could just pass the parms I need in the line that calls the

    sub.
    > >> >
    > >> > RB Smissaert wrote:
    > >> >>
    > >> >> Do I conclude then that there is just no solution for this?
    > >> >>
    > >> >> RBS
    > >> >>
    > >> >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > >> >> news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > >> >> > Have the following situation:
    > >> >> > An .xla file will import a Sub from a text file and then run it

    like
    > >> >> > this:
    > >> >> >
    > >> >> > Dim strSub as String
    > >> >> >
    > >> >> > 'some code here to get the Sub imported
    > >> >> > Application.Run strSub
    > >> >> >
    > >> >> > Now it is possible that in this imported Sub are variables that

    are
    > >> >> > not
    > >> >> > defined publicly, so there
    > >> >> > will be a compile error, variable not defined.
    > >> >> > As this is not a runtime error I am not sure this error can be
    > >> >> > handled
    > >> >> > gracefully, but I would be interested
    > >> >> > in any suggestions how this could be done.
    > >> >> >
    > >> >> >
    > >> >> > RBS
    > >> >> >
    > >> >
    > >> > --
    > >> >
    > >> > Dave Peterson

    > >
    > > --
    > >
    > > Dave Peterson

    >




  11. #11
    Vasant Nanavati
    Guest

    Re: How to make error handle for mis-typed variable?

    Hi RBS:

    Can you give an example of the imported sub where the variable is not
    declared publicly, giving rise to a compile error? I'm not sure I completely
    understand the problem. Is strSub a different sub at different times, with
    different sets of variables?

    Regards,

    Vasant




    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:O7$GQJkTFHA.2768@tk2msftngp13.phx.gbl...
    > Do I conclude then that there is just no solution for this?
    >
    > RBS
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > > Have the following situation:
    > > An .xla file will import a Sub from a text file and then run it like

    this:
    > >
    > > Dim strSub as String
    > >
    > > 'some code here to get the Sub imported
    > > Application.Run strSub
    > >
    > > Now it is possible that in this imported Sub are variables that are not
    > > defined publicly, so there
    > > will be a compile error, variable not defined.
    > > As this is not a runtime error I am not sure this error can be handled
    > > gracefully, but I would be interested
    > > in any suggestions how this could be done.
    > >
    > >
    > > RBS
    > >

    >




  12. #12
    Vasant Nanavati
    Guest

    Re: How to make error handle for mis-typed variable?

    RBS:

    OK, got it now. That's a challenge ... I can't quite figure it out at the
    moment. Perhaps, as you said, there is no good solution.

    I guess you're trying to avoid the "Compile error in hidden module" message.
    I'm not sure how you would handle the error much more gracefully than that
    anyway, since your add-in is not going to know the exact nature of the
    error.

    Regards,

    Vasant

    "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    news:%2353DaLmTFHA.3392@TK2MSFTNGP12.phx.gbl...
    > Hi RBS:
    >
    > Can you give an example of the imported sub where the variable is not
    > declared publicly, giving rise to a compile error? I'm not sure I

    completely
    > understand the problem. Is strSub a different sub at different times, with
    > different sets of variables?
    >
    > Regards,
    >
    > Vasant
    >
    >
    >
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:O7$GQJkTFHA.2768@tk2msftngp13.phx.gbl...
    > > Do I conclude then that there is just no solution for this?
    > >
    > > RBS
    > >
    > > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > > news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    > > > Have the following situation:
    > > > An .xla file will import a Sub from a text file and then run it like

    > this:
    > > >
    > > > Dim strSub as String
    > > >
    > > > 'some code here to get the Sub imported
    > > > Application.Run strSub
    > > >
    > > > Now it is possible that in this imported Sub are variables that are

    not
    > > > defined publicly, so there
    > > > will be a compile error, variable not defined.
    > > > As this is not a runtime error I am not sure this error can be handled
    > > > gracefully, but I would be interested
    > > > in any suggestions how this could be done.
    > > >
    > > >
    > > > RBS
    > > >

    > >

    >
    >




  13. #13
    RB Smissaert
    Guest

    Re: How to make error handle for mis-typed variable?

    Maybe the only solution is somehow to check the text before importing it in
    the VBE, but I am not sure that is worth the trouble.

    RBS


    "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    news:ObiSUQmTFHA.2392@TK2MSFTNGP10.phx.gbl...
    > RBS:
    >
    > OK, got it now. That's a challenge ... I can't quite figure it out at the
    > moment. Perhaps, as you said, there is no good solution.
    >
    > I guess you're trying to avoid the "Compile error in hidden module"
    > message.
    > I'm not sure how you would handle the error much more gracefully than that
    > anyway, since your add-in is not going to know the exact nature of the
    > error.
    >
    > Regards,
    >
    > Vasant
    >
    > "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    > news:%2353DaLmTFHA.3392@TK2MSFTNGP12.phx.gbl...
    >> Hi RBS:
    >>
    >> Can you give an example of the imported sub where the variable is not
    >> declared publicly, giving rise to a compile error? I'm not sure I

    > completely
    >> understand the problem. Is strSub a different sub at different times,
    >> with
    >> different sets of variables?
    >>
    >> Regards,
    >>
    >> Vasant
    >>
    >>
    >>
    >>
    >> "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> news:O7$GQJkTFHA.2768@tk2msftngp13.phx.gbl...
    >> > Do I conclude then that there is just no solution for this?
    >> >
    >> > RBS
    >> >
    >> > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    >> > news:OlThA0$SFHA.2872@TK2MSFTNGP14.phx.gbl...
    >> > > Have the following situation:
    >> > > An .xla file will import a Sub from a text file and then run it like

    >> this:
    >> > >
    >> > > Dim strSub as String
    >> > >
    >> > > 'some code here to get the Sub imported
    >> > > Application.Run strSub
    >> > >
    >> > > Now it is possible that in this imported Sub are variables that are

    > not
    >> > > defined publicly, so there
    >> > > will be a compile error, variable not defined.
    >> > > As this is not a runtime error I am not sure this error can be
    >> > > handled
    >> > > gracefully, but I would be interested
    >> > > in any suggestions how this could be done.
    >> > >
    >> > >
    >> > > RBS
    >> > >
    >> >

    >>
    >>

    >
    >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1