Jump to content
Server Maintenance This Week. ×

VBscript repository - free for the taking


This topic is 6729 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Microsoft offers a free Access database with some 2000 useful VBscripts. They were kind enough to allow me to rework this as a FileMaker database and make it available to the FileMaker community. You will find it in the downloads section of my website.

Enjoy,

Wim.

Wim Decorte

www.connectingdata.com

T +49 (0)8024 3030752

F +49 (0)8024 3030753

Certified FileMaker 7 Developer

Link to comment
Share on other sites

  • 2 weeks later...

Thanks, Wim! I have downloaded and looked through it. Though I'm familiar with VBA in Excel, VBScript is new to me. But the syntax looks quite similar.

So if you don't mind, let me ask a question about VBScript which will expose my ignorance. :

Is there a way to use VBScript to pull the text of a web page into a FM field? Or, alternatively, to save the web page text as a file so that I could import it into a field?

Thanks!

Link to comment
Share on other sites

Thanks very much for this, Wim!!

VBscripts offer such flexibility and control. The backup routines have saved me already! Your website is a beautiful collection of invaluable developer tools and I plan to take advantage of every one of them. :wink2:

Link to comment
Share on other sites

Is there a way to use VBScript to pull the text of a web page into a FM field? Or, alternatively, to save the web page text as a file so that I could import it into a field?

Most definitely. It will require talking to IE (Internet Explorer) but it can certainly be done. Let me see if I can find an example...

The challenge will be to get the data into FM. Unless you're willing to paste, you'll need to go through the import engine. That means you can't have returns in the data or fm will create different records. You'll need to have the VBscript replace all returns with something else and then have FM substitute those out again to put the returns back in.

Link to comment
Share on other sites

As a matter of fact, there is a script in the repository that does this. Look for "List the Contents of a Web Page" in category "scripting techniques".

If you don't like that one, here's another (below).

You'd need to add code to output the text to a text file (see the repository) and then have FM import it. You can even have the VBscript call the FM import script to solve any timing issues.

' ***************************************************

'

' VBScript to grab the content of a web page

'

' Author: Wim Decorte

' Date: Friday, November 25, 2005

' Version: 1.0

'

' ***************************************************

Option Explicit

Dim oIE

Dim webPage

Set oIE = CreateObject("InternetExplorer.Application")

oIE.Visible = True

oIE.Navigate("http://www.connectingdata.com/")

' loop until the page is loaded

While oIE.Busy

Wend

' if you want the full html:

' webPage = oIE.Document.DocumentElement.OuterHtml

webPage = oIE.Document.DocumentElement.innertext

MsgBox webPage

oIE.Quit

Set oIE = Nothing

Link to comment
Share on other sites

Nope, you need to talk to the Windows API to make that happen. VBscript can't talk to the API directly. VB and other real programming languages can. So you could write a tiny VB app that does it and use a Send Event from inside FM to run it.

To ease deployment you can put the VB app in a container and use the "export field content" to put the vb app on the hard disk before running it.

Link to comment
Share on other sites

Yes, that's one of the disadvantages of WinBatch. The executables are generally large (over 1MB) and slow to execute. A comparable VB application would a whole lot faster and would come in under 100Kb.

Different learning curve though. But I must say learning VB and VBscript go hand in hand and it's not called Basic for nothing :)

Link to comment
Share on other sites

You've made this comment before, but I have to strongly disagree with you. I have written many WB utilities all of which (except for the one we are currently discussing) are small and run very rapidly. Since most have fewer than 20 lines, I incorporated groups of scripts into one source file, which might have a length of 1500 lines.

To call an individual script, all I do is pass the .exe a command line parameter telling it which of the scripts to execute.

These compile rapidly (under a minute), and the .exe are in the 150k size. I don't include any extenders in the compiled .exe, preferring to put them on the user's disk using an installer.

I think what you're seeing is the source plus however many extenders the source refers to, linked into 1 .exe. The first time the WB is run, it auto-exports the attached extenders into the folder, but the extenders are still present within the .exe. That is what accounts for the large .exe size.

I find WB very efficient, requiring minimal scripting, covering a wide range of functionality, and great customer support. It is a great tool for working with FM limitations.

Link to comment
Share on other sites

Thanks, Wim! Your VBScript for pulling the text of a web page is nice!

I'm not familiar with the object model of IE, but from your statement MsgBox WebPage I had though that WebPage might be a string to which I could apply the Copy method (i.e., WebPage.Copy) to put the text on the clipboard, but that doesn't work. But if I could have the VBScript copy to the clipboard, I could have FM paste into a field and parse parse the web page instead of having another VBScript deal with the returns. Any suggestions on the Copy?

