HI im having problems to saving to a .txt file, i need to be able to store a number of employees to this file (and beable to open and these files to load in to text boxes)and retrieve then for later use to search and print and them add more at another stage , currently i can save and read from these files but only the last person entered is stored and over written each time . i have to use classes and Collections , im using Visual basic 6
my code so far is : -
Public Employee As Object
-
Public EmployeeCollection As New Collection
-
Dim counter As Integer
-
-
Private Sub cmdEdit_Click(Index As Integer)
-
Dim counter As Integer
-
-
counter = EmployeeCollection.Count
-
-
counter = 1
-
-
Open "c:\temp\Storage.txt" For Output As #1
-
-
For counter = 1 To forcounter
-
-
Print #1, txtFullname.Text
-
-
-
Write #1, txtAddress.Text
-
Write #1, txtArea.Text
-
Write #1, txtPostcode.Text
-
Write #1, txtContactno.Text
-
Write #1, txtPos.Text
-
Write #1, txtSalary.Text
-
-
forcounter = forcounter + 1
-
-
Next
-
-
Close #1
-
-
End Sub
-
-
Private Sub cmdExit_Click(Index As Integer)
-
-
-
Dim counter As Integer
-
-
counter = EmployeeCollection.Count
-
-
counter = 1
-
-
Open "c:\temp\Storage.txt" For Output As #1
-
-
For counter = 1 To counter
-
-
Print #1, txtFullname.Text
-
Write #1, txtArea.Text
-
Write #1, txtPostcode.Text
-
Write #1, txtContactno.Text
-
Write #1, txtPos.Text
-
Write #1, txtSalary.Text
-
-
-
' or Print #1, EmployeeCollection.item(forcounter).Fullname
-
-
forcounter = forcounter + 1
-
-
Next
-
-
Close #1
-
-
End
-
-
End Sub
-
-
-
Private Sub cmdFirst_Click(Index As Integer)
-
-
txtEmployeeno.Text = 1 'set the record number to first employee number
-
-
txtFullname.Text = EmployeeCollection.Item(1).Fullname
-
txtArea.Text = EmployeeCollection.Item(1).Area
-
txtPostcode.Text = EmployeeCollection.Item(1).Postcode
-
txtAddress.Text = EmployeeCollection.Item(1).Address
-
txtContactno.Text = EmployeeCollection.Item(1).Contactno
-
txtPos.Text = EmployeeCollection.Item(1).Pos
-
txtSalary = EmployeeCollection.Item(1).Salary
-
-
End Sub
-
-
Private Sub cmdLast_Click(Index As Integer)
-
-
counter = EmployeeCollection.Count
-
-
txtEmployeeno.Text = counter
-
-
txtFullname.Text = EmployeeCollection.Item(counter).Fullname
-
txtArea.Text = EmployeeCollection.Item(counter).Area
-
txtPostcode.Text = EmployeeCollection.Item(counter).Postcode
-
txtAddress.Text = EmployeeCollection.Item(counter).Address
-
txtContactno.Text = EmployeeCollection.Item(counter).Contactno
-
txtPos.Text = EmployeeCollection.Item(counter).Pos
-
txtSalary = EmployeeCollection.Item(counter).Salary
-
-
End Sub
-
-
Private Sub cmdNew_Click(Index As Integer)
-
-
Set Employee = New clsEmployee
-
-
Employee.Fullname = txtFullname.Text
-
Employee.Address = txtAddress.Text
-
Employee.Area = txtArea.Text
-
Employee.Postcode = txtPostcode.Text
-
Employee.Contactno = txtContactno.Text
-
Employee.Pos = txtPos.Text
-
Employee.Salary = txtSalary.Text
-
-
-
EmployeeCollection.Add clsEmployee
-
txtEmployeeno.Text = EmployeeCollection.Count
-
-
Set Employee = Nothing
-
-
txtFullname.Text = " "
-
txtAddress.Text = " "
-
txtArea.Text = " "
-
txtPostcode.Text = " "
-
txtContactno.Text = " "
-
txtPos.Text = " "
-
txtSalary = " "
-
-
End Sub
-
-
Private Sub cmdNext_Click(Index As Integer)
-
-
counter = txtEmployeeno.Text
-
counter = counter + 1
-
txtEmployeeno = counter
-
-
txtFullname.Text = EmployeeCollection.Item(1).Fullname
-
txtArea.Text = EmployeeCollection.Item(1).Area
-
txtPostcode.Text = EmployeeCollection.Item(1).Postcode
-
txtAddress.Text = EmployeeCollection.Item(1).Address
-
txtContactno.Text = EmployeeCollection.Item(1).Contactno
-
txtPos.Text = EmployeeCollection.Item(1).Pos
-
txtSalary = EmployeeCollection.Item(1).Salary
-
-
End Sub
-
-
Private Sub cmdPrev_Click(Index As Integer)
-
-
counter = txtEmployeeno.Text
-
counter = counter - 1
-
txtEmployeeno = counter
-
-
txtFullname.Text = EmployeeCollection.Item(1).Fullname
-
txtArea.Text = EmployeeCollection.Item(1).Area
-
txtPostcode.Text = EmployeeCollection.Item(1).Postcode
-
txtAddress.Text = EmployeeCollection.Item(1).Address
-
txtContactno.Text = EmployeeCollection.Item(1).Contactno
-
txtPos.Text = EmployeeCollection.Item(1).Pos
-
txtSalary = EmployeeCollection.Item(1).Salary
-
-
End Sub
-
-
Private Sub Form_Load()
-
-
Dim FileFullname As String
-
Dim FileArea As String
-
Dim FileAddress As String
-
Dim FilePostcode As String
-
Dim FileContactno As String
-
Dim FilePos As String
-
Dim FileSalary As String
-
-
Set EmployeeCollection = New Collection
-
Set Employee = New clsEmployee
-
-
Open "c:\temp\Storage.txt" For Input As #1
-
-
While EOF(1) = False
-
-
Input #1, FileFullname
-
Input #1, FileAddress
-
Input #1, FileArea
-
Input #1, FilePostcode
-
Input #1, FileContactno
-
Input #1, FilePos
-
Input #1, FileSalary
-
-
Employee.Fullname = FileFullname
-
Employee.Address = FileAddress
-
Employee.Area = FileArea
-
Employee.Postcode = FilePostcode
-
Employee.Contactno = FileContactno
-
Employee.Pos = FilePos
-
Employee.Salary = FileSalary
-
EmployeeCollection.Add Employee
-
-
Wend
-
Close #1
-
-
txtEmployeeno.Text = EmployeeCollection.Count
-
txtFullname.Text = EmployeeCollection.Item(EmployeeCollection.Count).Fullname
-
txtAddress.Text = EmployeeCollection.Item(EmployeeCollection.Count).Address
-
txtArea.Text = EmployeeCollection.Item(EmployeeCollection.Count).Area
-
txtPostcode.Text = EmployeeCollection.Item(EmployeeCollection.Count).Postcode
-
txtContactno.Text = EmployeeCollection.Item(EmployeeCollection.Count).Contactno
-
txtPos.Text = EmployeeCollection.Item(EmployeeCollection.Count).Pos
-
txtSalary.Text = EmployeeCollection.Item(EmployeeCollection.Count).Salary
-
End Sub
-
9 1872
Hi,
I guess, you are writing the Code To Save in Exit Button, And You are saving the Last Displayed TextBox Values.
Instead, Loop through all the Collection Items and Save From the Collection to the File..
Regards
Veena
Hi,
I guess, you are writing the Code To Save in Exit Button, And You are saving the Last Displayed TextBox Values.
Instead, Loop through all the Collection Items and Save From the Collection to the File..
Regards
Veena
How would i go about doing this ? im new to VB and not really any good with it
Hi,
Change the Code in Cmd_Exit to this : -
Private Sub cmdExit_Click(Index As Integer)
-
-
Dim i As Integer
-
Dim counter As Integer
-
-
counter = EmployeeCollection.Count
-
-
Open "c:\temp\Storage.txt" For Output As #1
-
-
For i = 1 To counter
-
-
Print #1, EmployeeCollection.Item(i).Fullname
-
Print #1, EmployeeCollection.Item(i).Area
-
Print #1, EmployeeCollection.Item(i).Postcode
-
Print #1, EmployeeCollection.Item(i).Address
-
Print #1, EmployeeCollection.Item(i).Contactno
-
Print #1, EmployeeCollection.Item(i).Pos
-
Print #1, EmployeeCollection.Item(i).Salary
-
Next
-
-
Close #1
-
-
End
-
-
End Sub
-
-
Regards
Veena
its giving out now an error 424 on
Print #1, EmployeeCollection.Item(i).Fullname
object required , sorry to be a pain but im really greatfull for ypur help:)
Will the following work? -
-
Dim employeeObject As clsEmployee
-
-
Set employeeObject = EmployeeCollection.Item(i)
-
-
Print #1, employeeObject.Fullname
-
Print #1, employeeObject.Area
-
Print #1, employeeObject.Postcode
-
Print #1, employeeObject.Address
-
Print #1, employeeObject.Contactno
-
Print #1, employeeObject.Pos
-
Print #1, employeeObject.Salary
-
Will the following work? -
-
Dim employeeObject As clsEmployee
-
-
Set employeeObject = EmployeeCollection.Item(i)
-
-
Print #1, employeeObject.Fullname
-
Print #1, employeeObject.Area
-
Print #1, employeeObject.Postcode
-
Print #1, employeeObject.Address
-
Print #1, employeeObject.Contactno
-
Print #1, employeeObject.Pos
-
Print #1, employeeObject.Salary
-
nope giving out error 9 on click of exit button
Set employeeObject = EmployeeCollection.Item(i)
Script out of range ?
nope giving out error 9 on click of exit button
Set employeeObject = EmployeeCollection.Item(i)
Script out of range ?
This may be your issue: -
Private Sub cmdNew_Click(Index As Integer)
-
-
Set Employee = New clsEmployee
-
-
Employee.Fullname = txtFullname.Text
-
Employee.Address = txtAddress.Text
-
Employee.Area = txtArea.Text
-
Employee.Postcode = txtPostcode.Text
-
Employee.Contactno = txtContactno.Text
-
Employee.Pos = txtPos.Text
-
Employee.Salary = txtSalary.Text
-
-
-
EmployeeCollection.Add clsEmployee
-
The last line above shows you are adding a type to the collection and not the object itself. I think you should be adding Employee and not its type 'clsEmployee' to the collection.
ok i got some thing working but still kinda over writting in the txt file now using -
-
Private Sub cmdExit_Click(Index As Integer)
-
-
Dim i As Integer
-
Dim counter As Integer
-
-
counter = EmployeeCollection.Count
-
-
Open "c:\temp\Storage.txt" For Append As #1
-
Seek #1, (counter + 1) * 7
-
Print #1, txtFullname.Text
-
Print #1, txtAddress.Text
-
Print #1, txtArea.Text
-
Print #1, txtPostcode.Text
-
Print #1, txtContactno.Text
-
Print #1, txtPos.Text
-
Print #1, txtSalary.Text
-
-
Close #1
-
End
-
-
End Sub
-
has anyone got any ideas to stop it over writting ?
The way you're using that Seek statement, it looks as though you're trying to treat the file as though all entries are exactly the same size. I doubt this is in fact the case. If you want to add onto the end of the file, just remove the Seek statement.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mchl gdbt |
last post by:
Hi,
I have several thousand tiffs generated by application A which are read by
application B. I need to remove a few colours from the tiffs and I decided
to try with the python imaging library....
|
by: G-Factor |
last post by:
Hi all
I've just started learning about saving files. I got bit of a problem. The
following code gives me an error about incompatible types. (Cannot covert
from class character to char *). I...
|
by: Philipp Lenssen |
last post by:
How do I load and save a UTF-8 document in XML in ASP/VBS?
Well, the loading* is not the problem actually -- the file is in UTF-8,
and understood correctly -- but once saved, the UTF-8 is...
|
by: Vijay |
last post by:
I need to generate HTML files based on the some codes. One HTML file per
code. I have the link
(ex:http://123.234.345.456/WebPages/GetTestData.aspx?SomeCode=25), by passing
the code as parameter I...
|
by: Peder Y |
last post by:
My code is something like this:
---------------
Image img = Image.FromFile("somefile.bmp");
FileStream fStream = new FileStream("someBinaryFile.dat");
BinaryWriter bw = new...
|
by: Thaynann |
last post by:
I have an app that (at the moment) moves through files that are on a web
site, and deletes them, wat i want to do for the next stage, is to be able to
download each file before i delete it.
i...
|
by: M Keeton |
last post by:
I currently have a picture which is stored in a "System.Drawing.Image"
variable and I want to save it as a bitmap file.
I have tried 2 different approaches and both give me the following error:
...
|
by: Pedro Leite |
last post by:
Good Afternoon.
the code below is properly retreiving binary data from a database and saving
it. but instead of saving at client machine is saving at the server machine.
what is wrong with my...
|
by: Speilman_54 |
last post by:
Hi,
I'm converting an excel Macro into visual basic 2005 express, as I
don't have a copy of VB 6 and trying to make and executable from it,
I know this version doesn't have the save file as .exe,...
|
by: Allie |
last post by:
Hi, all.
This might be a silly question... but I am very new to programming in
SQL so please bear with me :)
So. I'm using MS SQL Server 2005 Management Studio Express. I have a
table that...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
| |