hello please help me on this. i have cmdadd_click()..when i click the button add,the data will display on the flexgrid at the sametime it write on the notepad..my problem is that i don't know how to make code on cmddelete_click().i want to delete the data i added on the notepad or one record of person.can you please help me on this hoping for your positive responds...this is sequential..here is my code..

Private Sub cmdadd_Click()
    If Trim(txtLname.Text) < "A" Then
        MsgBox "Invalid , in your last name"
        txtLname.SelStart = 0
        txtLname.SetFocus
        txtLname.SelLength = Len(txtLname.Text)
        Exit Sub
        End If
    
    If Trim(txtFname.Text) < "A" Then
        MsgBox "invalid, in the firstname"
        txtFname.SelStart = 0
        txtFname.SetFocus
        txtFname.SelLength = Len(txtFname.Text)
        Exit Sub
        End If
  
    If Trim(txtMname.Text) < "A" Then
        MsgBox "Invalid,middle name"
        txtMname.SelStart = 0
        txtMname.SetFocus
        txtMname.SelLength = Len(txtMname.Text)
        Exit Sub
      
    ElseIf Len(Trim(txtMname.Text)) <> 1 Then
      MsgBox "Middle inital only"
      txtMname.SelStart = 0
      txtMname.SetFocus
      txtMname.SelLength = Len(txtMname.Text)
      Exit Sub
      End If

      If Trim(txtMname.Text) = "" Then
             MsgBox "you have not inputed Middle name", vbInformation
             txtMname.SelStart = 0
             txtMname.SetFocus
             txtMname.SelLength = Len(txtMname.Text)
             Exit Sub
      
         End If
  
   
         If (txtaddres.Text) = "" Then
             MsgBox "you have not inputed Addres", vbInformation
             txtaddres.SelStart = 0
             txtaddres.SetFocus
             txtaddres.SelLength = Len(txtaddres.Text)
             Exit Sub
             End If
            
 If (Val(txtAge.Text)) <= 0 Then
     MsgBox "that is not an age", vbCritical
     txtAge.SelStart = 0
     txtAge.SetFocus
     txtAge.SelLength = Len(txtAge.Text)
     Exit Sub
     
  ElseIf (Val(txtAge.Text)) < 18 Or (Val(txtAge.Text)) > 90 Then
     MsgBox "Invalid input Your not qualified voter", vbCritical
     txtAge.SelStart = 0
     txtAge.SetFocus
     txtAge.SelLength = Len(txtAge.Text)
     Exit Sub
     End If
    
    pn = Trim(txtc.Text) + "-" + Trim(txtPn.Text)
    adress = Trim(Me.lbladdress.Caption)
    vidno = Trim(lblvidno.Caption)
    last = Trim(txtLname.Text)
    first = Trim(txtFname.Text)
    middle = Trim(Me.txtMname)
    address = Trim(Me.txtaddres)
    age = Val(txtAge.Text)

 grd.TextMatrix(grd.Rows - 1, 0) = vidno
 grd.TextMatrix(grd.Rows - 1, 1) = pn
 grd.TextMatrix(grd.Rows - 1, 2) = last
 grd.TextMatrix(grd.Rows - 1, 3) = first
 grd.TextMatrix(grd.Rows - 1, 4) = middle
 grd.TextMatrix(grd.Rows - 1, 5) = address
 grd.TextMatrix(grd.Rows - 1, 6) = age
 
 grd.Rows = grd.Rows + 1
 delete
 
 gFnum = FreeFile
 Open "D:\voters.dat" For Append As #gFnum
 Write #gFnum, pn, adress, vidno, last, first, middle, address, age
 Close #gFnum
 
 vlno = vlno + 1
 
 gFnum1 = FreeFile
 Open "D:\votersid.dat" For Output As #gFnum1
 Write #gFnum1, vlno
 Close #gFnum1
 
 lblvidno = lblvidno + 1
 lblvidno.Caption = Format(lblvidno, "0000")

  generator
  
End Sub

Private Sub cmdExit_Click()
'Form2.Show
End
End Sub


Private Sub Form_Load()

header
generator

gFnum1 = FreeFile
Open "D:\votersid.dat" For Input As #gFnum1
Input #gFnum1, vlno

 lblvidno = 1
 lblvidno.Caption = Format(vlno, "0000")


Close #gFnum1
    
     
End Sub
Public Sub generator()
 N = Int(Rnd(1) * 10)
 
If N = 1 Or N = 2 Then
    txtc.Text = "A"
    txtPn.Text = "342"
    lbladdress = "Singapore"
    Exit Sub
ElseIf N = 3 Or N = 4 Then
    txtc.Text = "B"
    txtPn.Text = "256"
    lbladdress = "China"
    Exit Sub
ElseIf N = 5 Or N = 6 Then
    txtc.Text = "C"
    txtPn.Text = "245"
    lbladdress = "United States"
    Exit Sub
ElseIf N = 7 Or N = 8 Then
    txtc.Text = "D"
    txtPn.Text = "314"
    lbladdress = "California"
    Exit Sub
Else
    txtc.Text = "E"
    txtPn.Text = "344"
    lbladdress = "Korea"
    Exit Sub

End If
End Sub
Public Sub voter()
   lblvidno = 1
   lblvidno.Caption = Format(lblvidno, "0000")


End Sub

Public Sub delete()

 Me.txtLname = ""
 Me.txtFname = ""
 Me.txtMname = ""
 Me.txtaddres = ""
 Me.txtAge = ""
End Sub

Edited 6 Years Ago by __avd: Improved formatting and added [code] tags. Encase your code in: [code] and [/code] tags.

i think you have to open a new file simultaneously, start reading from first file and writing in second file ignoring the record you want to delete, then after closing both files you can delete first file & rename the second file.

i think this is the bad part of sequential storage system.

you can switch to database system like MS Jet(MS access)

Hi

Public Sub delete() 

Me.txtLname.text = ""
Me.txtFname.text = ""
Me.txtMname.text = ""
Me.txtaddres.text = ""
Me.txtAge.text = ""
End Sub

Look I am not sure but yes you can try this code and whatever the result is just show it up here.

This article has been dead for over six months. Start a new discussion instead.