VBS password protected image - image

I'm not a programmer and i need help.
How to combine this two scripts into one?
Then i will convert this to EXE and give as present on Tank Style pendrive :).
pass=inputbox("Password?")
if pass="fish" then msgbox("Correct Password!") else msgbox("Incorrect Password!")
AND
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer "
.Navigate "about:blank"
.ToolBar = 0
.StatusBar = 0
.Left = 200
.Top = 200
.Width = 650
.Height = 440
.Visible = 1
.Document.Title = "Kocham cie Maciek!"
.Document.Body.InnerHTML = _
"<center>Kocham cie Maciek <3<br><br><img src='http://www.crystalclearsports.net/file/2016/07/use_love_quotes_for_him_and_inspire_romantic_vitality.jpg' height=336 width=600></center>"
"
End With
When someone type good password it show Picture1, if bad Picture2.

Try this!
Dim MyPassword, objExplorer
MyPassword = InputBox("Enter the Password and Press 'OK' ", "Password")
MyPassword = Trim(MyPassword)
If MyPassword = "" Then
Msgbox "No Password is entered"
Else
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate "about:blank"
.ToolBar = 0
.StatusBar = 0
.Left = 200
.Top = 200
.Width = 650
.Height = 440
.Visible = 1
.Document.Title = "Kocham cie Maciek!"
End With
If StrComp(MyPassword, "FISH", 1) = 0 Then
' Correct Password
Msgbox "The Password is Correct"
objExplorer.Document.Body.InnerHTML = "<center>Kocham cie Maciek <3<br><br><img src='http://www.crystalclearsports.net/file/2016/07/use_love_quotes_for_him_and_inspire_romantic_vitality.jpg' height=336 width=600></center>'"
Else
Msgbox "Incorrect Password"
objExplorer.Document.Body.InnerHTML = "<center>Kocham cie Maciek <3<br><br><img src='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' height=336 width=600></center>'"
End If
End if
you missed the second image, update the XXXX with the location of second image you would want to show!!

Related

How to send an email with multiple attachments

This code is working well as long as every file is there.
What is missing in the code for sending an email even if a file is missing?
I have tried to find a solution but without success.
Set fso=CreateObject("Scripting.FileSystemObject")
strSMTP="smtp.telenor.no"
strSubject="Files form me to you"
strSubject="XXXXX"
strSubject="XXXX"
strBody="XXXXXX"
strAttach="File 1.csv"
strAttach1="File 2.csv"
strAttach2="File 3.csv"
If fso.FileExists(strAttach) then
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
With iMsg
Set .Configuration = iConf
.To = "XXXX"
.CC = ""
.BCC = ""
.From = "XXXX"
.Subject = strSubject
.TextBody = strBody
.AddAttachment strAttach
.AddAttachment strAttach1
.AddAttachment strAttach2
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Else
MsgBox "The specified attachment does not exist"
End if
The following uses an ArrayList to hold your attachments and adds them to the message one by one, checking if the file exists first:
Dim iCounter
Dim sAttachment
Dim objAttachments
Set objAttachments = CreateObject("System.Collections.ArrayList")
objAttachments.Add "File 1.csv"
objAttachments.Add "File 2.csv"
objAttachments.Add "File 3.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSMTP = "smtp.telenor.no"
strSubject = "Files form me to you"
strSubject = "XXXXX"
strSubject = "XXXX"
strBody = "XXXXXX"
' Create message and configuration
Set objMessage = CreateObject("CDO.Message")
Set objConf = CreateObject("CDO.Configuration")
objConf.Load -1 ' CDO Source Defaults
Set objFields = objConf.Fields
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
' Initalize message
With objMessage
Set .Configuration = objConf
.To = "XXXX"
.CC = ""
.BCC = ""
.From = "XXXX"
.Subject = strSubject
.TextBody = strBody
End With
' Add attachments
For iCounter = 1 To objAttachments.Count
sAttachment = objAttachments.Item(iCounter - 1)
If objFSO.FileExists(sAttachment) Then objMessage.AddAttachment sAttachment
Next
' Send Message
objMessage.Send

How to open ie.exe within an If/Else statement

