Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Need an IsConstant function (Office 97)

    In VBA for Office 97, is it possible for a module to tell if it was called with a constant or a variable? In other words, something like the following code would be great.
    <pre>Option Explicit
    '
    Sub A()
    Dim k As Integer
    B 100
    B k
    End Sub
    '
    Sub B(v As Variant)
    If isConstant(v) Then
    MsgBox "Called with a constant"
    Else
    MsgBox "Called with a variable"
    End If
    End Sub</pre>

    However, there is no IsConstant function. Is it possible to write one?

    Edited to add:
    Initially I said "Is it possible to make one up without using On Error (already done that)?"
    I lied when I said I had already done that. Just figured it would be easy, but I can't do it using an OnError either. Any solution would be appreciated; meanwhile, it's redesign time!
    TIA --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need an IsConstant function (Office 97)

    A crude approach may be.

    Instead of having 1 arg for the Sub, have two Optional args, where one is ByVal and the other is ByRef.

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Need an IsConstant function (Office 97)

    <img src=/S/razz.gif border=0 alt=razz width=25 height=17> That's a redesign, not a solution! (But it is essentially how I've solved the problem <img src=/S/grin.gif border=0 alt=grin width=15 height=15>) Thanks!
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Need an IsConstant function (Office 97)

    Once it is passed into the routine as an argument, it *is* a variable. The only way I can think of to test it's origins would be to declare the argument ByRef and then try to change the value in the routine. If you can't set it, it's definitely a constant. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

Posting Permissions

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