Results 1 to 2 of 2

Thread: Need to user a GLOBAL CONST in a function

  1. #1

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    I have a global variable declared in a module:

    Global Const HKEY_USERS = &H80000003

    How can I call this long variable by name in a function?

    Let's say I have a function and I would like to have the first parameter be the global constant.

    I want to have the user type the global variable name into
    a text box and then have the OnClick event of a command button call a Sub with the constant as a parameter.

    Call Myfunction(Text1.Text) gives me an error. |where text1.text = "HKEY_USERS"

    this doesn't work. Any help guys?
    Donald Sy - VB (ab)user

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    It's a variable, not a sring, you must use a select case statement
    Code:
    Select Case text1.text
    
    Case "HKEY_USERS"
        Call MyFunction(HKEY_USERS)
    Case "HKEY_LOCAL_MACHINE"
        Call MyFunction(HKEY_LOCAL_MACHINE)
    'other const here
    End Select
    Otherwise you might look into runtime proccessing like this
    More info is avalible at http://www.vbexplorer.com (I think thats were this is from)
    Code:
    '------------------------------------------
    '   (c) 1999 Trigeminal Software, Inc.  All Rights Reserved
    '------------------------------------------
    'Thanks to ----------michka - Michael Kaplan
    'Rest of code by Sergio Perciballi -oigres P (Aug-6-2000)
    'Email: [email protected]
    'Uses the function used by the immediate window
    'to execute a line of code.
    Option Compare Text
    Option Explicit
    Const HKEY = 14
    Private Declare Function EbExecuteLine Lib "vba6.dll" _
            (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
            ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    ' For VB5 IDE
    'Declare Function EbExecuteLine Lib "vba5.dll" _
     (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
     ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    ' FOR Access 97/VBE.dll clients like Word 97 and Excel 97
    'Declare Function EbExecuteLine Lib "vba332.dll" _
     (ByVal pStringToExec As Long, ByVal Foo1 As Long, _
     ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
    
    Function FExecuteCode(stCode As String, _
                Optional fCheckOnly As Boolean) As Boolean
    
        FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
    End Function
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

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