Bry Man
03-18-2005, 01:15 AM
Hey
I was wondering if it is possible to modify an online txt file that I have on my website, that is chmoded to 777 so that anyone else who uses my program can edit it as well, i have the following code that I have used in the past to modify a text file on my hard drive and just changed the paths to the online file but it just freezes and dies so somethings going on.
form code
Option Explicit
Private Sub cmdDelete_Click()
Dim I As Integer
For I = 0 To lstNames.ListCount - 1
If lstNames.Selected(I) Then
lstNames.RemoveItem I
End If
Next
Call SaveListToFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Private Sub cmdEnter_Click()
Dim Koc As String
Dim filenum As Long
filenum = FreeFile
Open "c:\Program Files\SS Manager\MemberList.txt" For Append As #filenum
Koc = txtInformation.Text
Print #filenum, Koc
Close #filenum
txtInformation.Text = ""
lblAdded.Caption = Koc & " Was Successfully Added To File"
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Module
Public Function LoadListFromFile(ByRef SourceFile As String, _
ByRef ToFormList As ListBox)
On Error GoTo ErrEvt
Dim TextLine As String, FN As Integer
ToFormList.Clear
FN = FreeFile
Open SourceFile For Input As #FN ' Open file.
Do While Not EOF(FN) ' Loop until end of file.
Line Input #FN, TextLine ' Read line into variable.
If TextLine <> LineToRem Then
ToFormList.AddItem (TextLine)
End If
Loop
Close #FN ' Close file.
Exit Function 'this error handler will skip the nasty problem
'if your text file isnt conformed with an extra linebreak at the end
'to avoid saying INPUT PAST EOF
ErrEvt:
Select Case Err.Number
Case 51
Err.Clear ' just bail out from this
Case Else ' do nothing
End Select
Resume Next
End Function
'============================================
'Outputting list boxes to text files'Call with blnClearList=true to clear the listbox afterwards
Public Function SaveListToFile(ByVal strPrintToFile As String, _
ByRef lstFormList As ListBox, Optional ByVal blnClearList As Boolean = False)
Dim I As Long 'longs are quicker than Integers so I normally use those
Dim FN As Integer
FN = FreeFile
'print each line in the list to a new text file
Open strPrintToFile For Output As #FN
'Add all Items to the opened file
For I = 0 To lstFormList.ListCount - 1
Print #FN, lstFormList.List(I)
Next I
Close #FN 'thats it... your file is updated 'clear the listbox? If blnClearList = True Then lstFormList.Clear
End Function
This loads the text file into a list and you can add and remove names, Also, if anyone knows how to make a list box multi-colomned and how i could load the info into a multi colomned box that would be great too.
I was wondering if it is possible to modify an online txt file that I have on my website, that is chmoded to 777 so that anyone else who uses my program can edit it as well, i have the following code that I have used in the past to modify a text file on my hard drive and just changed the paths to the online file but it just freezes and dies so somethings going on.
form code
Option Explicit
Private Sub cmdDelete_Click()
Dim I As Integer
For I = 0 To lstNames.ListCount - 1
If lstNames.Selected(I) Then
lstNames.RemoveItem I
End If
Next
Call SaveListToFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Private Sub cmdEnter_Click()
Dim Koc As String
Dim filenum As Long
filenum = FreeFile
Open "c:\Program Files\SS Manager\MemberList.txt" For Append As #filenum
Koc = txtInformation.Text
Print #filenum, Koc
Close #filenum
txtInformation.Text = ""
lblAdded.Caption = Koc & " Was Successfully Added To File"
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
Call LoadListFromFile("c:\Program Files\SS Manager\MemberList.txt", lstNames)
End Sub
Module
Public Function LoadListFromFile(ByRef SourceFile As String, _
ByRef ToFormList As ListBox)
On Error GoTo ErrEvt
Dim TextLine As String, FN As Integer
ToFormList.Clear
FN = FreeFile
Open SourceFile For Input As #FN ' Open file.
Do While Not EOF(FN) ' Loop until end of file.
Line Input #FN, TextLine ' Read line into variable.
If TextLine <> LineToRem Then
ToFormList.AddItem (TextLine)
End If
Loop
Close #FN ' Close file.
Exit Function 'this error handler will skip the nasty problem
'if your text file isnt conformed with an extra linebreak at the end
'to avoid saying INPUT PAST EOF
ErrEvt:
Select Case Err.Number
Case 51
Err.Clear ' just bail out from this
Case Else ' do nothing
End Select
Resume Next
End Function
'============================================
'Outputting list boxes to text files'Call with blnClearList=true to clear the listbox afterwards
Public Function SaveListToFile(ByVal strPrintToFile As String, _
ByRef lstFormList As ListBox, Optional ByVal blnClearList As Boolean = False)
Dim I As Long 'longs are quicker than Integers so I normally use those
Dim FN As Integer
FN = FreeFile
'print each line in the list to a new text file
Open strPrintToFile For Output As #FN
'Add all Items to the opened file
For I = 0 To lstFormList.ListCount - 1
Print #FN, lstFormList.List(I)
Next I
Close #FN 'thats it... your file is updated 'clear the listbox? If blnClearList = True Then lstFormList.Clear
End Function
This loads the text file into a list and you can add and remove names, Also, if anyone knows how to make a list box multi-colomned and how i could load the info into a multi colomned box that would be great too.