Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening an Input file that doesn't exist (cont)

Status
Not open for further replies.

BadCook

Technical User
Sep 7, 2009
71
0
0
US
Just got back to this problem.
I think my VB6 program lacks something.
The following,(copied from a VB6 reference book) gives an error message.

Dim Fsys as New FileSystemObject

Error Msg: "User defined type not defined"

Can anyone suggest a solution?
 
Click Project -> References
Select "Microsoft Scripting Runtime"


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
gnmastros
Thanks for responding

I did as you said, same error message.
Any other suggestions?
 
Check your references for a "MISSING" entry.
If none is missing: are you gettgin that error on the same line still, i.e. still for the FileSystemObject??

“Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.” (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Try running the following in the immediate window:

set fso= createobject("scripting.filesystemobject")

Do you get an error message?
 
In my Form_load Sub I typed:
Dim Fsys as New Filesystemobject
set Fsys = Createobject("Scripting.filesystemobject")

In the immediate window I typed the same:
set Fsys = Createobject("Scripting.filesystemobject")

pressing Ctrl+G, nothing happens
 
>I typed the same:
> set Fsys = Createobject("Scripting.filesystemobject")
>
>pressing Ctrl+G, nothing happens


Well it wouldn't. I asked you to run the command, so type it in the immediate window and then press Enter.

And let us know whether you get an error messsage of not.
 
I did just that and the only result was that it disapeared from the immediate window. No error message.
Is there a further step ?
 
>it disapeared from the immediate window

Er, how big is your immediate window. Unless it is onloy 1 line high I wouldn't expect any disappearance. Still, if there is no error message generated then it means that the Microsoft Scripting Runtime library is registered correctly, so

Dim Fsys as New FileSystemObject

should not be causing

"User defined type not defined"

So, can you copy and paste the chunk of code around the line that causes the problem, rather than just the line itself.


Oh, and just to be sure, when following gmmastro's advice, you did ensure that "Microsoft Scripting Runtime" was ticked, rather than just highlighted, yes?
 
I'm sorry that my unfamiliarity with these,to me,new areas of VB6 coding are causing confusion.
I appreciate your patience very much.
What do you mean by "ticked" ? Where should I put "Microsoft Scripting Runtime" and how do I "tick" it.
 
Open your project in the VB6 IDE.
On the menu at the top, click "Project"
Click "References"

After a moment, you should see a list of references. This list will show the references that are already part of the project and shown with a check mark in the box to the left of the item. After the list of selected references, you will see more items without a check in the box to the left of the reference name.

If "Microsoft Scripting Runtime" appears at the top of the list with a check in the box to the left of the description, then it is already referenced in the project. If it does not appear near the top of the list, that means it is not currently selected. In this case, scroll down until you find "Microsoft Scripting Runtime". Put a check mark in the box to the left of "Microsoft Scripting Runtime". Click OK to close the references box.

At this point, your code should work. Please report back either way (whether it works or not).

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
gnmastros
Thanks for your message.
The scripting changes worked.
Using "Append" in the file input sub opened a txt file on my C drive.
In the output file however using "Output" the files in the txt files are there but are simply skipped.
If I use "Append" the saved files are deleted.

What my program requires is that at the first start, during or after installation a text file is created on the C drive. The first thing the program does is to load data from this filte to a list box. It then deletes all data from the text file. After the imported data is worked on, the program transfers it to the text file.
In other words the data is either in the txt file or in the program.

I made a short test program I can send you. However I have my VB 6 innstalled in a virtual XP program on a computer with a main OS of 7. I can't get on line from the virtual machine.

Can I send you the test program to your blog ?
 
Sending code" to others off this site is discouraged, because it prevents others from benefiting from the help you get. Simply paste your code here... even better, paste it within [ignore]
Code:
[/ignore][/b] and [b][ignore]
[/ignore]
tags.
 
Here is the Code to my test file.
I had to type it manually Since my Virtual OS does not interact with Windows 7, so excuse any typos.
With This test program I type in multipl stuff from Text.Text, sending each entry to to List1, save List1 to "C\TextFile.txt", clear List1, then open "C\TextFile.txt" to retrieve the data back to list2-when the problem I described in my previous reply occurs.
Thank you for any help.

Option Explicit
Private Sub Command3_Click()
List1.AddItem Text1.Text
Text1.Text = ""
End Sub

Private Sub Command4_Click()
List1.Clear

Private Sub Form_Load()
Dim Ssys As New FileSystemObject
End Sub
Private Sub Command2_Click()
Dim fnum as Integer, DD as Integer
fnum = FreeFile()
Open "C\TextFile.txt" For Append As #fnum
For DD = 0 to List1.ListCount -1
Write #1, Trim(list.List(DD))
Next
Close fnum
End Sub

Prvate Sub Command1_Click()
Din SSS as String, fnum as integer,DD as Integer
fnum = FreeFile()
Open "C:\TextFile.txt" For Output As #fnum
Do until EOF(fnum) = True
Input #fnum, SSS
List1.AddItem SSS
Loop
Close fnum
End Sub















 
>I can't get on line from the virtual machine

Really? XP Mode on my Windows 7 box quite happily uses my internet connection (and happily interacts with W7, and can folders and files). What virtualisation are you using?

Anyway ...

The code you have shown is a non-FSO version, so all this time we've spent trying to get

[tt]Dim Ssys As New FileSystemObject[/tt]

working properly has been pointless, since you don't actually use Ssys at all.

Right, that being dealt with, let's move on. Consider this line:

[tt]Open "C:\TextFile.txt" For Output As #fnum[/tt]

Are you quite sure this is right, given that what you then seem to want to do is read from the file ...



 
Thank you again for your interest.
I bought my computer, an HP Laptop, with the virtual XP OS allready Installed. I don't know what the version is. I was told that VB 6 works better on XP. If as you say VB 6 works OK on Windows 7, I certanly will try it. I have consulted with my Time Warner cable people, the Geek Squad, and HP. All these "experts" told me that I can't get on line from the virtual side.

I used the Open for Output to simply make the file on the hard drive. I then used the Open for Input to acces that file. The first time a call for input is msde the file will be empty but from then on it will delliver data. But this is only a test program.
As I have said, the first thing the program I intend to use this on does is enter the stored data and delete that data from the file. Then, when the data is worked on, The reworked data is stored back to the file. In other words the data is either in the file or in the program, not both.
 
Nope. Almost, but not quite.

You really should give your controls better names other than Command1, List1, Text1, etc... It's makes debugging harder.

According to the code you posted, saving the data will append to the file. This means that if you load a couple items in the list box and the click Command2 several times, you will have duplicates.

The code that strongm was referring to is in Command1_Click. You code opens the file for output, and then inputs from the file.

Code:
Private Sub Command1_Click()

  Dim SSS as String, fnum as integer,DD as Integer

  fnum = FreeFile()

  Open "C:\TextFile.txt" For [!]Output[/!] As #fnum
  Do until EOF(fnum) = True
    [!]Input[/!] #fnum, SSS
    List1.AddItem SSS
  Loop
  
  Close fnum

End Sub


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
>VB 6 works better on XP

I'd agree with this.

>If as you say VB 6 works OK on Windows 7

That's not what I said.

>I have consulted with my Time Warner cable people, the Geek Squad, and HP. All these "experts" told me that I can't get on line from the virtual side

They are all completely 100% misinformed.
 
I believe the best way to handle this is to descrbes what the program does and requires.
When the program opens it immediatly imports the complete data from a file on the hard drive to a list box. So far I've been getting around the fact that in a new installation the file doesn't exist by separtly creating an empty file on the hard drive. I don't want the user to have to this, so the program has to do it.
The first time the program is used it should create the file. It will try but import no files since the file is empty. The user generates data in the program and when finished a command sends the data to the file which must be preserved. On subeequent use the program must not create the file again since that will creat a new file and destroy the stored data.
When the data is imported to the program the file is emptied so that the data is stored either in the programor in the file. never in both.

I hope this is clear and I feel this is a commone problem that has been solved.
But then, who am I to know?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top