I am trying to write a piece of code so when the user clicks "yes" on my message box my yes.gif opens in IE, but if the user clicks "no" I want my no.gif to open in IE. I get a synax error on line 5 (Else statement).
My code:
Result = MsgBox("Text", 20, "Title")
If Result = vbYes Then Set objExplorer = CreateObject("InternetExplorer.Application")
Else Result = vbNo Then Set objExplorer1 = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate "about:blank"
.Visible = 1
.Document.Title = "Right Decision"
.Toolbar = False
.Statusbar = False
.Top = 500
.Left = 500
.Height = 400
.Width = 600
.Document.Body.InnerHTML = "<img src='C:\User\yes.gif'>"
End With
With objExplorer1
.Navigate "about:blank"
.Visible = 1
.Document.Title = "Wrong Decision"
.Toolbar = False
.Statusbar = False
.Top = 500
.Left = 500
.Height = 400
.Width = 600
.Document.Body.InnerHTML = "<img src='C:\User\no.gif'>"
End With
There are multiple issues with your code:
The only possible values from the MsgBox are vbYes and vbNo because you launched it with the vbYesNo flag. Since the result is binary there is no need for multiple comparisons (which don't work like that in VBScript anyway).
Your If statement uses the single-line If..Then form, meaning that the subsequent Else is invalid. And even if it weren't invalid the syntax would still be incorrect.
Starting different IE instances is pointless when a string and an image name are the only differences.
Your code tries to configure both instances, but one of them will be invalid regardless of the user's choice.
Use an If..Then..Else to define the settings that actually differ, then create the IE instance after the conditional and configure it accordingly.
Result = MsgBox("Text", vbYesNo + vbCritical, "Title")
If Result = vbyes Then
title = "Right Decision"
picture = "C:\User\yes.gif"
Else
title = "Wrong Decision"
picture = "C:\User\no.gif"
End If
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Navigate "about:blank"
.Visible = True
.Document.Title = title
.Toolbar = False
.Statusbar = False
.Top = 500
.Left = 500
.Height = 400
.Width = 600
.Document.Body.InnerHtml = "<img src='" & picture & "'>"
End With

visual basic 6: create an object in other form

i would like create a rectangle in a different picture.
For example: the code is inside testpicture, but i would like that this rect is create in testpicture2.
How is possible please ?
Thank you very much
The solution...
Private Sub GenerateRuntimeForm()
Dim ctrl As Control
Set frm = New Form1
Set cmdOK = Nothing
Set cmdCancel = Nothing
Set txtInput = Nothing
Set lblDisplay = Nothing
'clear the form
For Each ctrl In frm
ctrl.Visible = False
Next
Set cmdOK = frm.Controls.Add("VB.CommandButton", "cmdOK")
Set cmdCancel = frm.Controls.Add("VB.CommandButton", "cmdCancel")
Set txtInput = frm.Controls.Add("VB.TextBox", "txtInput")
Set lblDisplay = frm.Controls.Add("VB.Label", "lblDisplay")
With frm
'Set form's width and height
.Width = 4000
.Height = 2500
.Caption = "Run-Time Generated Form"
End With
'Setup rest of controls
With lblDisplay
.Top = 250
.Left = 250
.AutoSize = True
.FontBold = True
.Caption = IIf(allowNumericOnly, "Enter Your Age:", "Enter Your Last Name:")
End With
With txtInput
.Top = lblDisplay.Top + lblDisplay.Height + 250
.Left = 250
.Height = 295
If allowNumericOnly Then
.Width = 500
.MaxLength = 3
Else
.Width = 2500
End If
End With
With cmdOK
.Top = txtInput.Top + txtInput.Height + 375
.Width = 800
.Left = 1000
.Height = cmdGenerate(0).Height
cmdOK.Caption = "&OK"
.Enabled = False
End With
With cmdCancel
.Left = cmdOK.Left + cmdOK.Width + 100
.Top = cmdOK.Top
.Width = cmdOK.Width
.Height = cmdOK.Height
.Caption = "&Cancel"
End With
cmdOK.Visible = True
cmdCancel.Visible = True
lblDisplay.Visible = True
txtInput.Visible = True
frm.Show vbModal
End Sub

WShell.Run returns 143

I am calling java code from VB script using WShell.Run. It returns a code 143. What does it mean? Where can i get the list of error codes that run method can return?
Here is the reference to System Error Codes.
ERROR_SAME_DRIVE 143 (0x8F) The system cannot join or substitute a
drive to or for a directory on the same drive.
P.S. I think that the next notes are out of the question, but just in case...
Just to note that Err object has "dummy" Description (Unknown runtime error) for most codes. If you like to get filtered list with all sensible descriptions, you can do something like this:
With CreateObject("InternetExplorer.Application")
Const DUMMY = "Unknown runtime error"
ReDim aryLines(15999)
Dim cnt, i, w, h
cnt = -1
.Navigate "about:blank"
.Document.Title = "Error Codes " & String(100, Chr(1))
.ToolBar = False
.Resizable = True
.StatusBar = False
.Width = 420
.Height = 380
With .Document.ParentWindow.Screen
w = .AvailWidth
h = .AvailHeight
End With
.Left = (w - .Width ) \ 2
.Top = (h - .Height) \ 2
Do While .Busy : WScript.Sleep 200 : Loop
On Error Resume Next
With Err
For i = 1 To 15999
.Raise i
If .Description <> DUMMY Then
cnt = cnt + 1
aryLines(cnt) = AddZero(i) & .Description
End If
.Clear
Next
End With
On Error GoTo 0
ReDim Preserve aryLines(cnt)
.Document.Body.InnerHTML = "<pre id=x>" & Join(aryLines, vbNewLine)
.Document.Body.Style.overflow = "auto"
.Document.All.X.Style.fontFamily = "Verdana, sans-serif"
.Visible = True
End With
Function AddZero(nVar)
AddZero = "<b>" & Right("00000" & nVar, 5) & "</b> "
End Function
this code returned by your java application. From MSDN
The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down.
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)

Displaying an image in a VBScript MsgBox

How can I display an image in a MsgBox?
The answer is: This is not possible. MsgBox can only display strings. (Documentation)
An alternative is to display your image in a small Internet Explorer window. Here's an example:
Set objExplorer = CreateObject("InternetExplorer.Application")
With objExplorer
.Navigate "about:blank"
.ToolBar = 0
.StatusBar = 0
.Left = 100
.Top = 100
.Width = 200
.Height = 200
.Visible = 1
.Document.Title = "Important image!"
.Document.Body.InnerHTML = _
"<img src='http://sstatic.net/stackoverflow/img/venn-diagram.png' height=100 width=100>"
End With
This should display the Venn diagram found in Stack Overflow's about section.
What you want is called a HyperText Application, or HTA. You use HTML to create the form.

Resources