Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 4th, 2003, 01:02 PM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
flatfile database using vb

hi,

I am doing a project on maintaining the contact details of the employees in a text file. I am using Visual Basic for this.
I am a bigginer in visual basic.

The thing I have to do is

1. entering data into the text file.
2. retriving the entire data from the text file.
3. editing a part of the data, like editing the contact details of a manager.
4. Saving back to the textfile any changes done to the edited data

I need to enter the data into the text file in a user friendly format
through textboxes.

and also i should edit the data of a particular employee in an user friendly format. like editing the contact details of the manager in the text boxes, textbox1 for name, textbox2 for phone number...etc.

Please help me in suggesting how to approach and also if you have done it earlier, please send a copy of the code and the procedure you did that.

Reply With Quote
  #2  
Old December 4th, 2003, 01:54 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Is this for a class project?
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old December 4th, 2003, 03:49 PM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no its a job project

hi,

this is not a course project , its my job project , which i am currently working.

if you have some information, please help me.
bye,

Reply With Quote
  #4  
Old December 4th, 2003, 05:25 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,957 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 15 h 35 m 19 sec
Reputation Power: 802
Why don't you use a backend database? If your text file gets to any size it won't be too fast and will be difficult to update.

Reply With Quote
  #5  
Old December 4th, 2003, 05:53 PM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
the project needs text file as backend

hi,

my poject needs a text file as a backend. So it was a customer specificatio. So i need to use text file only.

bye

Reply With Quote
  #6  
Old December 4th, 2003, 10:57 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Ok.. one more question - I'm guessing that you will have one text file with multiple lines, each line representing a different customer? If so, will each field be separated by commas, semicolons, how are you planning on delimiting the fields in the "records"

Reply With Quote
  #7  
Old December 5th, 2003, 11:41 AM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
abt the delimiters

hi,

I am going to use only one text file to store all the customer details. And one line for each customer.

And I should extract each customers data into textboxes.
Like one text box for name , one for phone number, one for address and so on.

And also I should save back any changes done to any feild in any text boxes to same text file at the same place from where the data has been extracted.

And also I should allow save the new data of the new customers in that field.

Thanks bye,
naveen

Reply With Quote
  #8  
Old December 5th, 2003, 01:09 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Well, there are a few ways to do this... the simplest way is to do something like this...

Code:
Dim Name As String, EmpType As String, Address As String, Pay As String, EmpClass As String
Open App.Path & "/Description.txt" For Input As #1
    Input #1, Name, EmpType, Address, Pay, EmpClass
    
Close #1

the important thing to remember is that your text file has to have the member data in the exact order you want it read in - remember, there are no field names here, and no manager to recognize them! You can do the above code by also using several arrays of strings and loading the data in a loop by using the Do Until EOF(1)...Loop structure. The way I would handle it, though, would be to declare either a class or a UserDefined type called employee, and then dim an array of that type/class. Personally, I would handle all manipulation of the data in the array, and the use the index of the array to determine what line you need to modify in the text file...

Code:
Private Type Employee
    Name As String
    EmpType As String
    Address As String
    Pay As String
    EmpClass As String
End Type
Private Sub Form_Load()
Dim EmployeeDetail() As Employee
Dim i As Integer
Open App.Path & "/Description.txt" For Input As #1
Do Until EOF(1) = True
    ReDim Preserve EmployeeDetail(i + 1)
    Input #1, EmployeeDetail(i).Name, EmployeeDetail(i).EmpType, EmployeeDetail(i).Address, EmployeeDetail(i).Pay, EmployeeDetail(i).EmpClass
    i = i + 1
Loop
Close #1
i = 0
Debug.Print EmployeeDetail(i).Name & " " & EmployeeDetail(i).EmpType & " " & EmployeeDetail(i).Address

End Sub


This is just a simple program where I have a file called "Description.txt" with comma-delimited strings as the records. I'm using a loop to load the data. One thing you will want to do - if you load records (check to make sure), then you will want to redim preserve the array after the loop to (i-1), otherwise, you'll have one more array element than you will need


Good Luck

Reply With Quote
  #9  
Old December 5th, 2003, 03:49 PM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy its not working

hi,

Thanks a lot,
but the code you gave is not working, please check it once.

Implemented it as

-----------------------------------

Private Type Employee
Name As String
EmpType As String
Address As String
Pay As String
EmpClass As String

End Type
----------------------------------------------------------------

Private Sub Form_Load()

