Click to See Complete Forum and Search --> : text file


al_3asel
08-15-2004, 01:30 AM
HI all,
I'm already started working on asp script which is used in

the script reads a text file likes this:

24255856 362413250265 SWT 1
24255857 362340249418 RTC 1
24255858 362220253704 SWE 1
35723160 785710209979 ASE 0
38623410 766200123783 ALQ 0
38765833 486600 CON 0
44320051 5277467444248130 GADI 0
75441957 487540 CR 0



then writes to another text file



24255856 362413250265 SWT 1
24255857 362340249418 RTC 1
24255858 362220253704 SWE 1
5723160 785710209979 ASE 0
8623410 766200123783 ALQ 0
8765833 486600 CON 0
44320051 5277467444248130 GADI 0
75441957 487540 CR 0


if you focus on it we only remove number 3 in the numbers which start with 3. 35723160 785710209979 ASE 0 -> 5723160 785710209979 ASE 0

I write this vb script

<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile, myFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath("phone.txt"))
set myFile = fso.CreateTextFile("C:\test.txt", true)
set firstchar = objTextFile.Readline(0)

Do While Not objTextFile.AtEndOfStream
if firstchar = '3' then
firstchar = ''
myFile.WriteLine(&objTextFile.ReadLine)& "<BR>" & vbCrLf
Loop

' Close the file.
objTextFile.Close

' Release reference to the text file.
Set objTextFile = Nothing
myFile.Close

' Release reference to the File System Object.
Set objFSO = Nothing
%>



I need your help

buntine
08-15-2004, 07:38 AM
You will have to use double quotes to assign and compare string variables. Otherwise, they will be treated as comments.

To get the firstchar of the line you will have to use some string handling functions.

Dim firstChar
firstChar = Mid(lineFromFile, 0, 1)

Regards.

al_3asel
08-16-2004, 01:24 AM
HI all,
I did but with another problem


<% @Language=VBScript %>
<html>
<body bgcolor="#f4f4f4" TEXT="#000000" >
<font color="#000000">
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile, myFile, firstChar
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
Set objTextFile = objFSO.OpenTextFile(Server.MapPath("phone.txt"))
set myFile = fso.CreateTextFile("C:\Inetpub\wwwroot\wardialer\test.txt", true)
set firstChar = Mid(lineFromFile, 0, 1)


Do While Not objTextFile.AtEndOfStream
if firstChar = "3" then
firstChar = " "
objTextFile.Readline() =objTextFile.Readline()
myFile.WriteLine(objTextFile.ReadLine) & "<BR>" & vbCrLf
end if
Loop

' Close the file.
objTextFile.Close

' Release reference to the text file.
Set objTextFile = Nothing
myFile.Close

' Release reference to the File System Object.
Set objFSO = Nothing
%>
<td align="Center">
<form method=POST >
<Input type="submit" name="write" value="Write now">
</body>
</html>

the error is

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/script.asp, line 14

buntine
08-16-2004, 02:22 AM
Your using the Set keyword to create variables. Unless those methods return objects, you cant use that keyword. Remove Set from line 14 and 15 and try again.

al_3asel
08-16-2004, 02:35 AM
but what about this problem


<% @Language=VBScript %>
<html>
<body bgcolor="#f4f4f4" TEXT="#000000" >
<font color="#000000">
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile, myFile, firstChar
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
objTextFile = objFSO.OpenTextFile(Server.MapPath("phone.txt"))
myFile = fso.CreateTextFile("C:\Inetpub\wwwroot\wardialer\test.txt", true)
firstChar = Mid(lineFromFile, 0, 1)


Do While Not objTextFile.AtEndOfStream
if firstChar = "3" then
firstChar = " "
objTextFile.Readline() =objTextFile.Readline()
myFile.WriteLine(objTextFile.ReadLine) & "<BR>" & vbCrLf
end if
Loop

' Close the file.
objTextFile.Close

' Release reference to the text file.
Set objTextFile = Nothing
myFile.Close

' Release reference to the File System Object.
Set objFSO = Nothing
%>
<td align="Center">
<form method=POST >
<Input type="submit" name="write" value="Write now">
</body>
</html>


the error is

Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method
script.asp, line 13

buntine
08-16-2004, 05:23 AM
Make sure you pay close attention when debugging code. This error can be easily resolved by using the Option Explicit coding methodology.

fso is not an object (its not even a variable). You cannot call the createTextFile() function from an expression which is not an FSO object.

Use this line instead

myFile = objFSO.CreateTextFile("C:\Inetpub\wwwroot\wardialer\test.txt", true)

Also, be aware that the same concept applies for the line below. You are passing a variable named lineFromFile to the Mid() function -- that variable does not exist. You have to create it first.

Regards,
Andrew Buntine.

al_3asel
08-16-2004, 06:10 AM
<% @Language=VBScript %>
<html>
<body bgcolor="#f4f4f4" TEXT="#000000" >
<font color="#000000">
<%
' Declare variables for the File System Object and the File to be accessed.
Dim objFSO, objTextFile, myFile, firstChar, lineFromFile
Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Create an instance of the the File System Object and assign it to objFSO.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open the file
objTextFile = objFSO.OpenTextFile(Server.MapPath("phone.txt"))
myFile = objFSO.CreateTextFile("C:\Inetpub\wwwroot\wardialer\test.txt", true)
firstChar = Mid(lineFromFile, 0, 1)


Do While Not objTextFile.AtEndOfStream
if firstChar = "3" then
firstChar = " "
objTextFile.Readline() =objTextFile.Readline()
myFile.WriteLine(objTextFile.ReadLine) & "<BR>" & vbCrLf
end if
Loop

' Close the file.
objTextFile.Close

' Release reference to the text file.
Set objTextFile = Nothing
myFile.Close

' Release reference to the File System Object.
Set objFSO = Nothing
%>
<td align="Center">
<form method=POST >
<Input type="submit" name="write" value="Write now">
</body>
</html>



this problem occurs:

Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method
/wardialer/script.asp, line 13

al_3asel
08-16-2004, 07:06 AM
quote:
--------------------------------------------------------------------------------

Error Type:
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method
/wardialer/script.asp, line 13

--------------------------------------------------------------------------------

al_3asel
08-17-2004, 12:06 AM
help

how can I resovle this problem.