×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

I need help with a vbs code!

I need help with a vbs code!

I need help with a vbs code!

(OP)
So, i'm learning vbs and i'm playing with code to learn more, but there's an error:

CODE --> vbs

Option Explicit
Dim x
Dim lol
Dim lol2
Dim lol3
Dim lol4

x=msgbox("oof" ,vbYesNo+vbSystemModal, "only oof")
if x = vbYes Then
   lol=msgbox("more oofs then",vbCritical+vbOKCancel+vbDefaultButton1, "hehe")
ElseIf x = vbNo Then
   lol2=msgBox("oh, ok then...",vbExclamation+vbOKCancel+vbDefaultButton1, "oh...")
ElseIf lol = vbOK Then
   lol3=msgBox("ok",vbExclamation+vbOKCancel, "ok") 
ElseIf lol2 = vbOK Then
   lol4=msgBox("sad",vbExclamation+vbOKCancel, "...") 
End If 

when we clicked in lol's 'ok', it was suppose to appear lol3, and if we clicked in lol2's 'ok', it was suppose to appear lol4, but lol3 and lol4 don't appear any more!

please,someone help! i really want to learn vbs, but i'm stuck with this code and i want to know what was my mistake, and no, Option Explicit didn't told me the mistake.

RE: I need help with a vbs code!

Hi LeuxD,
Your mistake is improper use of IF..ElSEIF...
Use nested IFs instead, e.g.:

CODE

x=msgbox("oof" ,vbYesNo+vbSystemModal, "only oof")
if x = vbYes Then
   lol=msgbox("more oofs then",vbCritical+vbOKCancel+vbDefaultButton1, "hehe")
   If lol = vbOK Then
      lol3=msgBox("ok",vbExclamation+vbOKCancel, "ok")
   End If
ElseIf x = vbNo Then
   lol2=msgBox("oh, ok then...",vbExclamation+vbOKCancel+vbDefaultButton1, "oh...")
   If lol2 = vbOK Then
      lol4=msgBox("sad",vbExclamation+vbOKCancel, "...")
   End If
End If 

RE: I need help with a vbs code!

I’d prefer Select Case...End Select

CODE

Select Case x
   Case vbYes 
      lol = msgbox("more oofs then",vbCritical+vbOKCancel+vbDefaultButton1, "hehe")
    Case vbNo 
      lol2=msgBox("oh, ok then...",vbExclamation+vbOKCancel+vbDefaultButton1, "oh...")
    Case vbOK 
      lol3=msgBox("ok",vbExclamation+vbOKCancel, "ok") 
    Case Else 
      lol4=msgBox("sad",vbExclamation+vbOKCancel, "...") 
End Select 


Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: I need help with a vbs code!

Not sure the Case solution provides the results indicated in the OP, needs some minor modification, e.g.

CODE

    x = MsgBox("oof", vbYesNo + vbSystemModal, "only oof")
    Select Case x
        Case vbYes
            lol = MsgBox("more oofs then", vbCritical + vbOKCancel + vbDefaultButton1, "hehe")
            'lol1 = lol ' in case we are capturing these for future use
        Case vbNo
            lol = MsgBox("oh, ok then...", vbExclamation + vbOKCancel + vbDefaultButton1, "oh...")
            'lol2 = lol ' in case we are capturing these for future use
    End Select
    Select Case lol
        Case vbOK
            lol3 = MsgBox("ok", vbExclamation + vbOKCancel, "ok")
        Case Else
            lol4 = MsgBox("sad", vbExclamation + vbOKCancel, "...")
    End Select 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close