You can even have the VBscript call the FM import script to solve any timing issues.

How would this be done?

Thanks so much for the help!

James

Link to comment
Share on other sites

Without trying this I would bet that you could have the VBScript dump the contents of the web page into a text file and then you could script FileMaker to import the contents of the text file into a global field.

I haven't tried this but I think I would try this method and not mess around with the clipboard at all.

Link to comment
Share on other sites

Ted, I have modified Wim's code to dump the results into a text file as follows:

' ********************************************* ******

'

' VBScript to grab the content of a web page

'

' Author: Wim Decorte

' Date: Friday, November 25, 2005

' Version: 1.0

'

' ********************************************* ******

Option Explicit

Dim oIE

Dim webPage

Dim objFSO, objFile

Const ForWriting = 2

Set oIE = CreateObject("InternetExplorer.Application")

oIE.Visible = True

oIE.Navigate("http://www.ConnectingData.com/")

' loop until the page is loaded

While oIE.Busy

Wend

' if you want the full html:

' webPage = oIE.Document.DocumentElement.OuterHtml

' webPage = oIE.Document.DocumentElement.innertext

' MsgBox webPage

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile ("C:results.txt", ForWriting)

objFile.Write oIE.Document.DocumentElement.innertext

objFile.Close

oIE.Quit

Set oIE = Nothing

Though I haven't tried an import yet, Wim pointed out that the returns in this file will create separate records when imported. So the returns need to be replaced with something else before import. I don't know enough about VBScript at this point to know if that would require a separate script or if I could perform the operation within the same script.

Seems like copying the text and pasting it might save that operation.

Link to comment
Share on other sites

Since I don't seem to be able to edit or delete my last post, here is Wim's code further modified to replace the returns with pipes so that an import of the file will be in a single record.

' ********************************************* ******

'

' VBScript to grab the content of a web page

'

' Author: Wim Decorte

' Date: Friday, November 25, 2005

' Version: 1.0

'

' ********************************************* ******

Option Explicit

Dim oIE

Dim webPage

Dim objFSO, objFile

Const ForWriting = 2

Set oIE = CreateObject("InternetExplorer.Application")

oIE.Visible = True

oIE.Navigate("http://www.ConnectingData.com/")

' loop until the page is loaded

While oIE.Busy

Wend

' if you want the full html:

' webPage = oIE.Document.DocumentElement.OuterHtml

webPage = oIE.Document.DocumentElement.innertext

' MsgBox webPage

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.CreateTextFile ("C:results.txt", ForWriting)

objFile.Write replace(webpage,vbcrlf,"|")

objFile.Close

oIE.Quit

Set oIE = Nothing

Link to comment
Share on other sites

Good responses so far.

I'm not a big fan of using the clipboard but if you want to use it, add this line right after capturing the web page:

oIE.document.parentwindow.clipboardData.SetData "text", webPage

Then you go can switch to FM and paste, or even have the VBscript call a FM script that goes to the right field and does a paste.

Note that using the clipboard can be turned off in the security settings of IE so it is not guaranteed to work...

Link to comment
Share on other sites

This is a standalone script so you'd to work this into whatever VBscript you want to use it.

Check the FM help file for "activeX" to read an overview of all the FM objects and methods. The examples give are for VB and VBA not VBscript so you'd need to do minimal changes to make the examples work in VBscript.

-----------------------------------------------

Dim fmApp, fmDocs, fmDoc

Set fmApp = CreateObject("FMPRO.application")

fmApp.Visible = True

Set fmDocs = fmApp.Documents

' typically you'd check here for fmDocs.count

' to see if FM even has files open

' hooks into the active doc

' loop through the docs and check for names if you want

' to target a specific one

Set fmDoc = fmDocs.active

' don't forget to check for scriptstatus before you do this

' calling a script from the outside *will* interrupt

' any running script

fmDoc.dofmscript("theScript")

' clean up

Set fmDoc = Nothing

Set fmDocs = Nothing

Set fmApp = Nothing

-----------------------------------------------

Link to comment
Share on other sites

Brudderman,

Take a look at the downloads section on Wim's site - near the bottom of the list. I believe that he has an example there.

I also think there is an example in FileMaker help. There was in v7, I assume it's there in v8 too although the v7 version was written for Visual Basic not VBScript if my memory serves me.

Link to comment
Share on other sites

This topic is 6729 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.