Solved

FileSystemObject

Posted on 2001-06-07
21
196 Views
Last Modified: 2010-05-02
Hi.

I have a browser form in my project. I'd like to be able to load my HTML resume within this browser from the frmAbout. I was looking in MSDN Help at the FileSystemObject. I tried to declare a variable of type FileSystemObject, but apparently I don't have it. It must be a control or a reference that I haven't included.

Is this the right approach and ,if so, where is this control located?

Jim
0
Comment
Question by:jnowlin
  • 9
  • 7
  • 2
  • +3
21 Comments
 
LVL 2

Expert Comment

by:chandukb
ID: 6165507
Reference Microsoft Scripting Runtime Library

Chandu
0
 
LVL 1

Expert Comment

by:eab111098
ID: 6165530
inowlin, the filesystemobject is part of the microsoft scripting runtime (scrrun.dll). goto to projects menu, and references and scroll thru till you see microsoft scripting runtime and check it. then you'll see filesystemobject as part of a type when declaring variables.

i've used this in the past and it has some good features but, it can be a slow beast.

have fun.
ed.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6165552
why do you think you need FSO?  are you using webbrowser control?  if so, simply...

WebBrowser.Navigate "C:\path\Resume.html"
0
 

Author Comment

by:jnowlin
ID: 6169303
AzraSound,

I thought the FileSystemObject was what i needed.
When I tried the WebBrowser control, as in the clicked event of the control went:
Dim res1 As WebBrowser


res1.Navigate "c:\resume1.htm"
I got the Object variable or With block variable Not Set.
run-time error 91.

Did I leave out another reference for the project?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6169390
the webbrowser control is just that, a control.  you add it to a form and then use it via code.  if this is not what you are after, then perhaps you are after automating an instance of IE.
0
 

Author Comment

by:jnowlin
ID: 6171652
Originally, I did think of automating an instance of IE. Actually, one of the buttons I added to this project was to try and use the Shell command to launch IE. It worked with NotePad and Windows Explorer but it crashed, unable to find the file: IEXPLORE.EXE.  Strange.

Anyway, as above, when I defined res1, one of the data types in the list was WebBrowser V1.

But, it's a control you say. I don't have it on my toolbar. Which component do I need to add to the project?
Jim
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6172175
to use the webbrowser control on a form:
go to project -> COMPONENTS and select Microsoft Internet Controls.  you will then see a small globe icon in your toolbar which denotes that component

to automate IE:
go to project -> REFERENCES and select Microsoft Internet Controls.  you can then use code like the following:


Private WithEvents IEObj As SHDocVw.InternetExplorer

Private Sub Form_Load()
   Set IEObj = New SHDocVw.InternetExplorer
   IEObj.Navigate "C:\path\Resume.html"
   IEObj.Visible = True
End Sub
0
 

Author Comment

by:jnowlin
ID: 6173586
AzraSound,

the WebBrowser control works. It's slick.

When I created a new form, frmIE
and put

Private WithEvents IEObj As SHDocVwCtl.InternetExplorer
' SHDocVw was not an available type

into the Genneral declaration
and the following into frmIE's Form_Load event, as in
Private Sub Form_Load()
  Set IEObj = New SHDocVw.InternetExplorer
  IEObj.Navigate "C:\Resume1_VBApp.html"
  IEObj.Visible = True
End Sub

and then, in a menu's Clicked event do the
frmIE.Show

I can hear IE starting to launch but then I get a Run-time error # 430- "Class does not support Automation or does not support expected interface"

I'm using VB 6.0 Professional SP3. Is this Class perhaps only available in the Enterprise version of VB?

Jim
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6173713
>>Private WithEvents IEObj As SHDocVwCtl.InternetExplorer
>>' SHDocVw was not an available type

if you wish to automate IE, you need to go into Project -> References and select Microsoft Internet Controls, in addition, or as opposed to, going into Project -> Components  (if you already have it checked in Project -> Components, it may appear checked under References as well, but it really isnt.  you will want to scroll down and find it in the list and select it again)
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6177585
jnowlin:

>When I tried the WebBrowser control, as in the clicked
>event of the control went:
>Dim res1 As WebBrowser
>
>
>res1.Navigate "c:\resume1.htm"
>I got the Object variable or With block variable Not Set.
>run-time error 91.
>
>Did I leave out another reference for the project?

Just thought I'd clear up one point of confusion. First, I don't think you can use this ActiveX Control (i.e. WebBrowser) in this manner. But this is not the problem I wanted to address. I wanted to address the issue of "Object Variable Not Set".

When you declare an object variable, such as your "res1" above, you have not yet created an instance of that object. All you've done is created a reference and have informed the compiler that it will be a reference to that particular type of object.

For example:

   Dim w As Widget

This does not create a Widget Object. It does create a Widget reference, named 'w'; but currently, that reference does not point to any Widget object. Its value is 'Nothing'. (i.e. it points to nothing)


Now consider the following:

   Dim w As Widget

   Set w = New Widget

The Set-statement above actually creates a new Widget object, and causes the reference 'w' to point to that Widget object.  The object variable 'w' now contains a reference to the newly-created Widget object.


Consider the following code:

   Dim w1 As Widget
   Dim w2 As Widget
   Dim w3 As Widget
   Dim w4 As Widget

   Set w1 = New Widget
   Set w2 = New Widget
   Set w3 = New Widget

Now, with this code how many Widget objects do you have? The answer is 3. w1 is a reference to the first Widget; w2 is a reference to the second Widget; w3 is a reference to the third Widget; and although w4 is also a Widget Reference Variable (i.e. object variable), it does not refer to any existing object; it points to Nothing; it has not been set. Make sense?


Now study the following code:

   Dim w1 As Widget
   Dim w2 As Widget
   Dim w3 As Widget
   Dim w4 As Widget

   Set w1 = New Widget
   Set w2 = w1
   Set w3 = w1
   Set w4 = w3

How many Widget objects have been created? The answer is 1. You have 4 Widget References, all of which point to the very same object (i.e. Widget)



Now, let's revisit your sample code:

   Dim res1 As WebBrowser

   res1.Navigate "c:\resume1.htm"

In the first line, you've created an object variable (res1) which you've stipulated can store a reference to a WebBrowser object. (again, we're assuming that 'WebBrowser' is a valid Object Class). So 'res1' is a WebBrowser reference, but does not yet point to any object; it has not been set; it points to Nothing.

Then, in the second line, you are instructing the WebBrowser Object (to which res1 refers) to invoke its Navigate() method. The problem is that res1 does not refer to any object, so that non-existant object cannot invoke the navigate method.

Hence, the reason you got the error: "Object variable or With Block variable Not Set"


Make sense?


-Dennis Borg
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:wsh2
ID: 6177856
<ping>
0
 

Author Comment

by:jnowlin
ID: 6178322
Yes DennisBorg, it makes sense. Just a oversight by me due to a misfiring brain cell or two. :)  
I'll correct that easily enough.

wsh2 -
<ping> ??
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6178660
jnowlin:

Glad you understand. ;-)

FYI - You inquired as to the meaning of the "ping" message given by wsh2. The ping simply means that the person may not have a solution, but is interested in learning what the solution is. This allows for them to be notified via e-mail as additional comments are made, just like the subscribe feature, but with the added ability to turn the e-mail notifications off, should a lengthy discussion continue after the question is closed by a answer being chosen. Another benefit would be to allow one to read the answer without having to spend the points.

In short, it simply means the person is "listening in, in hopes of learning something new"


-Dennis Borg
0
 

Author Comment

by:jnowlin
ID: 6179071
Ah, OK.
I couldn't for the life of me figure out what that was.


AzraSound,

>>the WebBrowser control works. It's slick.

Yes. But, when I close the form it's on, I get "This Program has performed an illegal action and will be shut down.", and VB crashes. I am missing something. The WebBrowser is a control on another form, named, wb1. And, on the Form Load event of frmJim, this is placed there:

wb1.Navigate "C:\VB_Audit\resume1_VBApp.htm"

opening my resume (RESUME1.HTM) and displaying it correctly within the control (wb1).
Do I need to perfom some file closing on the Form Unload event?

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6179168
strange...what version of IE do you use?  if IE5 or above, you may look at upgrading to SP4.  i have used the control many times before and never received such an error.

what other tasks are you performing in your app?  any subclassing?  any memory copying/moving APIs being used?
0
 

Author Comment

by:jnowlin
ID: 6179328
I have one function CheckSpelling() which creates Word objects and performs SendKeys ^c True to copy text from a text file into Word, invoke the spell checker, leave the spell checker, take the changed text and paste it back into the original file.....it crashes also. I have a couple of forms which use a Adodc control on each to get data from the NorthWind database.

It's not yet THAT complex, I don't think.

It's IE 5.5 but I don't know what Service Pack it is.
I've been trying to add someone's code to display messages in the status bar. I was told that I need to subclass but subclassing is very new to me. I don't as yet have any APIs in this project.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 6179349
are you properly destroying these Word objects you are creating?  i'm not an expert on word automation, so i am not aware of possible problems it may raise.  however it sounds like some of what you are doing could be tackled easier by utilizing the object model exposed via Word automation (e.g., in place of using the SendKeys method to perform tasks)

if youve got yourself a quick internet connection, you may look at upgrading to SP4 for VB.  it seems it has cleared a few issues before with regards to IE5.5.  i think even wsh2 has stated this ever so eloquently before in other threads, that installing SP4 is highly recommended for users of IE5.5.
0
 

Author Comment

by:jnowlin
ID: 6182374
This Word automation code was given to me, with comments.
At the end of the CheckSpelling() function, the objects created are destroyed
Set wordApp = Nothing
Set wordDoc = Nothing
Yes, checking into the object model appears to be worth a try, for sure. It's kind of cool (should it work and assuming the user has Office installed) to be able to load a text file in, check the spelling correcting any errors and return the spell-checked text to the file to be saved(overwritten).

VB's SP4 is good to get, I'm sure. I was not aware that there was a SP beyond SP3. VB has been crashing each and every time I try to end (within the IDE) this program. I try to click on 'End' or 'Debug' when an error occurs, and VB goes down in flames. This frequency of crashes seems to coincide with the addition to this project of the WebBrowser control and the ability to load my resume file into it, hence, the issue of VB 6 SP3 and IE 5.5.

Well, it looks like it's gone on far enough with this question! Time for an 'A', I'd say.

Jim
0
 

Author Comment

by:jnowlin
ID: 6188672
eab,

AzraSound had the more complete answer. It was more involved and it was also where I was headed.
Thanks.
Jim
0
 

Author Comment

by:jnowlin
ID: 6188702
Hey AzraSound, thanks again.

I was working with subclassing code from expert 'Richie_Simonetti', trying to get text messages into the status bar of the MDI main form. What he sent me was working on an SDI form. I started a new project, an SDI project. It works but only in an SDI program. Also, I downloaded both Visual Basic 6.0 Service pack 4 *and* Service Pack 5. VB's IDE STILL crashes, even after an install of SP4. Interestingly enough, when I removed the subclassing code module from the MDI project, VB became much more stable. So, VB 6.0, doesn't like subclassing. Richie_Simonetti seems to understand that subclassing is in more widespread use using Visual C++ due to the fact that one is able to code at the lower level required.

That's all for this question. I'm sure I'll have more as time goes on and on and.....

Thanks again,

Jim Nowlin
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6188893
>>So, VB 6.0, doesn't like subclassing

just ensure that the code the begins subclassing a window is also properly cleaned up by unsubclassing that window before your program exits.  often times this is found in your form's unload event.  therefore, also ensure that you do not simply use the "Stop" button in the IDE to end your program as that will not call your form's unload event, and is generally just a bad practice since it introduces abnormal termination of your program.  you should always end your program just as a user would, via the "X" on your MDI form, for example.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now