Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What data type is a constant?

    Below is pasted the Help from "Separator" (as in :
    Selection.Tables(1).Select
    Selection.Rows.ConvertToText Separator:=wdSeparateByTabs)


    How does one easily get to know what data type is a constant?

    I'm guessing that here wdSeparateByTabs would be an Integer because it has a small range of possible values, perhaps 0 through 4 or 5.



    (snip!)
    Separator Property

    Endnotes or Footnotes object: Returns a Range object that represents the endnote or footnote separator. Read-only.

    CaptionLabel object: Returns or sets the character between the chapter number and the sequence number. Can be one of the following WdSeparatorType constants: wdSeparatorColon, wdSeparatorEmDash, wdSeparatorEnDash, wdSeparatorHyphen, or wdSeparatorPeriod. Read/write Long.

    TableOfAuthorities object: Returns or sets the characters (up to five) between the sequence number and the page number. A hyphen (-) is the default character. This property corresponds to the d switch for a TOA field. Read/write String.
    (snip!)

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    The TypeName function returns a string describing a variable, i.e. whether it is Integer, Double, Currency, Date etc.

    Hope it is what you are looking for

    Andrew C

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    Thanks, Andrew; useful to know (this function, that is), but I should have made myself more clear.

    It's when I'm using the VBE help files, and it tells me there are wd-constants, and gives me their names. I want to write a procedure that takes these constant values as a parameter, and so i want to know - from the HELP files ideally - what type I should declare in the function.
    Worst case I could write me a generalised function that took in the name and found it out for me. I was wondering if there was a way of determining the type (Long, Integer, Boolean) from within the help file text.

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

    Re: What data type is a constant?

    Have you looked them up in the object browser? Most built-in constants in Office are longs, probably to avoid confusion. At least, I haven't found any that aren't, with the exception of booleans, which are really integers.
    Charlotte

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    Integer or long both work OK- except in the rare case where the value is too large. In Excel 97, there's only one that I can find (out of 1268) which would overflow using integer.

    A constant isn't really a data type per se. It's something the compiler plugs in directly into the code. So you could also validly use Single or Double and it would work:

    <pre>Sub Test()
    Call ShowIt(xlRTL)
    End Sub
    Sub ShowIt(var As Single)
    MsgBox var
    End Sub
    </pre>


    You can get a list of constants used in Office 97 from <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q112/6/71.asp>Microsfot</A>. I have the spreadsheets of constants, and I find it extremely useful (I found it in response to a query in the Old lounge {RIP}). For instance, if I have a graph, I want to be able to determine what graph type it is. I can debug the code, and find out that it's type -4169. I can then go to the spreadsheet to find out that I need to use constant xlXYScatter.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    >You can get a list of constants used in Office 97 from Microsfot.

    Thanks. I am d/l it as we squeak. BTW, I won't get a case of fot in mouse disease from this hyperlink, will I?

    So, what does the rest of the world do when they're writing a procedure and want to declare a parameter which will be filled as a wd-constant? Do we just try for LONG and hope that we've guessed right? I'm trying to make my procedure declarations appropriate to the data in use.

    I can always use LONG for an integer type of value, I know. Seemed cleaner to use INTEGER if the wd- was so, LONG if it was long, and so on.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    >You can get a list of constants used in Office 97 from Microsfot.

    I hadn't realised from my previous post that the earthquake in Seattle has shaken up the letters in that company's name.

    I've been told by a Seattle resident that it wasn't even an earthquake- it was Bill Gates' wallet dropping.

    But on the subject.

    For Excel, a Long will work for every constant defined. I didn't look at the list in Word, and I don't have it here at home.

    But, if you wanted to cater for any future expansion and/or changes of mind by Microsoft (not that that's ever happened before), go for a variant. You've changed your chances of the routine falling over from a bad parameter type from .01% to .001%.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: What data type is a constant?

    >For Excel, a Long will work for every constant defined.

    This is what I've been doing to date in Word - making use of LONG wherever on the grounds that while **I** don't anticipate an array/string/collection that big, as soon as I use INTEGER or BYTE someone will come along and want LONG. I'm using the same approach with constants.

    There's always that lurking notion that by using LONG for a parameter that has at most 5 values I'm spawning code that is unnecessarily inefficient. Not that I'm worried about RAM or tun-time speed .... (grin!)

    BTW I used BYTE for the first time last night.

Posting Permissions

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