473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

object problem

Hi
im trying to create a VB program that allows storing and reading to a TXT file i keep getting error 424 object required, im not all to good with VB but i have to get this working for an assignment by thursday. i can (without the loop) read and write a single persons information but i have to save many records .

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Dim Employee As Object
  4. Dim EmployeeCollection As New Collection
  5. Dim counter As Integer
  6.  
  7.  
  8. Private Sub cmdExit_Click(Index As Integer)
  9.  
  10. Dim i As Integer
  11. Dim counter As Integer
  12.  
  13. counter = EmployeeCollection.Count
  14.  
  15. Open "c:\temp\Storage.txt" For Output As #1
  16.  
  17. For i = 1 To counter
  18.  
  19.     Write #1, EmployeeCollection.Item(i).Fullname
  20.     Print #1, EmployeeCollection.Item(i).Area
  21.     Print #1, EmployeeCollection.Item(i).Postcode
  22.     Print #1, EmployeeCollection.Item(i).Address
  23.     Print #1, EmployeeCollection.Item(i).Contactno
  24.     Print #1, EmployeeCollection.Item(i).Pos
  25.     Print #1, EmployeeCollection.Item(i).Salary
  26. Next
  27.  
  28. Close #1
  29.  
  30. End
  31.  
  32. End Sub
  33.  
  34.  
  35. Private Sub cmdNew_Click(Index As Integer)
  36.  
  37. Set Employee = New clsEmployee
  38.  
  39.     Employee.Fullname = txtFullname.Text
  40.     Employee.Address = txtAddress.Text
  41.     Employee.Area = txtArea.Text
  42.     Employee.Postcode = txtPostcode.Text
  43.     Employee.Contactno = txtContactno.Text
  44.     Employee.Pos = txtPos.Text
  45.     Employee.Salary = txtSalary.Text
  46.  
  47.  
  48. EmployeeCollection.Add clsEmployee
  49. txtEmployeeno.Text = EmployeeCollection.Count
  50. Set Employee = Nothing
  51.  
  52.     txtFullname.Text = " "
  53.     txtAddress.Text = " "
  54.     txtArea.Text = " "
  55.     txtPostcode.Text = " "
  56.     txtContactno.Text = " "
  57.     txtPos.Text = " "
  58.     txtSalary = " "
  59.  
  60. End Sub
  61. Private Sub Form_Load()
  62.  
  63.     Dim FileFullname As String
  64.     Dim FileArea As String
  65.     Dim FileAddress As String
  66.     Dim FilePostcode As String
  67.     Dim FileContactno As String
  68.     Dim FilePos As String
  69.     Dim FileSalary As String
  70.  
  71. Set EmployeeCollection = New Collection
  72. Set Employee = New clsEmployee
  73.  
  74.  
  75. Open "c:\temp\Storage.txt" For Input As #1
  76.  
  77. While EOF(1) = False
  78.  
  79.     Input #1, FileFullname
  80.     Input #1, FileAddress
  81.     Input #1, FileArea
  82.     Input #1, FilePostcode
  83.     Input #1, FileContactno
  84.     Input #1, FilePos
  85.     Input #1, FileSalary
  86.  
  87.     Employee.Fullname = FileFullname
  88.     Employee.Address = FileAddress
  89.     Employee.Area = FileArea
  90.     Employee.Postcode = FilePostcode
  91.     Employee.Contactno = FileContactno
  92.     Employee.Pos = FilePos
  93.     Employee.Salary = FileSalary
  94.     EmployeeCollection.Add Employee
  95.  
  96. Wend
  97. Close #1
  98.  
  99.     txtEmployeeno.Text = EmployeeCollection.Count
  100.     txtFullname.Text = EmployeeCollection.Item(EmployeeCollection.Count).Fullname
  101.     txtAddress.Text = EmployeeCollection.Item(EmployeeCollection.Count).Address
  102.     txtArea.Text = EmployeeCollection.Item(EmployeeCollection.Count).Area
  103.     txtPostcode.Text = EmployeeCollection.Item(EmployeeCollection.Count).Postcode
  104.     txtContactno.Text = EmployeeCollection.Item(EmployeeCollection.Count).Contactno
  105.     txtPos.Text = EmployeeCollection.Item(EmployeeCollection.Count).Pos
  106.     txtSalary.Text = EmployeeCollection.Item(EmployeeCollection.Count).Salary
  107.  
  108. End Sub
  109.  
  110.  
  111.  
  112.  
  113.  
Mar 10 '08 #1
3 1168
jeffstl
432 Expert 256MB
First start with narrowing it down. Which line is the Error 424 occuring on? This will help if you can step through the code during run time and try to determine where its happening.

I also notice you are delclaring a class in your code
Set Employee = New clsEmployee

I assume you have a .cls file that declares the Employee properties?

If so you need to make sure that class is referenced in your references of the project. Also make sure if they are seperate that you have compiled them in the right order. That would be my first guess of the problem.
Mar 10 '08 #2
First start with narrowing it down. Which line is the Error 424 occuring on? This will help if you can step through the code during run time and try to determine where its happening.

I also notice you are delclaring a class in your code
Set Employee = New clsEmployee

I assume you have a .cls file that declares the Employee properties?

If so you need to make sure that class is referenced in your references of the project. Also make sure if they are seperate that you have compiled them in the right order. That would be my first guess of the problem.

the problem is
Print #1, EmployeeCollection.Item(i).Fullname
and i got clsEmployee as the main class and
Fullname
Address
Area
Postcode
Contactno
Pos
and Salary as propities
my collection is Employee
Mar 10 '08 #3
Killer42
8,435 Expert 8TB
Try defining a new object of type clsEmployee (or whatever it was, I forget). Assign each item from the collection to that object, and print from there, instead of from the collection.
Mar 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
7
by: Nick Zdunic | last post by:
I have a remotable object running in my host application. The host starts up and creates the object. Within a method to start the remote object doing its thing it creates an object. ...
8
by: mcmg | last post by:
Hi, I have an asp app that works fine on a windows xp machine but does not work on a windows 2000 server. I have the following code in my global.asa: <OBJECT RUNAT=Server SCOPE=SESSION...
2
by: Aaron | last post by:
I have a data sructure setup and I populate it in a loop like so: y=0 while X: DS.name = "ASDF" DS.ID = 1234 list = DS; y = y + 1
4
by: 6tc1 | last post by:
Hi all, I have just finished debugging a windows application and have solved the problem - however, I want to be sure that I understand the problem before I move on. Before I detail the problem,...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
4
by: Arapi | last post by:
I am having a very strange problem with my asp.net application. I am getting error: 'Object reference not set to an instance of an object' when I run my app from my hosting company. I have...
6
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.