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 1882 QVeen72 1,445
Recognized Expert Top Contributor
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
QVeen72 1,445
Recognized Expert Top Contributor
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, EmployeeCollect ion.Item(i).Ful lname
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 = EmployeeCollect ion.Item(i)
Script out of range ?
nope giving out error 9 on click of exit button
Set employeeObject = EmployeeCollect ion.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.
Running under debug mode permits saving my tiff files (with Image.DEBUG=0,
the save doesn't work! see below) , but it truncates the crazy tags in my
tiff and changes the resolution of the image
|
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 would appreciate it if anyone could
either help me out, or direct me to an online resource site that has
information on saving/loading classes. I have found several tutorials, but
they either do not really help (saving text files) or are too...
|
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 replaced by
what seems to be iso-8859-1 (which Flash doesn't understand, but that's
another problem). Any help greatly appreciated.
* Something like this...
|
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 will get the page displayed.
But I don't want to display it, instead save those files in one of the
network directories that can be accessed by our third party vended web based
application. How can I do this accessing and saving HTML files a...
|
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 BinaryWriter(fStream);
img.Save(bw.BaseStream, ImageFormat.Bmp);
| |
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 have tried POSTin to be able to view the image, then saving it, but it
doesnt work, the problem i have is that all the files on the server have the
same name, which is
http://1.1.1.1/DH/repository/content.tif
and for me to be able to view one, 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:
An unhandled exception of type
'System.Runtime.InteropServices.ExternalException' occurred in
system.drawing.dll
Additional information: A generic error occurred in GDI+.
|
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 code ??
thank you
Pedro Leite From Portugal
------------------------------------
|
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, but I have a
3rd party software that will convert vb projects into .exe files. My
issue is in the the saving of the excel file. The macro bassicly
imports a tab delimeted file and manipulates the file and then saves
it, as a template to work...
|
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 was created via an existing .sql file. Included were a
bunch of stored procedures. I went in to re-format these procedures.
(They were written in haste by another programmer. It is my task to go
back and improve their readabilities.) However, I am...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |