First VBS script - any suggestions? (1 Viewer)

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
This is my first VBS script. I wrote it in notepad. It works fine. I'm going to use it to launch my Access app.
1. Any improvements I can make?
2. Is there an included dev environment in Windows 10?

Code:
'This script is used to launch the KingslyOperation database.
'It tests if the database front end location exists then copies the most
'current front end from the server location to the target local directory.
'It then launches the database.


'Set new folder location and current file location
Const strFolder = "C:\KingslyOp\", strFile = "\\KCI-CAMBRIDGE\TEST FOLDER\test.txt"
Const Overwrite = True
Dim oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

If Not oFSO.FolderExists(strFolder) Then
  oFSO.CreateFolder strFolder
End If

oFSO.CopyFile strFile, strFolder, Overwrite

'Pop Up WiFi Warning
strMsgBoxText = "Do NOT connect to Kingsly Operations over WiFi, FortiNet or other VPN software. " _
    & "This may cause program instability and data corruption."
strMsgBoxTitle = "WARNING!"

'This is a messagebox with OK and Cancel buttons.
result = MsgBox(strMsgBoxText, 1+48, strMsgBoxTitle)
    Select Case result
        Case 1
        'App Launch Code
        Dim objShell
        Dim strPath
        strPath = "C:\KingslyOp\test.txt"
        Set objShell = WScript.CreateObject("WScript.Shell")
        objShell.Run (strPath)
        Case 2
                MsgBox "Application Launch Terminated"
    End Select
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
I copied and pasted different sample things (such as creating the folder) and I don't know why one example uses the constant variable type and another uses Dim. Mixing syntaxes? It all appears to work, but I know VB (amateurly) and haven't ever developed a VB Script before.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:31
Joined
Oct 29, 2018
Messages
21,467
Looks fine to me. 👍
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
you give Each user his FE.
using Common FE will likely cause curruption.
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
That is the purpose of this launch script. It goes out to the server location, copies the latest FE to the local user and then they use that to connect to the database. So, no shared FE.
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
This seems an appropriate place to ask. Is there a free dev/text editor for vbscript? I can use notepad, but I am used to being able to change the indent on blocks of code at a time! Just curious what everyone uses these days.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
vbsEdit, it's a Freeware. google it.
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
Thanks. I found vbsEdit a little while ago but missed that it had a freeware version. Excellent! Thanks!
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
Thanks! I discovered that script via the super handy (and spooky) "Similar threads" list. It is indeed comprehensive. I'm parsing through it right now. Its actually why I asked for an editor just a few posts ago. I wanted to format the script from that thread to make it easier to read and so that I could make sure I understood what each part was doing.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 18:31
Joined
Apr 27, 2015
Messages
6,328
The "author" of that code is a member here and I'm sure he would answer any questions you have. Best of luck!
 

Minty

AWF VIP
Local time
Today, 23:31
Joined
Jul 26, 2013
Messages
10,371
I use Notepad++ https://notepad-plus-plus.org/ - it's free and very powerful
And Textpad which I paid for years ago.

They both have language add-ins that will highlight text and keywords automatically and have powerful Block Editing functions, really handy when making adjustments to large chunks of text.
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
@Minty - Thanks for the suggestions!

So, it appears that MS has done a lot to kill vbscript in the last few years (automatically disabled in IE and Edge for one thing). To those using vbscript regularly (as FE udpater, app launcher, etc) what do you do?
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
I'm working on an app launcher. It should:
1. Automatically pull the latest FE from a server location and copy it to a local users computer.
2. Verify that the user has the Access runtime installed.
3. Verify that any other app requirements are met.
4. Display warning about using WiFI while using the database.
5. Any other prelaunch requirements I can think of.
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
Clearly I don't mind "borrowing" other peoples ideas (just ask @isladogs). But, I'm leery of using compiled tools such as this one, because I have no recourse if they break in some way in the future. If I'm reimplementing someone's source code, then, at least I have the base code to modify if need be.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:31
Joined
May 7, 2009
Messages
19,230
hey break in some way in the future.

it never breaks since i use a2007 up to a2019.
it only saves the paths of the db in cryptic way.
anyway, there are many alternatives that you will find.
btw .vbs, .bat are prone to editing unlike .exe
 

Minty

