domingo, 1 de julho de 2018

[VBS] VBScript - Exemplos de Scripts (source) {Vegeta Multi jogos}



[Tutorial]
Os scripts podem ser criados ou editados pelo bloco de notas sem a necessidade de nenhum programa ou pelo editor Notepad++ se preferir:

Para executar os códigos do blog basta criar um arquivo "novo" em sua area de trabalho e mudar a extenssão *.txt para *.vbs ou com o bloco de notas e "salvar como" *.vbs.

Exemplo:
clique direito do mouse: Opçao "novo" clicar em "Novo documento txt" e depois mudar a extenção *.txt para *.vbs e o seu arquivo esta pronto para ser editado ou executado no windows.

##################################################
##################################################
MSGBOX
[source]
Rem # Meu Primeiro programa
msgbox "Hello World!", vbInformation, "Meu Primeiro programa em VB Script"

INPUTBOX
[source]
Rem #Inputbox
nome =Inputbox("Digite o seu nome e Sobrenome","Input Required")
WScript.Echo nome

idade =Inputbox("Digite a sua idade","Input Required")
WScript.Echo idade

INPUTBOX + COMANDO DE VOZ
[source]
Dim message, sapi
message=InputBox("Digite a sua mensagem de voz?", "Speak to Me")
Set sapi=CreateObject("sapi.spvoice")
sapi.Speak message
##################################################
##################################################
Neste campo segue varios exemplos do mesmo Script em blocos diferentes:
##################################################
RUN COMAND (0) - CMD
[source]
Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /K CD C:\ & Dir"
Set objShell = Nothing

RUN COMAND (1)
[source]
Rem Declarar uma variavel "obj"
Dim objShell

Rem Criar uma variavel "Obj" (Qualquer nome)
Set objShell = WScript.CreateObject ("WScript.shell")

Rem Executar programas
objShell.run "notepad.exe"
objShell.run "mspaint.exe"
Set objShell = Nothing

RUN COMAND (2)
[source]
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run ("%windir%\notepad.exe " & WScript.ScriptFullName)

RUN COMAND (3)
[source]
Rem # Declarar uma variavel
Dim a

Rem # Criar uma variavel (Qualquer nome)
Set a = WScript.CreateObject ("WScript.shell")

Rem Executar programas
a.run "notepad.exe"
a.run "mspaint.exe"
Set a = Nothing

RUN COMAND (4) - FULL
[source]
Rem # Para adicionar um "Comentario" nas linhas do programa.

Rem # Forçar todas as variaveis
Option Explicit

Rem # Declarar todas as variaveis
Dim obj, a, b, c
Set obj = WScript.CreateObject ("WScript.shell")
Set a = WScript.CreateObject ("WScript.shell")
Set b = WScript.CreateObject ("WScript.shell")
Set c = WScript.CreateObject ("WScript.shell")

Rem # Executar todos os programas
obj.run "notepad.exe"
a.run "chrome.exe"
b.run "mspaint.exe"
c.run "iexplore.exe"

Rem # Variavel Nula ou Vazia
Set d = Nothing

RUN COMAND (5)
[source]
Set objShell = CreateObject("WScript.Shell")
objShell.run("cscript C:\scripts\demo.vbs")
##################################################
##################################################
Neste campo segue 2 exemplos do mesmo Script:
##################################################
StrComp (1)
[source]
REM #######################################################
REM # Syntax
REM #      StrComp(String1, String2 [,compare] )

REM # Key
REM #   String1   A string expression.

REM #   String2   A string expression.
REM # compare   vbBinaryCompare (0) or vbTextCompare(1)
REM #######################################################
REM # If string1 = string2 StrComp returns 0 (vbFalse)
REM # If string1 < string2 StrComp returns -1 (vbTrue)
REM # If string1 > string2 StrComp returns 1
REM # If either string = null StrComp returns null
REM #######################################################

REM # DECLARAÇÃO DE STRINGS USANDO TEXTOS, NUMEROS E EXPRESSÕES:(=, <, >, null)
Dim strCasa
strCasa ="Casa"
strNumero =45

REM # COMPARAÇÃO DE STRINGS USANDO STRING
strResultado =StrComp(45, strCasa)
WScript.Echo strResultado

StrComp (2)
[source]
REM #######################################################
REM # Syntax
REM #      StrComp(String1, String2 [,compare] )

REM # Key
REM #   String1   A string expression.

REM #   String2   A string expression.
REM # compare   vbBinaryCompare (0) or vbTextCompare(1)
REM #######################################################
REM # If string1 = string2 StrComp returns 0 (vbFalse)
REM # If string1 < string2 StrComp returns -1 (vbTrue)
REM # If string1 > string2 StrComp returns 1
REM # If either string = null StrComp returns null
REM #######################################################

REM # DECLARAÇÃO DE STRINGS USANDO TEXTOS, NUMEROS E EXPRESSÕES:(=, <, >, null)
Dim strCasa
strCasa ="Casa"
strNumero ="45"

REM # COMPARAÇÃO DE STRINGS USANDO VARIAVEL
var1 =StrComp(strCasa, strNumero, 0)
WScript.Echo var1
##################################################
##################################################
Neste campo segue exemplos de if e else usando varieis e strings:
##################################################
If then, ElseIf, Else
[source]
Rem Comparaçoes usando Case sensitivity (if then, ElseIf, Else)
IF "CACHORRO" = "Cachorro" Then
msgbox "O Valor é diferente (1)", vbInformation

ElseIf "Cachorro" = "Cachorro" Then
msgbox "O Valor esta correto (2)", vbInformation

Else msgbox "O Valor de ambos é diferente (3)", vbInformation
End If

If then, ElseIf, Else - STR (1)
[source]
hournow = hour(Time())
If hournow < 12 Then WScript.Echo "Good Afternoon"


Dim strCountry
strCountry = "USA"

If strCountry = "USA" Then
   WScript.Echo "United States of America."
ElseIf strCountry = "CA" Then
   WScript.Echo "Canada."
Else
   WScript.Echo "Some other country."
End If

If then, ElseIf, Else - STR (2)
[source]
Rem Comparação de variaveis (if then, ElseIf, Else)

DIM strCountry
strCountry = "USA"

IF strCountry = "EUA" Then
msgbox "O local esta correto (1)", vbInformation

ElseIf strCountry = "CA" Then
msgbox "O Local esta errado! (2)", vbInformation

Else msgbox "O Local de ambos esta errado! (3)", vbInformation
End If
##################################################
##################################################


Nenhum comentário: