473,396 Members | 1,760 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,396 software developers and data experts.

Deleting Row from Data File

63
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from the file. How can I do that. I have some code for deleting a row from the table, but it's only deleting the row from the table, and not the entry itself. Please help! Is there a relatively easy way to do this ?

Private Sub cmdAddDelivery_Click()

Open App.Path & "\deliveries.txt" For Append As #11
Write #11, lblAccNum.Caption, txtPName.Text, txtPAddress1.Text & ", " & txtPAddress2.Text & ", " & cboPTown.Text, cboPPrefix.Text & " " & txtPTelephone.Text & ", " & cboPMPrefix.Text & " " & txtPMobile.Text, txtDName.Text, txtDAddress1.Text & ", " & txtDAddress2.Text & ", " & cboDTown.Text, cboDPrefix.Text & " " & txtDTelephone.Text & ", " & cboDMPrefix.Text & " " & txtDMobile.Text, txtWeightOfPackage.Text, txtDeliveryPrice.Text, txtPickupDate.Text, txtDeliveryDate.Text, lblPriorityLevel.Caption

MsgBox "New Delivery has been Added !", vbInformation, "Success!!!"

txtPName.Text = ""
txtPAddress1.Text = ""
txtPAddress2.Text = ""
cboPTown.Text = ""
cboPPrefix.Text = "021"
txtPTelephone.Text = ""
cboPMPrefix.Text = "085"
txtPMobile.Text = ""

txtDName.Text = ""
txtDAddress1.Text = ""
txtDAddress2.Text = ""
cboDTown.Text = ""
cboDPrefix.Text = "021"
txtDTelephone.Text = ""
cboDMPrefix.Text = "085"
txtDMobile.Text = ""
txtWeightOfPackage.Text = ""
txtDeliveryPrice.Text = ""
txtPickupDate.Text = ""
txtDeliveryDate.Text = ""

txtPName.SetFocus

Close #11

End Sub

Private Sub tabAdmin_Click(PreviousTab As Integer)

If tabAdmin.Tab = 1 Then

Open App.Path & "\deliveries.txt" For Input As #12

Dim oldRow As Long
Dim lngRow As Long
Dim lngCol As Long

Dim tRow As Long
Dim tCol As Long

Dim strID As String
Dim strPickupName As String
Dim strPickupAdd As String
Dim strPickupTel As String
Dim strDelName As String
Dim strDelAdd As String
Dim strDelTel As String
Dim strWoP As String
Dim strDelPrice As String
Dim strPickupDate As String
Dim strDelDate As String
Dim strPriority As String
Dim counter As Integer


MSFlexGrid1.Rows = 2

Do Until EOF(12)
Input #12, strID, strPickupName, strPickupAdd, strPickupTel, strDelName, strDelAdd, strDelTel, strWoP, strDelPrice, strPickupDate, strDelDate, strPriority

MSFlexGrid1.TextMatrix(1, 0) = strID
MSFlexGrid1.TextMatrix(1, 1) = strPickupName
MSFlexGrid1.TextMatrix(1, 2) = strPickupAdd
MSFlexGrid1.TextMatrix(1, 3) = strPickupTel
MSFlexGrid1.TextMatrix(1, 4) = strDelName
MSFlexGrid1.TextMatrix(1, 5) = strDelAdd
MSFlexGrid1.TextMatrix(1, 6) = strDelTel
MSFlexGrid1.TextMatrix(1, 7) = strWoP
MSFlexGrid1.TextMatrix(1, 8) = strDelPrice
MSFlexGrid1.TextMatrix(1, 9) = strPickupDate
MSFlexGrid1.TextMatrix(1, 10) = strDelDate
MSFlexGrid1.TextMatrix(1, 11) = strPriority

MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
For lngRow = MSFlexGrid1.Rows - 2 To MSFlexGrid1.Row Step -1
For lngCol = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.TextMatrix(lngRow + 1, lngCol) = MSFlexGrid1.TextMatrix(lngRow, lngCol)
If lngRow = MSFlexGrid1.Row Then
MSFlexGrid1.TextMatrix(lngRow, lngCol) = "" 'Make the current row empty
End If
Next
Next

Loop

End If

Close #12

End Sub
Feb 27 '08 #1
4 1457
VBWheaties
145 100+
My approach would be to write a routine that reads values off the grid into a temp file. Once its done reading values off the grid, save the Temp file as the primary file.
Feb 27 '08 #2
MiziaQ
63
How can I do that ? Could you please give a coded example ? Thanks
Feb 27 '08 #3
VBWheaties
145 100+
How can I do that ? Could you please give a coded example ? Thanks
It's real easy to do this.
I see you already know how to reference TextMatrix and you know how to open/close files. So basically

1. Create a sub (call it WriteGridToFile or something)
2. Open any arbitrary file giving a temp file name. Open for writing (or output)
2. In a loop, enumerate the rows of the grid.
3. For each row, read the TextMatrix values into variables, or simply write to the file directly using TextMatrix. Your choice.
4. Once done looping the grid rows, writing the values to file, close the file.
5. Save the Temp file as your primary source file, overwriting the primary file.
6. Call WriteGridToFile whenever you need to persist (save) changes.

Let me know if you need help on anything else.
Feb 27 '08 #4
MiziaQ
63
Hey :) Thanks a lot for your help. I have one last thing to do, and that is to replace the files, which I don't know how to do. Once again, thanks !
Feb 27 '08 #5

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

Similar topics

1
by: John Baker | last post by:
Hi: I am working with an XLS file, andhave Access 2000. When I try and clear the xlf file (so that xls can use it for additional data), I get an error message: "Deleting data in a linked...
13
by: Bob Darlington | last post by:
I have a repair and backup database routine which runs when a user closes down my application. It works fine in my development machine, but breaks on a client's at the following line: If...
3
by: kris.dorey | last post by:
Hi, Ive got the following code which seems ok but when the user runs the function for a second time I get an error message stating that the mdb is in use by another process. There is still an...
2
by: melanieab | last post by:
Hi, I'm deleting nodes in my xml file, and it does seem to work, but then when I later reload the file and make an xmlNodeList, the nodelist count still includes the deleted nodes yet the file...
2
by: GMK | last post by:
Dear all in my asp.net application i have a text file that is installed with my application on the server. this text file is filled with data through a web interface in my application. i need to...
8
by: shandra | last post by:
I have a file I need to delete or truncate. I tried using the KILL command in VB6. I tried using the file.delete command in VB.net. I tried manually deleting, renaming, and copying over the...
2
by: SiouxieQ | last post by:
Hi there, I'm using the code below to try to delete a name from a list of names in a file. Unfortunately it doesn't quite do what I want it to. Instead of looking for the name in the...
0
by: John Yale | last post by:
I am using an XmlDocument to save some data. Periodically I add new data and save the XmlDocument to a file: Me.fXmlDoc.Save(Me.fFilename) When I have added all the data I need, I want to move...
2
by: emphyrio | last post by:
Hi, I am new to programming in vb. net. I have this problem: I created a form with a datagrid. I can add records and then save them to a XML file, using this code on the click event of a button...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
0
Oralloy
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,...
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...
0
agi2029
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,...

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.