Hello all,
I am trying to create and appln. where the data/records of individuals are listed inthe list box from a tex file.When the user clicks the particular record..it takes to another form and displays the name and id of the person selected and there is also an textbox where the user just enters some comment..i want those comments to be appended back to the same persons record and also saved to the file back(by over-writing the existing one)..i have tried to code it..but i have a problem here..when i try to append it back...it..replaces the first record of the file and not exactly to the selected line..Please help me..its really urgent...
Hope so i am clear to u.. am attaching my code..please lemme know soon..
mY TEXT FILE FORMAT IS :
JIM 4564656 CALIFORNIA|TOM 2234253 WISCONSIN|CAROL 889832 WASHINGTON
...AND SO ON..
FORM 1:
-------
' Defining the public member to be used in Form2
Public selIndex As Integer
Private Sub Command1_Click()
Dim i As Integer
selIndex = List1.Selected(i)
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
Form2.Show
End If
Next i
End Sub
Private Sub Form_load()
Dim selIndex As Integer
Dim nFileNum As Integer
Dim rep As Integer
Dim sNextLine As String
Dim lLineCount As Integer
' Get a free file number
nFileNum = FreeFile()
' Open Test.txt for input. App.Path returns the path your app is saved in
Open App.Path & "\Test.txt" For Input As FreeFile
sNextLine = Input(LOF(nFileNum), #nFileNum)
Close #(nFileNum)
sText = Split(sNextLine, "|")
List1.Clear
For rep = 0 To UBound(sText)
List1.AddItem sText(rep)
Next
End Sub
FORM2:
--------
Private Sub Command1_Click()
Dim userEnteredVal As String
nameStr = txtName.Text
MsgBox ("name" + nameStr)
childID = txtChildId.Text
MsgBox ("id" + childID)
locStr = txtLocn.Text
MsgBox ("locaiton" + locStr)
addStr = txtAddComment.Text
MsgBox ("add" + addStr)
' Creating the string based on user input
userEnteredVal = nameStr + " " + childID + " " + locStr + " " + addStr
MsgBox ("user" + userEnteredVal)
Dim rep As Integer
Dim str As String
str = ""
' Hiding the form
Form1.Hide
' Setting the new string into the array
'sText(mySelIndex) = userEnteredVal
' Creating the final string to be written to the file
For rep = 0 To UBound(sText)
If (rep = UBound(sText)) Then
MsgBox ("before" + str)
str = str + sText(rep)
MsgBox (str)
Else
str = str + sText(rep) + "|"
MsgBox (str)
End If
Next
MsgBox (" the str is " + str)
' Overwritting the file text
Open App.Path & "\test.txt" For Output As #1
Print #1, str
Close #1
' Clearing the contents of the list
Form1.List1.Clear
' Re-creating the list
For rep = 0 To UBound(sText)
Form1.List1.AddItem sText(rep)
Next
End Sub
Private Sub Form_load()
Dim mySplit() As String
' Getting values from Form1
mySelArr = sText
mySelIndex = Form1.selIndex
' Getting the selected String
mySelStr = Form1.List1.Text
MsgBox ("selected text" + mySelStr)
' Spliting the value based on space
mySplit = Split(mySelStr, " ")
' Getting the name, childid and location string
nameStr = mySplit(0)
MsgBox (nameStr)
childID = mySplit(1)
locStr = mySplit(2)
' Getting the additional data also
If UBound(mySplit) > 3 Then
MsgBox ("I am inside the 4th Element")
addStr = mySplit(3)
End If
' Printing the name
txtName.Text = nameStr
' Printing the Child ID
txtChildId.Text = childID
txtLocn.Text = locStr
txtAddComment.Text = addStr
End Sub
thanks a ton....
Pooja
I am trying to create and appln. where the data/records of individuals are listed inthe list box from a tex file.When the user clicks the particular record..it takes to another form and displays the name and id of the person selected and there is also an textbox where the user just enters some comment..i want those comments to be appended back to the same persons record and also saved to the file back(by over-writing the existing one)..i have tried to code it..but i have a problem here..when i try to append it back...it..replaces the first record of the file and not exactly to the selected line..Please help me..its really urgent...
Hope so i am clear to u.. am attaching my code..please lemme know soon..
mY TEXT FILE FORMAT IS :
JIM 4564656 CALIFORNIA|TOM 2234253 WISCONSIN|CAROL 889832 WASHINGTON
...AND SO ON..
FORM 1:
-------
' Defining the public member to be used in Form2
Public selIndex As Integer
Private Sub Command1_Click()
Dim i As Integer
selIndex = List1.Selected(i)
If List1.ListIndex = -1 Then Exit Sub
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
Form2.Show
End If
Next i
End Sub
Private Sub Form_load()
Dim selIndex As Integer
Dim nFileNum As Integer
Dim rep As Integer
Dim sNextLine As String
Dim lLineCount As Integer
' Get a free file number
nFileNum = FreeFile()
' Open Test.txt for input. App.Path returns the path your app is saved in
Open App.Path & "\Test.txt" For Input As FreeFile
sNextLine = Input(LOF(nFileNum), #nFileNum)
Close #(nFileNum)
sText = Split(sNextLine, "|")
List1.Clear
For rep = 0 To UBound(sText)
List1.AddItem sText(rep)
Next
End Sub
FORM2:
--------
Private Sub Command1_Click()
Dim userEnteredVal As String
nameStr = txtName.Text
MsgBox ("name" + nameStr)
childID = txtChildId.Text
MsgBox ("id" + childID)
locStr = txtLocn.Text
MsgBox ("locaiton" + locStr)
addStr = txtAddComment.Text
MsgBox ("add" + addStr)
' Creating the string based on user input
userEnteredVal = nameStr + " " + childID + " " + locStr + " " + addStr
MsgBox ("user" + userEnteredVal)
Dim rep As Integer
Dim str As String
str = ""
' Hiding the form
Form1.Hide
' Setting the new string into the array
'sText(mySelIndex) = userEnteredVal
' Creating the final string to be written to the file
For rep = 0 To UBound(sText)
If (rep = UBound(sText)) Then
MsgBox ("before" + str)
str = str + sText(rep)
MsgBox (str)
Else
str = str + sText(rep) + "|"
MsgBox (str)
End If
Next
MsgBox (" the str is " + str)
' Overwritting the file text
Open App.Path & "\test.txt" For Output As #1
Print #1, str
Close #1
' Clearing the contents of the list
Form1.List1.Clear
' Re-creating the list
For rep = 0 To UBound(sText)
Form1.List1.AddItem sText(rep)
Next
End Sub
Private Sub Form_load()
Dim mySplit() As String
' Getting values from Form1
mySelArr = sText
mySelIndex = Form1.selIndex
' Getting the selected String
mySelStr = Form1.List1.Text
MsgBox ("selected text" + mySelStr)
' Spliting the value based on space
mySplit = Split(mySelStr, " ")
' Getting the name, childid and location string
nameStr = mySplit(0)
MsgBox (nameStr)
childID = mySplit(1)
locStr = mySplit(2)
' Getting the additional data also
If UBound(mySplit) > 3 Then
MsgBox ("I am inside the 4th Element")
addStr = mySplit(3)
End If
' Printing the name
txtName.Text = nameStr
' Printing the Child ID
txtChildId.Text = childID
txtLocn.Text = locStr
txtAddComment.Text = addStr
End Sub
thanks a ton....
Pooja