Results 1 to 8 of 8

Thread: Substituting a string var for a named constant

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    50

    Question

    OK, I am probably overlooking something really simple here, but...
    Here is something similar to want I want to do:

    Dim strMsg As String
    Dim strTitle As String
    Dim strOptions As String
    Dim intReturn As Integer

    strTitle = "Test"
    strMsg = "blah blah blah"
    strOptions = "vbOKCancel + vbExclamation"

    intReturn = MsgBox(strMsg, strOptions, strTitle)


    How can I get the string strOptions to be interpreted as:
    vbOKCancel + vbExclamation
    and not:
    "vbOKCancel + vbExclamation" <- which of course causes a type mismatch error.

    Thx,

    ~Michael Kizer
    http://Michael.Kizer.ws

    The Ivory Gate Of Dreams ~ http://www.ivorygate.com

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?> get around the + operator

    strOptions = "vbOKCancel" & " + " & "vbExclamation"
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    New Member
    Join Date
    May 2000
    Posts
    4
    I don't know if this would help, but I've run into simular situations with passing variables into statements that require a vb constant.. The work around I'd suggest is using a select case for it... ie:
    Code:
    Dim strMsg As String
    Dim strTitle As String
    Dim strOptions As String
    Dim intReturn As Integer
    
    strTitle = "Test"
    strMsg = "blah blah blah"
    select case strOptions
    
         "vbOkCancel + vbExclamation"
          intReturn = MsgBox(strMsg, vbOkCance + vbExclamation, strTitle)
    
    End select
    Now this would be if you didn't hard code the strOptions, but if you were actually passing that variable into this function/sub and it were going to change... You could just stick the possibilities into the case statement and pass it that way..

    Hope this helps, if there is another way lemme know!

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Are you trying to combine the two? Because if that is the case, you need to drop the quotes. Keep in mind, anything with a lowercase prefix of "vb" such as vbOKCancel is a reserve word.

    Code:
    intReturn = MsgBox(strMsg, vbOKCancel + vbExclamation, strTitle)
    Chemically Formulated As:
    Dr. Nitro

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'sorry, I misread your question 1st. time
    'this will work for what you want.

    Code:
    Private Sub Form_Load()
    
        Dim strMsg As String
        Dim strTitle As String
        Dim intReturn As Integer
        
        Const strOptions = vbcancel + vbExclamation
        
        strTitle = "Test"
        strMsg = "blah blah blah"
        
        intReturn = MsgBox(strMsg, strOptions, strTitle)
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    As a rule:
    Always use OR when you add flags
    Code:
    intReturn = MsgBox(strMsg, vbcancel OR vbExclamation, strTitle)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    50
    hmmm... not exactly what I had in mind...
    The problem is that I am building the string var containing the named constants, dynamically. There could be hundreds of different combinations of them contained in the string. Once I have the string in the format I want, ie:
    "vbOKCancel + vbExclamation + vbSystemModal + vbDefaultButton1" <- Or what ever...

    Is there a way to make VB substitute the contents of the variable in the MsgBox function call, instead of trying to process the variable as a string var (which is illegal since that paramter of the function requires a numeric expression?
    ~Michael Kizer
    http://Michael.Kizer.ws

    The Ivory Gate Of Dreams ~ http://www.ivorygate.com

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Sounds like you want to build a script,

    You could do this
    Code:
    If string  like "*vbOKCancel*" then Result=Result Or vbOKCancel
    If string  like "*vbExclamation*" then Result=Result Or vbExclamation
    If string  like "*vbSystemModal*" then Result=Result Or vbSystemModal
    ...
    Which means you pass the Result (which is a integer) to the Msgbox
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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