Message Box Kullanımı Dim MsgBaslik Dim MsgIcerik MsgBaslik="Mesaj Başlığı" MsgIcerik="Mesaj içeriği" MsgBox MsgIcerik, 64, MsgBaslik 'Mesaj kutusundaki simge için kod değerleri: '16(Hata) '64(Dikkat) '48(Bilgi) 'vbquestion + vbyesno(soru) Window Script Host Pupup(Acilir)Message Kullanımı 'Yeni bir vbs object oluşturuldu dim wshshell set wshshell=createobject("wscript.shell") ' 'Başlık için String bir değişken oluşturuldu ve içine veri eklendi. strtitle="başlık" ' 'Mesaj için String bir değişken oluşturuldu. '& MEsajı birleştirmek için kullanılır 'VbCrLf Enter işlemi görür. strmsg="selam" & VbCrLf strmsg=strmsg & "Dünyalı" ' 'Messagebox işlemi gören komut 'Mesaj+Ekranda mesajın kalacağı süre+başlık+mesaj stili 'süre bölümüne -1 verilirse OK butonuna basılana kadar mesaj ekranda kalır. wshshell.popup strmsg,7,strtitle,vbokonly+vbinformation 1
Procedure Kullanımı ProcedureMsg Sub ProcedureMsg MsgBox "Procedure Çağırıldı ve Ekrana Mesaj Yazıldı..." Procedure ün Dışardan Veri İle Kullanılması GreetUser "Arslan" Sub GreetUser(strUserName) MsgBox "Selam, " & strusername &_ ". İsim procedure 'e dışardan gönderildi.",,"baslik" Function Kullanımı Dim Sayi1 Dim Sayi2 Sayi1 = 10 Sayi2 = 20 MsgBox Sayi1 & "+"& Sayi2 & "= "& Topla(Sayi1, Sayi2) Function Topla(GelenSayi1, GelenSayi2) Topla = GelenSayi1 + GelenSayi2 Function un Dışardan Veri İle Kullanılması KullaniciSelam Sub KullaniciSelam MsgBox "Selam, "& KullaniciAdi & _ ". Procedure ve Function Örneği..." Function KullaniciAdi KullaniciAdi = InputBox("Lütfen Adınızı Giriniz:") 2
Function ve Procedure ün Dışardan Veri İle Kullanılması KullaniciSelam KullaniciAdi Sub KullaniciSelam(GelenKullaniciAdi) MsgBox "Selam, " & GelenKullaniciAdi & _ ". Procedure ve Function Örneği..." Function KullaniciAdi KullaniciAdi = InputBox("Lütfen Adınızı Giriniz:") Function ve Procedure ün Dışardan Veri İle Kullanılması - Kuşullu Dim Cevap Sub KullaniciSelam(GelenKullaniciAdi) MsgBox "Selam, " & GelenKullaniciAdi & _ ". Procedure ve Function Örneği..." Function KullaniciAdi KullaniciAdi = InputBox("Lütfen Adınızı Giriniz:") 'Main Cevap = MsgBox("Selam Vermek İstiyormusun?", vbyesno) If Cevap = vbyes Then KullaniciSelam KullaniciAdi 3
Function ve If- Kullanımı Function KullaniciAdi KullaniciAdi = InputBox("İsim :") Sub KullaniciSelamla(GelenKullaniciAdi) If IsNumeric(GelenKullaniciAdi) or IsDate(GelenKullaniciAdi) Then MsgBox "Yanlış İsim Girişi...!!!" MsgBox "Selam, "& GelenKullaniciAdi & _ ". Function ve If- Deneme..." 'Main KullaniciSelamla KullaniciAdi 4
Function ve Tarih Verisi Tanımları Private BugunTarih BugunTarih = Date MsgBox "Bugünün Tarihi: "& BugunTarih & "." MsgBox "Yarının Tarihi: "& TariheBirGunEkle(BugunTarih) & "." Function TariheBirGunEkle(GelenTarih) TariheBirGunEkle = DateAdd("d",1, GelenTarih) For - Döngüsü Dim lngindex For lngindex = 1 To 5 MsgBox " Index Degeri: " & lngindex For - Döngüsü (Step 2) Dim lngindex For lngindex = 10 To 18 Step 2 MsgBox "Index Degeri: " & lngindex İç İçe For - Döngüsü Dim lngouter Dim lnginner For lngouter = 1 to 5 MsgBox "Outer loop index: " & lngouter For lnginner = 10 to 18 Step 2 MsgBox "Inner loop index: " & lnginner 5
For Each - Döngüsü Dim astrcolors(3) Dim strelement astrcolors(0) = "Red" astrcolors(1) = "Green" astrcolors(2) = "Blue" astrcolors(3) = "Yellow" For Each strelement In astrcolors MsgBox strelement For Each - Döngüsü ve Dosya Bulma İşlemi Dim objfso Dim objrootfolder Dim objfileloop Dim boolfoundit Set objfso = WScript.CreateObject("Scripting.FileSystemObject") Set objrootfolder = objfso.getfolder("c:\") Set objfso = Nothing boolfoundit = False For Each objfileloop In objrootfolder.files If UCase(objFileLoop.Name) = "AUTOEXEC.BAT" Then boolfoundit = True Exit For Set objfileloop = Nothing Set objrootfolder = Nothing If boolfoundit Then MsgBox "We found your AUTOEXEC.BAT file in "& "the C:\ directory." MsgBox "We could not find AUTOEXEC.BAT in " & "the C:\ directory." 6
For Each - Döngüsü ve Loop Olmadan Dosya Bulma İşlemi Dim objfso Set objfso = WScript.CreateObject("Scripting.FileSystemObject") If objfso.fileexists("c:\autoexec.bat") Then MsgBox "We found your AUTOEXEC.BAT file in the " & "C:\ directory." MsgBox "We could not find AUTOEXEC.BAT in " & "the C:\ directory." Set objfso = Nothing Do - Loop Döngüsü Dim boolloopagain Dim lngloopcount Dim strresponse boolloopagain = False lngloopcount = 0 Do boolloopagain = False lngloopcount = lngloopcount + 1 strresponse = InputBox("Sihirli Kelime Nedir?") If UCase(Trim(strResponse)) = "TÜRK" Then MsgBox "Tebrikler Bildiniz!!!" If lngloopcount < 5 Then MsgBox "Bilemedin, Tekrar Dene...!!!" boolloopagain = True MsgBox "Bilemedin... Sihirli Kelime ='TÜRK'" Loop While boolloopagain 7
Do While - Loop Döngüsü Dim boolloopagain Dim lngloopcount Dim strresponse boolloopagain = True lngloopcount = 0 Do While boolloopagain boolloopagain = False lngloopcount = lngloopcount + 1 strresponse = InputBox("Sihirli Kelime Nedir?") If UCase(Trim(strResponse)) = "TÜRK" Then MsgBox "Tebrikler Bildiniz!!!" If lngloopcount < 5 Then MsgBox "Bilemedin, Tekrar Dene...!!!" boolloopagain = True MsgBox "Bilemedin... Sihirli Kelime ='TÜRK'" Loop While - Wend Döngüsü Dim lngcounter lngcounter = 0 While lngcounter <= 20 lngcounter = lngcounter + 1 MsgBox lngcounter Wend Klasör Oluşturmak Dim FSO Dim objfolder Set FSO = CreateObject("Scripting.FileSystemObject") Set objfolder = FSO.GetFolder("C:\") If Not FSO.FolderExists("C:\TestVBScriptFolder") Then objfolder.subfolders.add "TestVBScriptFolder" MsgBox "The C:\TestVBScriptFolder folder was " & _ "created successfully." 8
Klasör Kopyalamak Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FolderExists("C:\TestVBScriptFolder") Then FSO.CopyFolder "C:\TestVBScriptFolder", _ "C:\MyFolder2\", True MsgBox "C:\TestVBScriptFolder Bulunamadı..." Dosya Kopyalamak Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") ' Belirtilen Dosyasın Olup Olmadığı Kontrol Eder If FSO.FileExists("C:\MyFolder\TextDeneme.txt") Then FSO.CopyFile "C:\MyFolder\TextDeneme.txt", _ "C:\MyFolder2\TextDeneme.txt", True MsgBox "C:\MyFolder\TextDeneme.txt Bulunamadı..." Text Dosya Oluşturmak ve İçerisine Veri Yazdırmak Dim FSO Dim objstream Const TristateFalse = 0 Const FILE_NAME = "C:\MyFolder\TextDeneme2.txt" Set FSO = CreateObject("Scripting.FileSystemObject") Set objstream = FSO.CreateTextFile(FILE_NAME, _ True, TristateFalse) With objstream.writeline "Test Line 1".WriteLine "Test Line 2".WriteLine "Test Line 3".Close End With MsgBox "Successfully created "& FILE_NAME & "." 9
Text Dosya İşlemleri - Genel Dim FSO Dim objstream Dim objfolder Dim File_Address Const ForAppending = 8 Const TristateFalse = 0 Const Folder_Name = "DenemeKlasor" Const File_Name = "DenemeDosya.txt" File_Address= "C:\" & Folder_Name & "\" &File_Name Set FSO = CreateObject("Scripting.FileSystemObject") Set objfolder = FSO.GetFolder("C:\") ' Klasör Var mı? Yok mu? Yoksa Yeni Klasör Oluştur If Not FSO.FolderExists("C:\" & Folder_Name) Then objfolder.subfolders.add Folder_Name MsgBox "C:\" & Folder_Name & " Klasörü oluşturuldu...!!!" ' Dosya Var mı? Yok mu? Yoksa Yeni Dosya Oluştur If Not FSO.FileExists(File_Address) Then Set objstream = FSO.CreateTextFile(File_Address, _ True, TristateFalse) With objstream.writeline "Test Line 1".WriteLine "Test Line 2".WriteLine "Test Line 3".Close End With ' Dosya Varsa Üzerine Yazar Set objstream = FSO.OpenTextFile(File_Address, _ ForAppending, False, TristateFalse) With objstream.writeline "Appended Line 1".WriteLine "Appended Line 2".WriteLine "Appended Line 3".Close End With 10