Dim EmployeeDetail() As Employee
Dim i As Integer
Open "c:\Description.txt" For Input As #1
Do Until EOF(1) = True
ReDim Preserve EmployeeDetail(i + 1)
Input #1, EmployeeDetail(i).Name, EmployeeDetail(i).EmpType, EmployeeDetail(i).Address, EmployeeDetail(i).Pay, EmployeeDetail(i).EmpClass
i = i + 1
Loop

Close #1
i = 0
Debug.Print EmployeeDetail(i).Name & " " & EmployeeDetail(i).EmpType & " " & EmployeeDetail(i).Address

End Sub

------------------------------------------------------------------------------------

Private Sub Command1_Click()

Dim Name As String, EmpType As String, Address As String, Pay As String, EmpClass As String
Open "c:\Description.txt" For Input As #1
Input #1, Name, EmpType, Address, Pay, EmpClass

Close #1

End Sub

------------------------------------------------------------------------------------

Private Sub Command2_Click()
End
End Sub
------------------------------------------------------------------------------------


please check this..

bye,
naveen

Reply With Quote
  #10  
Old December 5th, 2003, 05:31 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
ok, well, what part isn't working? Is the program printing the record out in the immediate window? Also, what are you trying to accomplish in Command1_click? Is that where you're wanting to update the file?

Reply With Quote
  #11  
Old December 6th, 2003, 11:01 AM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
its not printing

hi,

the program is not printing in the immediate window.

And in Command_Click() I want to update the file.

plz check that.

Reply With Quote
  #12  
Old December 6th, 2003, 10:23 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
if you are wanting to update your file in Command1_Click, then you want to update that file using the Open "Filename.txt" for APPEND as #1/2/3 - a word on that subject, if your file dubbed #1 is still open, then your next instance of that file must use a different IO number (ie, incrementing that value by 1,5, whatever you want, just so that you don't have two open instances using the same alias at the same time. One more thing you will want to know, there are three main modes for opening a file - input, output, and append. Input reads data into your app, output will write to the file and over any existing data, append will write to the file leaving current data intact. For your app, I would recommend that you modify your data inside your array, use the value of the array index (counter variable?) to determine which line you want to modify in your table, then open the the file for input, loop through the records until you reach the one you want to modify. Then, move one past that record, and capture all records after that into a second array (or extend/redim your existing array and capture all values into it). Now close your input and open another instance for append - move to the record to change and rewrite it and everything after it.

After all that I should say this - if you will not a lot of records in a table (more than 5-10,000), then you can just manipulate your data in the array, and open the file for OUTPUT - this will rewrite everything in the file, including existing data. A word of caution about this - if more than one instance of your app will be open at one time, then this could cause problems when two people try to update at once. You might find a way to lock the file once it's been opened for output.

this is why Database Management Systems are so nice!

Reply With Quote
  #13  
Old December 10th, 2003, 12:15 PM
middenaveen middenaveen is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Bowling Green, Kentucky
Posts: 22 middenaveen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Private Type Employee
Name As String
EmpType As String
Address As String
Pay As String
EmpClass As String
End Type

Private Sub Form_Load()

Dim EmployeeDetail() As Employee
Dim i As Integer
Open "c:\Description.txt" For Input As #1
'i = 0
Do Until EOF(1) = True
ReDim Preserve EmployeeDetail(i + 1)
Input #1, EmployeeDetail(i).Name, EmployeeDetail(i).EmpType, EmployeeDetail(i).Address, EmployeeDetail(i).Pay, EmployeeDetail(i).EmpClass
i = i + 1
Loop

Close #1
i = 0
'Debug.Print EmployeeDetail(i).Name & " " & EmployeeDetail(i).EmpType & " " & EmployeeDetail(i).Address
MsgBox (EmployeeDetail(i).Name & " " & EmployeeDetail(i).EmpType & " " & EmployeeDetail(i).Address)
End Sub

Private Sub Command1_Click()

Dim Name As String, EmpType As String, Address As String, Pay As String, EmpClass As String
Open "c:\Description.txt" For Append As #2
'Write #2, Name, EmpType, Address, Pay, EmpClass
Print #2, Text1.Text
Close #2

End Sub

Private Sub Command2_Click()

End

End Sub




This is the code you I am trying but I am getting an error "INPUT PAST END OF FILE" in the Private sub Form_Load().

And at the line "Input #1, EmployeeDetail(i).Name, EmployeeDetail(i).EmpType, EmployeeDetail(i).Address, EmployeeDetail(i).Pay, EmployeeDetail(i).EmpClass "


please check this out

bye

Reply With Quote
  #14  
Old December 10th, 2003, 01:37 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
usually you get this error when your program has reached the end of the file, and is expecting to read another value. The cause of this is typically that somewh