PDA

View Full Version : Vb help... or at least guide..


Immortal
04-05-03, 10:29 PM
Dim empid(100), empname(100) As String
Dim empsal(100), month(100) As Double
Dim n As Integer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim line, fields() As String
Dim sr As IO.StreamReader = IO.File.OpenText("edata.txt")
Dim i As Integer
n = 0
Do While sr.Peek <> -1
line = sr.ReadLine
fields = line.Split(","c)

empid(n) = fields(0)
empname(n) = fields(1)
empsal(n) = CDbl(fields(2))

lstname.Items.Add(empname(n))
n += 1
Loop

sr.Close()
End Sub

this is what is executed from form load.... this is what happens when I hit the "delete" button

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim pos, i As Integer
Dim response As MsgBoxResult
pos = lstname.SelectedIndex
If pos = -1 Then
Exit Sub
End If

response = MsgBox("Are you sure?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Confirmation")

If response = MsgBoxResult.No Then Exit Sub

For i = pos To n - 1
empid(i) = empid(i + 1)
empname(i) = empname(i + 1)
empsal(i) = empsal(i + 1)
Next

empid(n - 1) = ""
empname(n - 1) = ""
empsal(n - 1) = 0

n = n - 1
lstname.Items.RemoveAt(pos)
lstname.SelectedIndex = 0

Dim sw As IO.StreamWriter = IO.File.CreateText("edata.txt")
sw.WriteLine()
sw.Close()
For i = 0 To n
deletedata(empid(n), empname(n), empsal(n))
Next
End Sub

Here's the deletedata function

Sub deletedata(ByVal a As String, ByVal b As String, ByVal c As Double)
Dim sw As IO.StreamWriter = IO.File.AppendText("edata.txt")
Dim y, x(2) As String
x(0) = a
x(1) = b
x(2) = c
y = Join(x, ",")

sw.WriteLine(y)
sw.Close()
End Sub

Here's what I want to do.. when I choose something from the "lstbox" that I wanna delete.. I delete it then I change the edata.txt ... the place where I get hte info from... how do I make it work?

I just want to press delete and it deletes a particular line of data from edata.txt and rewrite the file so that the line I info I want deleted is not in the edata.txt anymore.......

I don't know how I could put it.. but thanx in advance.. I'll answer any question

Immortal
04-05-03, 10:42 PM
scratch that.. I made it work! WOOOO OOO!