+ 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?

    Vasant,

    Thanks, I didn't know that one.
    Still it doesn't help me that much.
    Rember I do:

    Sub RunningImportedSub()
    Application.Run strImportedSub
    End Sub

    I have no control over what is in strImportedSub.
    So, how could I have an error handler in Sub RunningImportedSub()
    that catches the variable in strImportedSub where IsEmpty is True, without
    causing
    a compile error?
    In fact checking all the variables doesn't even catch everything as there
    could be wrongly
    named functions and/or subs.

    RBS


    "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    news:uFL7%233oTFHA.3308@TK2MSFTNGP14.phx.gbl...
    > Hi RBS:
    >
    > IsEmpty(MyVar) will return a False if the variable has been initialized.
    >
    > For Example:
    >
    > Sub Test1()
    > Dim s As String
    > MsgBox IsEmpty(s)
    > End Sub
    >
    > Sub Test2()
    > MsgBox IsEmpty(s)
    > End Sub
    >
    > Hope this helps!
    >
    > Regards,
    >
    > Vasant
    >
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:%235irmsoTFHA.3620@TK2MSFTNGP09.phx.gbl...
    >> Peter, Dave,
    >>
    >> That is it!
    >>
    >> I had Option Explicit at the top of the module that got the code
    >> imported.
    >> If I leave this off the code will run happily even with un-declared
    >> variables.
    >> I will now have to figure out what happens when there are these

    > un-declared
    >> variables.
    >> It causes some strange behaviour or maybe not:
    >>
    >> If VarNonse = False Then
    >> Columns(2).Delete
    >> End If
    >>
    >> This will delete the column, even when the variable is declared nowhere.
    >> I suppose this is expected in that un-declared equates to false.
    >> In fact this probably is more trouble than getting the compile error as I
    >> now don't know
    >> if the variable was un-declared or declared but False.
    >>
    >> Is it possible to check somehow if a variable was declared or not?
    >>
    >> Thanks again for all the contributions; I learned something there!
    >>
    >>
    >> 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
    Vasant Nanavati
    Guest

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

    "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    news:uX7qnKpTFHA.1568@TK2MSFTNGP10.phx.gbl...
    > In fact checking all the variables doesn't even catch everything as there
    > could be wrongly
    > named functions and/or subs.


    This is the core of the problem and I don't think it has a satisfactory
    solution. Unfortunately you are working in the dark.

    I wonder if there might be a way of importing not just the sub but also all
    globally declared variables. That might alleviate the problem.

    --

    Vasant



  3. #3
    RB Smissaert
    Guest

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

    The imported text files don't normally have public or even private
    variables, although they could have.
    I think I will go with may latest reply to Peter T's post.

    RBS

    "Vasant Nanavati" <vasantn *AT* aol *DOT* com> wrote in message
    news:eThkuPpTFHA.2336@TK2MSFTNGP12.phx.gbl...
    > "RB Smissaert" <bartsmissaert@blueyonder.co.uk> wrote in message
    > news:uX7qnKpTFHA.1568@TK2MSFTNGP10.phx.gbl...
    >> In fact checking all the variables doesn't even catch everything as there
    >> could be wrongly
    >> named functions and/or subs.

    >
    > This is the core of the problem and I don't think it has a satisfactory
    > solution. Unfortunately you are working in the dark.
    >
    > I wonder if there might be a way of importing not just the sub but also
    > all
    > globally declared variables. That might alleviate the problem.
    >
    > --
    >
    > Vasant
    >
    >



+ 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