Link to home
Start Free TrialLog in
Avatar of stevenlewis
stevenlewis

asked on

edit a notepad file

OK, I have a file, named daily.dat
it's a list of times
0000AM,Sample Entries,0
0615AM,Sample Entries,0
1145AM,Sample Entries,0
1157AM,Add details here.,0
I can open it and populate my combo box (dropdown)
it reads
0000am
0615am
1145am
1157am
now I want to delete a value (the one highlighted in the dropdown box
and then move the others up
example if I have 0615  in the dropdown box
then the edited notepad file will read
0000AM,Sample Entries,0
1145AM,Sample Entries,0
1157AM,Add details here.,0

this is how I am opening the notepad file (daily.dat)
Private Sub Form_Load()
Dim intCounta As Integer
Dim intColumna As Integer
Dim myFile As Integer
Dim ControlName As ComboBox
Dim data As String
Dim x As Long
Dim PathName As String
Dim mydata As String

mydata = Left(mydata, 6)
PathName = App.Path & "\daily.dat"
                             

                               
    Set ControlName = cboDaily
    mydata = FillCombo(ControlName, PathName)

 
End Sub
Function FillCombo(ComboName As Object, PathName As String)

Dim mydata As String



                             

    Open PathName For Input As #1
      Do While Not EOF(1)
        Line Input #1, mydata
        mydata = Left(mydata, 6)
        ComboName.AddItem mydata
Loop
    cboDaily.ListIndex = 0
Close 1
End Function

TIA again
Steve
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Howard Cantrell
Hi stevenlewis,
There is alot of ways to do  what you are talking about.
One way is to have a ID number at the beginning of each line in your daily.dat
Example : 1,0000AM,Sample Entries,0
               2,0000AM,Sample Entries,0
               3,0000AM,Sample Entries,0
then when you delete a line from your combobox you have a var that is holding the ID number that is to be removed
from your daily.dat.
Now you have to create a new TEMPdaily.dat file to hold the new data.
You then reopen your orignal daily.dat file and read each line into a new TEMPdaily.dat file.
Checking for the ID number. You will then skip over the deleted ID number and read the next line until you are finished (EOFinto  your new TEMPdaily.dat file. Then you can rename your new file back to the orig. file (daily.dat).
Avatar of magnus23
magnus23

HI stevenlewis
You cannot delete line from file. What you have to do is read entire content of a file into a variable, find a string that should be deleted, delete entire line until(including) Carrage return and Line feed chars (const vbCrLf) and rewrite then file.

dim temp as string
Do While Not EOF(1)
        Line Input #1, mydata
        if Left(mydata, 6)<>ComboName.SelectedItem.Text
             temp=temp & vbCrLf & mydata
        End IF
Loop


Now just write temp variable to a file.

Good Luck.
I like a mix of planocz and magnus123 comments.
When i was writing mine i didn't sow others yet :)
Avatar of stevenlewis

ASKER

worked great!
tried the others, but I'm not good enough to get them to work LOL