Results 1 to 15 of 15

Thread: "As Any" declaration???

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    "As Any" declaration???

    In VB6, there apparently is this "As Any" clause being used in declaring API calls. This "As Any" is part of the function signature. Has anyone ever heard of this. I'm only bringing this up because I am in the process of converting VB6 code to .Net. I don't know what the .Net equivalent is.

    Thanks,
    Blake

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: "As Any" declaration???

    hmm Ive never heard of that, but if you declare something as Object then you can set it to any type of object.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: "As Any" declaration???

    Aethiest,

    That seemed to work for now. I will know for sure when I start testing!

    Thanks,
    Blake

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: "As Any" declaration???

    As Any can generally be replaced with a general Object type, I have done it before... However, I think that if you know what object it will be returning and put that type into it (whether its some other API structure or whatever) it should work as well... as long as you always know what type it will return for what you are using it for...

  5. #5
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: "As Any" declaration???

    You should never use As Any in VB6 because it it denies the compiler the ability to do strong type checking on your code.

    In VB.Net you should create one overloaded declaration for each parameter type you can pass.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: "As Any" declaration???

    I never created the statement. This was a downloaded procedure to read and retrieve INI info.

    I don't understand what you mean on your last statement by overloaded declaration statement.
    Blake

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: "As Any" declaration???

    He means that if your argument can take multiple types then you should declare multiple overloads, one for each type. It's quite possible to declare many API functions with multiple signatures. For instance, where a handle is required you could declare an Integer or an IntPtr.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: "As Any" declaration???

    What are overloads?
    Blake

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: "As Any" declaration???

    For example try writing this in VB:
    VB Code:
    1. Dim sr as new StreamReader(
    Intellisense will show this:

    As you can see, there are 10 overloaded "New" subroutines of the StreamReaders. That means that there are 10 "New" subroutines that does the same thing, with different arguments that can be passed. If you press up and down the arrows you can see the different overloads.
    Bah..this explanation was pretty crap, hope you get the point anyways.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: "As Any" declaration???

    If you post up the VB6 declaration you want to convert we'll give you an example using that declaration...

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: "As Any" declaration???

    Here is the API call that contains the "As Any"

    VB Code:
    1. Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
    2. "WritePrivateProfileStringA" (ByVal lpApplicationName As any, _
    3. ByVal lpKeyName As Any, _
    4. ByVal lpString As Any, _
    5. ByVal lpFileName As String) As Long
    Blake

  12. #12
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: "As Any" declaration???

    When you call that API what do you pass as arguments on the "as any" arguments?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: "As Any" declaration???

    That call came from a generic module that opened and retrieved INI values. The program that used that module never made a call to it.
    Blake

  14. #14
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: "As Any" declaration???

    Looks like all should just be strings, and the Long changed to Int32... like below:
    VB Code:
    1. Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
    2.     "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    3.                                           ByVal lpKeyName As String, _
    4.                                           ByVal lpString As String, _
    5.                                           ByVal lpFileName As String) As Int32
    In the code sample in this MSDN Link, they were passing in strings...

  15. #15
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: "As Any" declaration???

    According to the MSDN[ documentation there are two ways of using this function.
    One uses string parameters the other wants NULL.
    To cater for this in VB.Net you write two overloaded declarations thus:-
    VB Code:
    1. Private Overloads Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
    2.     "WritePrivateProfileStringA" (ByVal lpApplicationName As String, _
    3.                                           ByVal lpKeyName As String, _
    4.                                           ByVal lpString As String, _
    5.                                           ByVal lpFileName As String) As Int32
    6.  
    7. Private Overloads Declare Function WritePrivateProfileString Lib "KERNEL32" Alias _
    8.     "WritePrivateProfileStringA" (ByVal lpApplicationName As IntPtr, _
    9.                                           ByVal lpKeyName As IntPtr, _
    10.                                           ByVal lpString As IntPtr, _
    11.                                           ByVal lpFileName As String) As Int32

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