AWF VIP
Local time
Today, 23:31
Joined
Jul 26, 2013
Messages
10,371
Was it just me, but I was hoping when I read the title of this thread that someone was going to suggest

Code:
WScript.StdOut.Write("Hello World !")
 

JMongi

Active member
Local time
Today, 18:31
Joined
Jan 6, 2021
Messages
802
Heh...it looks like my concerns about vbscript are lessened. It's vbscript interacting with web browsers that MS is trying to kill off. So, back on task with the posted script.
Since the hooks into IE are being closed off sooner rather than later, does anyone have a splash screen they use that doesn't involve Internet Explorer? Here is the code snippet from the script @NauticalGent was referring to.

Code:
Function SplashBox(sTitle)
'Purpose : Creates Splash screen while front end downloads.
'DateTime : 1/11/2007 11:18
'Author : Tom Lavedas
Dim s, sBody, item
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
    'Commented out for IE7
    '.FullScreen = True
    .Toolbar = False
    .RegisterAsDropTarget = False
    .StatusBar = False
    .Menubar = False
    .Addressbar = False
    .Navigate ("about:blank")
    Do Until .ReadyState = 4: WScript.Sleep 100: Loop
    .Width = 300: .Height = 300
    With .Document
        With .ParentWindow.Screen
            oIE.Left = (.availWidth - oIE.Width) \ 2
            oIE.Top = (.availheight - oIE.Height) \ 2
        End With
        
        sBody = "Please wait while latest version of " & cAppName & " loads..."
        
        s = "<html><head><title>" & sTitle _
        & "</title></head><script language=vbs>bWait=true<" & "/script>" _
        & "<body bgColor=#0d8499><center>" _
        & "<center> </center>" _
        & "<center> </center>" _
        & "<center>" _
        & "<font face=" & Chr(34) & "Comic Sans MS" & Chr(34) & " color=#d4d4d4>" _
        & sBody & "</font><p>" _
        & "<img alt=" & Chr(34) & Chr(34) _
        & "src=" & Chr(34) & "file:///" & cSVRPATH & "\" & cAniGif & Chr(34) _
        & "align=bottom>"
        s = s & "<br><br> <input id=Button1 type=button value=Cancel onclick =Window.Close()>"
        s = s & "</center></body></html>"
        .Open
        .Write (s)
        .Close
        Do Until .ReadyState = "complete": WScript.Sleep 50: Loop
        With .body
            .Scroll = "no"
            .Style.BorderStyle = "outset"
            .Style.BorderWidth = "3px"
        End With
        oIE.Visible = True
        CreateObject("Wscript.Shell").AppActivate sTitle
        On Error Resume Next
        On Error GoTo 0
    End With
End With

End Function
 

Isaac

Lifelong Learner
Local time
Today, 15:31
Joined
Mar 14, 2017
Messages
8,777
@Minty - Thanks for the suggestions!

So, it appears that MS has done a lot to kill vbscript in the last few years (automatically disabled in IE and Edge for one thing). To those using vbscript regularly (as FE udpater, app launcher, etc) what do you do?
The death of VBScript has been greatly exaggerated, tho PowerShell is definitely it's younger, prettier sister, in the game of popularity.

I use it for fairly simple stuff regularly and have no issues, I mean, it of course has advantages and disadvantages. It's easy to pop the path to a script file into Windows Task Scheduler, which is nice - and, I can attest, an approach still used by large, modern companies in many more cases than they'd like to admit...

Obviously it's best for situations where your code does not need to be private, and for people who deeply enjoy testing for error codes with IF statements...
 

Isaac

Lifelong Learner
Local time
Today, 15:31
Joined
Mar 14, 2017
Messages
8,777
I use Notepad++ https://notepad-plus-plus.org/ - it's free and very powerful
And Textpad which I paid for years ago.

They both have language add-ins that will highlight text and keywords automatically and have powerful Block Editing functions, really handy when making adjustments to large chunks of text.
Love Notepad++!! An absolute "must". Even for the smallest things - get a VBScript error, right click the file and open in Notepad++ this time, just to see the line #'s if nothing else. It's also good for LAAARGE text files if you've ever had to deal w/those from a vendor or something, (although get the 64 bit steroid edition of it in order to handle really large text files, > 2GB).

Also love the plugin in Notepad++ that enables you to actually place the fully-colored text on your clipboard - nice for sending emails.
 

Users who are viewing this thread

Top Bottom