Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: vbs script, press cancel to exit?  (Read 19534 times)

0 Members and 1 Guest are viewing this topic.

progmer

    Topic Starter


    Rookie

    vbs script, press cancel to exit?
    « on: May 11, 2010, 09:37:34 PM »
    Hi i have a vbs script as shown:
    Code: [Select]
    Dim message, sapi
    Set sapi=CreateObject("sapi.spvoice")
    do
    message=InputBox("Enter the text you want spoken","Speak This")
    sapi.Speak message
    loop
    I want to vbs box to keep on apearing on the screen but only exit when i press the cancel button.
    So do anyone know the script?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: vbs script, press cancel to exit?
    « Reply #1 on: May 11, 2010, 09:53:30 PM »
    Code: [Select]
    Dim message, sapi
    Set sapi=CreateObject("sapi.spvoice")
    do
    message=InputBox("Enter the text you want spoken","Speak This")

    if message <> "" then sapi.Speak message
    loop Until message=""


    If you press cancel, Inputbox returns an empty string.
    I was trying to dereference Null Pointers before it was cool.

    progmer

      Topic Starter


      Rookie

      Re: vbs script, press cancel to exit?
      « Reply #2 on: May 12, 2010, 06:43:17 AM »
      Code: [Select]
      Dim message, sapi
      Set sapi=CreateObject("sapi.spvoice")
      do
      message=InputBox("Enter the text you want spoken","Speak This")

      if message <> "" then sapi.Speak message
      loop Until message=""


      If you press cancel, Inputbox returns an empty string.
      Maybe you don't understand what i really want here.
      "Press cancel to exit, Press ok to speak message."

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: vbs script, press cancel to exit?
      « Reply #3 on: May 12, 2010, 07:15:12 PM »
      That's exactly what it does. just change the Prompt of the InputBox.
      I was trying to dereference Null Pointers before it was cool.

      progmer

        Topic Starter


        Rookie

        Re: vbs script, press cancel to exit?
        « Reply #4 on: May 13, 2010, 07:55:04 PM »
        Ok here is another task:
        Code: [Select]
        'Blank

        x=msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.")

        'Blank

        Dim message, sapi
        Set sapi=CreateObject("sapi.spvoice")
        do
        message=InputBox("Enter the text you want spoken","Speak This")
        if message <> "" then sapi.Speak message
        loop until message= ""
        What script should i add at the 'Blank in order to exit the program when i click no?
        And i click yes to run the program?

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: vbs script, press cancel to exit?
        « Reply #5 on: May 14, 2010, 12:39:19 PM »
        Code: [Select]
        If msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.") = vbNo Then
        WScript.Quit
        End If

        Dim message, sapi
        Set sapi=CreateObject("sapi.spvoice")
        do
        message=InputBox("Enter the text you want spoken","Speak This")
        if message <> "" then sapi.Speak message
        loop until message= ""

        For readability, try using using constant names (vbInformation, vbSystemModal) instead of constant values (64, 4096).

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        progmer

          Topic Starter


          Rookie

          Re: vbs script, press cancel to exit?
          « Reply #6 on: May 17, 2010, 09:35:57 PM »
          Code: [Select]
          If msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.") = vbNo Then
          WScript.Quit
          End If

          Dim message, sapi
          Set sapi=CreateObject("sapi.spvoice")
          do
          message=InputBox("Enter the text you want spoken","Speak This")
          if message <> "" then sapi.Speak message
          loop until message= ""

          For readability, try using using constant names (vbInformation, vbSystemModal) instead of constant values (64, 4096).

           8)

          Well thanks!! It works greate.
          Here is my code:
          Code: [Select]
          Do
          Dim message, sapi
          Set sapi=CreateObject("sapi.spvoice")
          If InputBox("Enter the text you want spoken","Speak This") = vbCancel then
          wscript.quit
          End if
          sapi.Speak message
          loop
          My code is wrong and i hope you can help me with it.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: vbs script, press cancel to exit?
          « Reply #7 on: May 17, 2010, 09:44:41 PM »
          Here is my code:
          Code: [Select]
          Do
          Dim message, sapi
          Set sapi=CreateObject("sapi.spvoice")
          If InputBox("Enter the text you want spoken","Speak This") = vbCancel then
          wscript.quit
          End if
          sapi.Speak message
          loop
          My code is wrong and i hope you can help me with it.

          If you press cancel, Inputbox returns an empty string.
          I was trying to dereference Null Pointers before it was cool.

          progmer

            Topic Starter


            Rookie

            Re: vbs script, press cancel to exit?
            « Reply #8 on: May 19, 2010, 07:12:01 AM »

            I hope anyone can help me with this......

            press cancel, inputbox returns an empty string.


            press the "x" button, the script exit.

            This is actually what i want.

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: vbs script, press cancel to exit?
            « Reply #9 on: May 19, 2010, 08:45:23 AM »
            pressing "X" on the prompt window also causes the Inputbox() function to return an empty string.

            I was trying to dereference Null Pointers before it was cool.