473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Converted code

I have a VB6 program that runs as an app, that I want to both convert it
to vb.net, and run it as a service on the server.

I have been able to create the service, and what I did was to open the
vb6 document and convert it into a vb.net program. Once I did that, the
routine "check_for_file" I yanked out & put into my service program.

The program though - doesn't work like the existing VB6 one does.
I've debugged the service as it runs, and it appears to read in the HTML
file, but dies on this line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) & Chr(34) &
">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x, 10, 2) & "</A> "

that is located in the GOTMONTH: section of the code.

What happens is that it will attempt to write the file (when I open it I
get a sharing violation message), but it has only 1 byte in the file.
It must run again to put 06031201 into that file, but that's all that it
ever writes. Debugging the process, it'll step through and appear to
read everything like it should, but when it's into that section, it just
dies. No error message or anything in the logfile that gives me any
meaningful info.

Code follows.

Any help appreciated....

BC
Private Sub check_for_file()
Dim j As Short
Dim RepDate As String
Dim RepTitle As String
Dim RunDate As String
Dim OFile As String
Dim z As String
Dim OutFile As Short
Dim AnchSeq As Short
Dim ReptMonth As String
Dim RunDay As String
Dim RunMon As String
Dim RunYear As String
Dim x As String
Dim anchor As Array

On Error GoTo FileNotThere
If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
FileNotThere:
On Error GoTo 0
GoTo ExitCheck

FoundHim:

FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
x = LineInput(1)
x = LineInput(1)
RunYear = Mid(x, 17, 2)
RunMon = Mid(x, 11, 2)
RunDay = Mid(x, 14, 2)
x = LineInput(1)
ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
FileClose()

On Error GoTo CmonthNotFound
FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
x = LineInput(1)
FileClose()
GoTo GotMonth
CmonthNotFound:
On Error GoTo 0
x = "JANUARY "
GotMonth:
On Error GoTo 0
If ReptMonth = VB.Left(x, 9) Then
AnchSeq = 2
FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
PrintLine(2, x)
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
GoTo GetTheRest
End If
Loop
GetTheRest:
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
End If
PrintLine(2, x)
Loop
FileClose()
Else
FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Output)
PrintLine(4, ReptMonth)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
PrintLine(2, "</BODY>")
PrintLine(2, "</HTML>")
FileClose()
End If

FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
PrintLine(3, "<HTML>")
PrintLine(3, " ")
PrintLine(3, "<HEAD>")
PrintLine(3, " ")
PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" & Chr(34) &
" CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) & "
CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
PrintLine(3, "</HEAD>")
PrintLine(3, " ")
PrintLine(3, "<BODY>")
PrintLine(3, " ")
PrintLine(3, "<H1><CENTER>My Main Company, Inc.</CENTER></H1>")
PrintLine(3, " ")
PrintLine(3, "<H3><CENTER>Daily Sales Information Reports for "
& ReptMonth & " 20" & RunYear & "</CENTER></H3>")
FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
RunDay, OpenMode.Output)
OutFile = 0
Loop1:
If EOF(1) Then GoTo EndThis
z = LineInput(1)
PrintLine(4, z)

If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") > 0 Then

If OutFile > 0 Then FileClose(2)
OutFile = OutFile + 1
OFile = RunYear & RunMon & RunDay & VB.Right("00" &
Mid(Str(OutFile), 2), 2) & ".txt"
FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RunDate = Mid(z, 11, 8)
RepTitle = Trim(Mid(z, 20, 120))
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
' Print #2, z$
PrintLine(3, " ")
PrintLine(3, "<P>")
If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
anchor(1) = "Move directly to day <A HREF=" & Chr(34) &
"#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
For j = 1 To AnchSeq - 1 Step 10
Print(3, anchor(j) & anchor(j + 1) & anchor(j + 2)
& anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6) &
anchor(j + 7) & anchor(j + 8) & anchor(j + 9))
Next j
PrintLine(3, " ")
PrintLine(3, "<P>")
PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile, 6) &
Chr(34) & "></A>")
End If
PrintLine(3, "<A HREF=" & Chr(34) &
"http://www.myserver.com/reports/" & OFile & Chr(34) & ">" & RepTitle &
" - " & RepDate & " (" & RunDate & ")" & "</A>")
End If
If z <> "-----------------------------" And z <>
"=============================" Then
If VB.Left(z, 50) = New String("=", 50) Then z = New
String("=", 140)
PrintLine(2, z)
End If
GoTo Loop1
EndThis:
PrintLine(3, "<P>")
FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
Do While Not EOF(5)
x = LineInput(5)
PrintLine(3, x)
Loop
FileClose()
For j = 1 To 100
anchor(j) = ""
Next j
Kill("c:\000Glen\DAORDSHP")
Kill("c:\000Glen\dasis.htm")

'Dim oFile As System.IO.File
'Dim oWrite As System.IO.StreamWriter
'oWrite = oFile.CreateText("C:\sample.txt")
'OpenText()
'Dim fs As New Scripting.FileSystemObject
Dim iLine As String
Dim oLine As String
Dim fs As System.IO.File
Dim fs2 As System.IO.File
'Dim f As Scripting.File
Dim f As System.IO.StreamReader
Dim f2 As System.IO.StreamWriter
f = fs.OpenText("c:\000Glen\dasis6.htm")
f2 = fs2.CreateText("c:\000Glen\dasis.htm")
While f.Peek <> -1
iLine = f.ReadLine()
f2.WriteLine(iLine)
End While

f.Close()
f2.Close()

ExitCheck:

End Sub

Mar 13 '06 #1
5 1449
Blasting Cap wrote:
I have a VB6 program that runs as an app, that I want to both convert it
to vb.net, and run it as a service on the server.

I have been able to create the service, and what I did was to open the
vb6 document and convert it into a vb.net program. Once I did that, the
routine "check_for_file" I yanked out & put into my service program.

The program though - doesn't work like the existing VB6 one does.
I've debugged the service as it runs, and it appears to read in the HTML
file, but dies on this line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) & Chr(34) &
">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x, 10, 2) & "</A> "

that is located in the GOTMONTH: section of the code.

What happens is that it will attempt to write the file (when I open it I
get a sharing violation message), but it has only 1 byte in the file. It
must run again to put 06031201 into that file, but that's all that it
ever writes. Debugging the process, it'll step through and appear to
read everything like it should, but when it's into that section, it just
dies. No error message or anything in the logfile that gives me any
meaningful info.

Code follows.

Any help appreciated....

BC
Private Sub check_for_file()
Dim j As Short
Dim RepDate As String
Dim RepTitle As String
Dim RunDate As String
Dim OFile As String
Dim z As String
Dim OutFile As Short
Dim AnchSeq As Short
Dim ReptMonth As String
Dim RunDay As String
Dim RunMon As String
Dim RunYear As String
Dim x As String
Dim anchor As Array

On Error GoTo FileNotThere
If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
FileNotThere:
On Error GoTo 0
GoTo ExitCheck

FoundHim:

FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
x = LineInput(1)
x = LineInput(1)
RunYear = Mid(x, 17, 2)
RunMon = Mid(x, 11, 2)
RunDay = Mid(x, 14, 2)
x = LineInput(1)
ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
FileClose()

On Error GoTo CmonthNotFound
FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
x = LineInput(1)
FileClose()
GoTo GotMonth
CmonthNotFound:
On Error GoTo 0
x = "JANUARY "
GotMonth:
On Error GoTo 0
If ReptMonth = VB.Left(x, 9) Then
AnchSeq = 2
FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
PrintLine(2, x)
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
GoTo GetTheRest
End If
Loop
GetTheRest:
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
End If
PrintLine(2, x)
Loop
FileClose()
Else
FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Output)
PrintLine(4, ReptMonth)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
PrintLine(2, "</BODY>")
PrintLine(2, "</HTML>")
FileClose()
End If

FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
PrintLine(3, "<HTML>")
PrintLine(3, " ")
PrintLine(3, "<HEAD>")
PrintLine(3, " ")
PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" & Chr(34) & "
CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) & "
CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
PrintLine(3, "</HEAD>")
PrintLine(3, " ")
PrintLine(3, "<BODY>")
PrintLine(3, " ")
PrintLine(3, "<H1><CENTER>My Main Company, Inc.</CENTER></H1>")
PrintLine(3, " ")
PrintLine(3, "<H3><CENTER>Daily Sales Information Reports for "
& ReptMonth & " 20" & RunYear & "</CENTER></H3>")
FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
RunDay, OpenMode.Output)
OutFile = 0
Loop1:
If EOF(1) Then GoTo EndThis
z = LineInput(1)
PrintLine(4, z)

If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") > 0 Then

If OutFile > 0 Then FileClose(2)
OutFile = OutFile + 1
OFile = RunYear & RunMon & RunDay & VB.Right("00" &
Mid(Str(OutFile), 2), 2) & ".txt"
FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RunDate = Mid(z, 11, 8)
RepTitle = Trim(Mid(z, 20, 120))
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
' Print #2, z$
PrintLine(3, " ")
PrintLine(3, "<P>")
If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
anchor(1) = "Move directly to day <A HREF=" & Chr(34) &
"#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
For j = 1 To AnchSeq - 1 Step 10
Print(3, anchor(j) & anchor(j + 1) & anchor(j + 2) &
anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6) & anchor(j
+ 7) & anchor(j + 8) & anchor(j + 9))
Next j
PrintLine(3, " ")
PrintLine(3, "<P>")
PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile, 6) &
Chr(34) & "></A>")
End If
PrintLine(3, "<A HREF=" & Chr(34) &
"http://www.myserver.com/reports/" & OFile & Chr(34) & ">" & RepTitle &
" - " & RepDate & " (" & RunDate & ")" & "</A>")
End If
If z <> "-----------------------------" And z <>
"=============================" Then
If VB.Left(z, 50) = New String("=", 50) Then z = New
String("=", 140)
PrintLine(2, z)
End If
GoTo Loop1
EndThis:
PrintLine(3, "<P>")
FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
Do While Not EOF(5)
x = LineInput(5)
PrintLine(3, x)
Loop
FileClose()
For j = 1 To 100
anchor(j) = ""
Next j
Kill("c:\000Glen\DAORDSHP")
Kill("c:\000Glen\dasis.htm")

'Dim oFile As System.IO.File
'Dim oWrite As System.IO.StreamWriter
'oWrite = oFile.CreateText("C:\sample.txt")
'OpenText()
'Dim fs As New Scripting.FileSystemObject
Dim iLine As String
Dim oLine As String
Dim fs As System.IO.File
Dim fs2 As System.IO.File
'Dim f As Scripting.File
Dim f As System.IO.StreamReader
Dim f2 As System.IO.StreamWriter
f = fs.OpenText("c:\000Glen\dasis6.htm")
f2 = fs2.CreateText("c:\000Glen\dasis.htm")
While f.Peek <> -1
iLine = f.ReadLine()
f2.WriteLine(iLine)
End While

f.Close()
f2.Close()

ExitCheck:

End Sub


Try running the program as a console or windows form application. Get
that working first then paste it into your service. This will help you
figure out if there is a problem on how you are running the service or
your function.

How is your Check_for_file function called in your service? When is it
triggered? Are you starting a new thread in the service to run the
check_for_file?

Chris
Mar 13 '06 #2
Chris wrote:
Blasting Cap wrote:
I have a VB6 program that runs as an app, that I want to both convert
it to vb.net, and run it as a service on the server.

I have been able to create the service, and what I did was to open the
vb6 document and convert it into a vb.net program. Once I did that,
the routine "check_for_file" I yanked out & put into my service program.

The program though - doesn't work like the existing VB6 one does.
I've debugged the service as it runs, and it appears to read in the
HTML file, but dies on this line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) & Chr(34)
& ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x, 10, 2) &
"</A> "

that is located in the GOTMONTH: section of the code.

What happens is that it will attempt to write the file (when I open it
I get a sharing violation message), but it has only 1 byte in the
file. It must run again to put 06031201 into that file, but that's all
that it ever writes. Debugging the process, it'll step through and
appear to read everything like it should, but when it's into that
section, it just dies. No error message or anything in the logfile
that gives me any meaningful info.

Code follows.

Any help appreciated....

BC
Private Sub check_for_file()
Dim j As Short
Dim RepDate As String
Dim RepTitle As String
Dim RunDate As String
Dim OFile As String
Dim z As String
Dim OutFile As Short
Dim AnchSeq As Short
Dim ReptMonth As String
Dim RunDay As String
Dim RunMon As String
Dim RunYear As String
Dim x As String
Dim anchor As Array

On Error GoTo FileNotThere
If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
FileNotThere:
On Error GoTo 0
GoTo ExitCheck

FoundHim:

FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
x = LineInput(1)
x = LineInput(1)
RunYear = Mid(x, 17, 2)
RunMon = Mid(x, 11, 2)
RunDay = Mid(x, 14, 2)
x = LineInput(1)
ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
FileClose()

On Error GoTo CmonthNotFound
FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
x = LineInput(1)
FileClose()
GoTo GotMonth
CmonthNotFound:
On Error GoTo 0
x = "JANUARY "
GotMonth:
On Error GoTo 0
If ReptMonth = VB.Left(x, 9) Then
AnchSeq = 2
FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
PrintLine(2, x)
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
GoTo GetTheRest
End If
Loop
GetTheRest:
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
End If
PrintLine(2, x)
Loop
FileClose()
Else
FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt",
OpenMode.Output)
PrintLine(4, ReptMonth)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
PrintLine(2, "</BODY>")
PrintLine(2, "</HTML>")
FileClose()
End If

FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
PrintLine(3, "<HTML>")
PrintLine(3, " ")
PrintLine(3, "<HEAD>")
PrintLine(3, " ")
PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" & Chr(34) &
" CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) & "
CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
PrintLine(3, "</HEAD>")
PrintLine(3, " ")
PrintLine(3, "<BODY>")
PrintLine(3, " ")
PrintLine(3, "<H1><CENTER>My Main Company, Inc.</CENTER></H1>")
PrintLine(3, " ")
PrintLine(3, "<H3><CENTER>Daily Sales Information Reports for
" & ReptMonth & " 20" & RunYear & "</CENTER></H3>")
FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
RunDay, OpenMode.Output)
OutFile = 0
Loop1:
If EOF(1) Then GoTo EndThis
z = LineInput(1)
PrintLine(4, z)

If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") > 0
Then

If OutFile > 0 Then FileClose(2)
OutFile = OutFile + 1
OFile = RunYear & RunMon & RunDay & VB.Right("00" &
Mid(Str(OutFile), 2), 2) & ".txt"
FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RunDate = Mid(z, 11, 8)
RepTitle = Trim(Mid(z, 20, 120))
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
' Print #2, z$
PrintLine(3, " ")
PrintLine(3, "<P>")
If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
anchor(1) = "Move directly to day <A HREF=" & Chr(34)
& "#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
For j = 1 To AnchSeq - 1 Step 10
Print(3, anchor(j) & anchor(j + 1) & anchor(j + 2)
& anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6) &
anchor(j + 7) & anchor(j + 8) & anchor(j + 9))
Next j
PrintLine(3, " ")
PrintLine(3, "<P>")
PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile, 6)
& Chr(34) & "></A>")
End If
PrintLine(3, "<A HREF=" & Chr(34) &
"http://www.myserver.com/reports/" & OFile & Chr(34) & ">" & RepTitle
& " - " & RepDate & " (" & RunDate & ")" & "</A>")
End If
If z <> "-----------------------------" And z <>
"=============================" Then
If VB.Left(z, 50) = New String("=", 50) Then z = New
String("=", 140)
PrintLine(2, z)
End If
GoTo Loop1
EndThis:
PrintLine(3, "<P>")
FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
Do While Not EOF(5)
x = LineInput(5)
PrintLine(3, x)
Loop
FileClose()
For j = 1 To 100
anchor(j) = ""
Next j
Kill("c:\000Glen\DAORDSHP")
Kill("c:\000Glen\dasis.htm")

'Dim oFile As System.IO.File
'Dim oWrite As System.IO.StreamWriter
'oWrite = oFile.CreateText("C:\sample.txt")
'OpenText()
'Dim fs As New Scripting.FileSystemObject
Dim iLine As String
Dim oLine As String
Dim fs As System.IO.File
Dim fs2 As System.IO.File
'Dim f As Scripting.File
Dim f As System.IO.StreamReader
Dim f2 As System.IO.StreamWriter
f = fs.OpenText("c:\000Glen\dasis6.htm")
f2 = fs2.CreateText("c:\000Glen\dasis.htm")
While f.Peek <> -1
iLine = f.ReadLine()
f2.WriteLine(iLine)
End While

f.Close()
f2.Close()

ExitCheck:

End Sub


Try running the program as a console or windows form application. Get
that working first then paste it into your service. This will help you
figure out if there is a problem on how you are running the service or
your function.

How is your Check_for_file function called in your service? When is it
triggered? Are you starting a new thread in the service to run the
check_for_file?

Chris

Here's where I am checking:

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog ' create a new event log
' Check if the the Event Log Exists
If Not MyLog.SourceExists("mycompany Daily") Then
MyLog.CreateEventSource("mycompanyDaily", "mycompany
Daily") ' Create Log
End If

check_for_file()
MyLog.Source = "mycompanyDaily"
' Write to the Log
MyLog.WriteEntry("mycompany Daily Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)

End Sub
The OnStart/OnStop events are:

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should
set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
Timer1.Enabled = False
End Sub

This stuff would work, but all I had it doing originally was to write
events at a particular interval.

The timer is set for 480000 ticks, which should be around 5-8 minutes or
so.

Re your last question - I do not know if I am or not.

I will though, take a look at running the converted app to see what's
going on.

BC
Mar 13 '06 #3
Blasting Cap wrote:
Chris wrote:
Blasting Cap wrote:
I have a VB6 program that runs as an app, that I want to both convert
it to vb.net, and run it as a service on the server.

I have been able to create the service, and what I did was to open
the vb6 document and convert it into a vb.net program. Once I did
that, the routine "check_for_file" I yanked out & put into my service
program.

The program though - doesn't work like the existing VB6 one does.
I've debugged the service as it runs, and it appears to read in the
HTML file, but dies on this line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) &
Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x,
10, 2) & "</A> "

that is located in the GOTMONTH: section of the code.

What happens is that it will attempt to write the file (when I open
it I get a sharing violation message), but it has only 1 byte in the
file. It must run again to put 06031201 into that file, but that's
all that it ever writes. Debugging the process, it'll step through
and appear to read everything like it should, but when it's into that
section, it just dies. No error message or anything in the logfile
that gives me any meaningful info.

Code follows.

Any help appreciated....

BC
Private Sub check_for_file()
Dim j As Short
Dim RepDate As String
Dim RepTitle As String
Dim RunDate As String
Dim OFile As String
Dim z As String
Dim OutFile As Short
Dim AnchSeq As Short
Dim ReptMonth As String
Dim RunDay As String
Dim RunMon As String
Dim RunYear As String
Dim x As String
Dim anchor As Array

On Error GoTo FileNotThere
If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
FileNotThere:
On Error GoTo 0
GoTo ExitCheck

FoundHim:

FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
x = LineInput(1)
x = LineInput(1)
RunYear = Mid(x, 17, 2)
RunMon = Mid(x, 11, 2)
RunDay = Mid(x, 14, 2)
x = LineInput(1)
ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
FileClose()

On Error GoTo CmonthNotFound
FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
x = LineInput(1)
FileClose()
GoTo GotMonth
CmonthNotFound:
On Error GoTo 0
x = "JANUARY "
GotMonth:
On Error GoTo 0
If ReptMonth = VB.Left(x, 9) Then
AnchSeq = 2
FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
PrintLine(2, x)
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
GoTo GetTheRest
End If
Loop
GetTheRest:
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) &
"/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
End If
PrintLine(2, x)
Loop
FileClose()
Else
FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt",
OpenMode.Output)
PrintLine(4, ReptMonth)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
PrintLine(2, "</BODY>")
PrintLine(2, "</HTML>")
FileClose()
End If

FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
PrintLine(3, "<HTML>")
PrintLine(3, " ")
PrintLine(3, "<HEAD>")
PrintLine(3, " ")
PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" & Chr(34)
& " CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) & "
CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
PrintLine(3, "</HEAD>")
PrintLine(3, " ")
PrintLine(3, "<BODY>")
PrintLine(3, " ")
PrintLine(3, "<H1><CENTER>My Main Company, Inc.</CENTER></H1>")
PrintLine(3, " ")
PrintLine(3, "<H3><CENTER>Daily Sales Information Reports for
" & ReptMonth & " 20" & RunYear & "</CENTER></H3>")
FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
RunDay, OpenMode.Output)
OutFile = 0
Loop1:
If EOF(1) Then GoTo EndThis
z = LineInput(1)
PrintLine(4, z)

If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") > 0
Then

If OutFile > 0 Then FileClose(2)
OutFile = OutFile + 1
OFile = RunYear & RunMon & RunDay & VB.Right("00" &
Mid(Str(OutFile), 2), 2) & ".txt"
FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RunDate = Mid(z, 11, 8)
RepTitle = Trim(Mid(z, 20, 120))
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
' Print #2, z$
PrintLine(3, " ")
PrintLine(3, "<P>")
If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
anchor(1) = "Move directly to day <A HREF=" & Chr(34)
& "#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
For j = 1 To AnchSeq - 1 Step 10
Print(3, anchor(j) & anchor(j + 1) & anchor(j +
2) & anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6) &
anchor(j + 7) & anchor(j + 8) & anchor(j + 9))
Next j
PrintLine(3, " ")
PrintLine(3, "<P>")
PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile, 6)
& Chr(34) & "></A>")
End If
PrintLine(3, "<A HREF=" & Chr(34) &
"http://www.myserver.com/reports/" & OFile & Chr(34) & ">" & RepTitle
& " - " & RepDate & " (" & RunDate & ")" & "</A>")
End If
If z <> "-----------------------------" And z <>
"=============================" Then
If VB.Left(z, 50) = New String("=", 50) Then z = New
String("=", 140)
PrintLine(2, z)
End If
GoTo Loop1
EndThis:
PrintLine(3, "<P>")
FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
Do While Not EOF(5)
x = LineInput(5)
PrintLine(3, x)
Loop
FileClose()
For j = 1 To 100
anchor(j) = ""
Next j
Kill("c:\000Glen\DAORDSHP")
Kill("c:\000Glen\dasis.htm")

'Dim oFile As System.IO.File
'Dim oWrite As System.IO.StreamWriter
'oWrite = oFile.CreateText("C:\sample.txt")
'OpenText()
'Dim fs As New Scripting.FileSystemObject
Dim iLine As String
Dim oLine As String
Dim fs As System.IO.File
Dim fs2 As System.IO.File
'Dim f As Scripting.File
Dim f As System.IO.StreamReader
Dim f2 As System.IO.StreamWriter
f = fs.OpenText("c:\000Glen\dasis6.htm")
f2 = fs2.CreateText("c:\000Glen\dasis.htm")
While f.Peek <> -1
iLine = f.ReadLine()
f2.WriteLine(iLine)
End While

f.Close()
f2.Close()

ExitCheck:

End Sub


Try running the program as a console or windows form application. Get
that working first then paste it into your service. This will help
you figure out if there is a problem on how you are running the
service or your function.

How is your Check_for_file function called in your service? When is
it triggered? Are you starting a new thread in the service to run the
check_for_file?

Chris


Here's where I am checking:

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog ' create a new event log
' Check if the the Event Log Exists
If Not MyLog.SourceExists("mycompany Daily") Then
MyLog.CreateEventSource("mycompanyDaily", "mycompany Daily")
' Create Log
End If

check_for_file()
MyLog.Source = "mycompanyDaily"
' Write to the Log
MyLog.WriteEntry("mycompany Daily Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)

End Sub
The OnStart/OnStop events are:

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should
set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
Timer1.Enabled = False
End Sub

This stuff would work, but all I had it doing originally was to write
events at a particular interval.

The timer is set for 480000 ticks, which should be around 5-8 minutes or
so.

Re your last question - I do not know if I am or not.

I will though, take a look at running the converted app to see what's
going on.

BC


As a general rule you should not do procssing inside the service thread,
which is what you are doing. I have always read that you should start a
new thread inside your timer_elapsed event and have the worker thread do
the work.

Someone smarter than me might want to comment on this issue.

Chris
Mar 13 '06 #4
The code in the app keeps blowing on the same line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) & Chr(34) &
">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x, 10, 2) & "</A> "

It says that anchor(anchseq) is null.

It's not defined in the converted app, but I defined it as an array and
an arraylist by me outside of that, but it gives the same message each
time.

Any ideas?

BC

Chris wrote:
Blasting Cap wrote:
Chris wrote:
Blasting Cap wrote:

I have a VB6 program that runs as an app, that I want to both
convert it to vb.net, and run it as a service on the server.

I have been able to create the service, and what I did was to open
the vb6 document and convert it into a vb.net program. Once I did
that, the routine "check_for_file" I yanked out & put into my
service program.

The program though - doesn't work like the existing VB6 one does.
I've debugged the service as it runs, and it appears to read in the
HTML file, but dies on this line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) &
Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x,
10, 2) & "</A> "

that is located in the GOTMONTH: section of the code.

What happens is that it will attempt to write the file (when I open
it I get a sharing violation message), but it has only 1 byte in the
file. It must run again to put 06031201 into that file, but that's
all that it ever writes. Debugging the process, it'll step through
and appear to read everything like it should, but when it's into
that section, it just dies. No error message or anything in the
logfile that gives me any meaningful info.

Code follows.

Any help appreciated....

BC
Private Sub check_for_file()
Dim j As Short
Dim RepDate As String
Dim RepTitle As String
Dim RunDate As String
Dim OFile As String
Dim z As String
Dim OutFile As Short
Dim AnchSeq As Short
Dim ReptMonth As String
Dim RunDay As String
Dim RunMon As String
Dim RunYear As String
Dim x As String
Dim anchor As Array

On Error GoTo FileNotThere
If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
FileNotThere:
On Error GoTo 0
GoTo ExitCheck

FoundHim:

FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
x = LineInput(1)
x = LineInput(1)
RunYear = Mid(x, 17, 2)
RunMon = Mid(x, 11, 2)
RunDay = Mid(x, 14, 2)
x = LineInput(1)
ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
FileClose()

On Error GoTo CmonthNotFound
FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
x = LineInput(1)
FileClose()
GoTo GotMonth
CmonthNotFound:
On Error GoTo 0
x = "JANUARY "
GotMonth:
On Error GoTo 0
If ReptMonth = VB.Left(x, 9) Then
AnchSeq = 2
FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
PrintLine(2, x)
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2)
& "/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
GoTo GetTheRest
End If
Loop
GetTheRest:
Do While Not EOF(1)
x = LineInput(1)
If VB.Left(x, 8) = "<A NAME=" Then
anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2)
& "/" & Mid(x, 10, 2) & "</A> "
AnchSeq = AnchSeq + 1
End If
PrintLine(2, x)
Loop
FileClose()
Else
FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt",
OpenMode.Output)
PrintLine(4, ReptMonth)
FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
PrintLine(2, "</BODY>")
PrintLine(2, "</HTML>")
FileClose()
End If

FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
PrintLine(3, "<HTML>")
PrintLine(3, " ")
PrintLine(3, "<HEAD>")
PrintLine(3, " ")
PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" & Chr(34)
& " CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) &
" CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
PrintLine(3, "</HEAD>")
PrintLine(3, " ")
PrintLine(3, "<BODY>")
PrintLine(3, " ")
PrintLine(3, "<H1><CENTER>My Main Company, Inc.</CENTER></H1>")
PrintLine(3, " ")
PrintLine(3, "<H3><CENTER>Daily Sales Information Reports
for " & ReptMonth & " 20" & RunYear & "</CENTER></H3>")
FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
RunDay, OpenMode.Output)
OutFile = 0
Loop1:
If EOF(1) Then GoTo EndThis
z = LineInput(1)
PrintLine(4, z)

If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") >
0 Then

If OutFile > 0 Then FileClose(2)
OutFile = OutFile + 1
OFile = RunYear & RunMon & RunDay & VB.Right("00" &
Mid(Str(OutFile), 2), 2) & ".txt"
FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RunDate = Mid(z, 11, 8)
RepTitle = Trim(Mid(z, 20, 120))
PrintLine(2, z)
z = LineInput(1)
PrintLine(4, z)
RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
' Print #2, z$
PrintLine(3, " ")
PrintLine(3, "<P>")
If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
anchor(1) = "Move directly to day <A HREF=" &
Chr(34) & "#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
For j = 1 To AnchSeq - 1 Step 10
Print(3, anchor(j) & anchor(j + 1) & anchor(j +
2) & anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6) &
anchor(j + 7) & anchor(j + 8) & anchor(j + 9))
Next j
PrintLine(3, " ")
PrintLine(3, "<P>")
PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile,
6) & Chr(34) & "></A>")
End If
PrintLine(3, "<A HREF=" & Chr(34) &
"http://www.myserver.com/reports/" & OFile & Chr(34) & ">" &
RepTitle & " - " & RepDate & " (" & RunDate & ")" & "</A>")
End If
If z <> "-----------------------------" And z <>
"=============================" Then
If VB.Left(z, 50) = New String("=", 50) Then z = New
String("=", 140)
PrintLine(2, z)
End If
GoTo Loop1
EndThis:
PrintLine(3, "<P>")
FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
Do While Not EOF(5)
x = LineInput(5)
PrintLine(3, x)
Loop
FileClose()
For j = 1 To 100
anchor(j) = ""
Next j
Kill("c:\000Glen\DAORDSHP")
Kill("c:\000Glen\dasis.htm")

'Dim oFile As System.IO.File
'Dim oWrite As System.IO.StreamWriter
'oWrite = oFile.CreateText("C:\sample.txt")
'OpenText()
'Dim fs As New Scripting.FileSystemObject
Dim iLine As String
Dim oLine As String
Dim fs As System.IO.File
Dim fs2 As System.IO.File
'Dim f As Scripting.File
Dim f As System.IO.StreamReader
Dim f2 As System.IO.StreamWriter
f = fs.OpenText("c:\000Glen\dasis6.htm")
f2 = fs2.CreateText("c:\000Glen\dasis.htm")
While f.Peek <> -1
iLine = f.ReadLine()
f2.WriteLine(iLine)
End While

f.Close()
f2.Close()

ExitCheck:

End Sub
Try running the program as a console or windows form application.
Get that working first then paste it into your service. This will
help you figure out if there is a problem on how you are running the
service or your function.

How is your Check_for_file function called in your service? When is
it triggered? Are you starting a new thread in the service to run
the check_for_file?

Chris


Here's where I am checking:

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog ' create a new event log
' Check if the the Event Log Exists
If Not MyLog.SourceExists("mycompany Daily") Then
MyLog.CreateEventSource("mycompanyDaily", "mycompany
Daily") ' Create Log
End If

check_for_file()
MyLog.Source = "mycompanyDaily"
' Write to the Log
MyLog.WriteEntry("mycompany Daily Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)

End Sub
The OnStart/OnStop events are:

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should
set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop
your service.
Timer1.Enabled = False
End Sub

This stuff would work, but all I had it doing originally was to write
events at a particular interval.

The timer is set for 480000 ticks, which should be around 5-8 minutes
or so.

Re your last question - I do not know if I am or not.

I will though, take a look at running the converted app to see what's
going on.

BC


As a general rule you should not do procssing inside the service thread,
which is what you are doing. I have always read that you should start a
new thread inside your timer_elapsed event and have the worker thread do
the work.

Someone smarter than me might want to comment on this issue.

Chris

Mar 14 '06 #5
Blasting Cap wrote:
The code in the app keeps blowing on the same line:

anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) & Chr(34) &
">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x, 10, 2) & "</A> "

It says that anchor(anchseq) is null.

It's not defined in the converted app, but I defined it as an array and
an arraylist by me outside of that, but it gives the same message each
time.

Any ideas?

BC

Chris wrote:
Blasting Cap wrote:
Chris wrote:

Blasting Cap wrote:

> I have a VB6 program that runs as an app, that I want to both
> convert it to vb.net, and run it as a service on the server.
>
> I have been able to create the service, and what I did was to open
> the vb6 document and convert it into a vb.net program. Once I did
> that, the routine "check_for_file" I yanked out & put into my
> service program.
>
> The program though - doesn't work like the existing VB6 one does.
>
>
> I've debugged the service as it runs, and it appears to read in the
> HTML file, but dies on this line:
>
> anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" & Mid(x, 10, 6) &
> Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2) & "/" & Mid(x,
> 10, 2) & "</A> "
>
> that is located in the GOTMONTH: section of the code.
>
> What happens is that it will attempt to write the file (when I open
> it I get a sharing violation message), but it has only 1 byte in
> the file. It must run again to put 06031201 into that file, but
> that's all that it ever writes. Debugging the process, it'll step
> through and appear to read everything like it should, but when it's
> into that section, it just dies. No error message or anything in
> the logfile that gives me any meaningful info.
>
> Code follows.
>
> Any help appreciated....
>
> BC
>
>
> Private Sub check_for_file()
> Dim j As Short
> Dim RepDate As String
> Dim RepTitle As String
> Dim RunDate As String
> Dim OFile As String
> Dim z As String
> Dim OutFile As Short
> Dim AnchSeq As Short
> Dim ReptMonth As String
> Dim RunDay As String
> Dim RunMon As String
> Dim RunYear As String
> Dim x As String
> Dim anchor As Array
>
> On Error GoTo FileNotThere
> If FileLen("c:\000Glen\DAORDSHP") > 0 Then GoTo FoundHim
> FileNotThere:
> On Error GoTo 0
> GoTo ExitCheck
>
> FoundHim:
>
> FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
> x = LineInput(1)
> x = LineInput(1)
> RunYear = Mid(x, 17, 2)
> RunMon = Mid(x, 11, 2)
> RunDay = Mid(x, 14, 2)
> x = LineInput(1)
> ReptMonth = Mid(x, InStr(x, "MONTH:") + 7, 9)
> FileClose()
>
>
>
> On Error GoTo CmonthNotFound
> FileOpen(1, "c:\000Glen\ordshpbu\cmonth.txt", OpenMode.Input)
> x = LineInput(1)
> FileClose()
> GoTo GotMonth
> CmonthNotFound:
> On Error GoTo 0
> x = "JANUARY "
> GotMonth:
> On Error GoTo 0
> If ReptMonth = VB.Left(x, 9) Then
> AnchSeq = 2
> FileOpen(1, "c:\000Glen\dasis.htm", OpenMode.Input)
> FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
> Do While Not EOF(1)
> x = LineInput(1)
> If VB.Left(x, 8) = "<A NAME=" Then
> PrintLine(2, x)
> anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
> Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2)
> & "/" & Mid(x, 10, 2) & "</A> "
> AnchSeq = AnchSeq + 1
> GoTo GetTheRest
> End If
> Loop
> GetTheRest:
> Do While Not EOF(1)
> x = LineInput(1)
> If VB.Left(x, 8) = "<A NAME=" Then
> anchor(AnchSeq) = "<A HREF=" & Chr(34) & "#" &
> Mid(x, 10, 6) & Chr(34) & ">" & Mid(x, 12, 2) & "/" & Mid(x, 14, 2)
> & "/" & Mid(x, 10, 2) & "</A> "
> AnchSeq = AnchSeq + 1
> End If
> PrintLine(2, x)
> Loop
> FileClose()
> Else
> FileOpen(4, "c:\000Glen\ordshpbu\cmonth.txt",
> OpenMode.Output)
> PrintLine(4, ReptMonth)
> FileOpen(2, "c:\000Glen\dasis2.htm", OpenMode.Output)
> PrintLine(2, "</BODY>")
> PrintLine(2, "</HTML>")
> FileClose()
> End If
>
> FileOpen(3, "c:\000Glen\dasis6.htm", OpenMode.Output)
> PrintLine(3, "<HTML>")
> PrintLine(3, " ")
> PrintLine(3, "<HEAD>")
> PrintLine(3, " ")
> PrintLine(3, "<META NAME=" & Chr(34) & "GENERATOR" &
> Chr(34) & " CONTENT=" & Chr(34) & "VB Generated HTML" & Chr(34) & ">")
> PrintLine(3, "<META NAME=" & Chr(34) & "AUTHOR" & Chr(34) &
> " CONTENT=" & Chr(34) & "CodeAuthor" & Chr(34) & ">")
> PrintLine(3, "</HEAD>")
> PrintLine(3, " ")
> PrintLine(3, "<BODY>")
> PrintLine(3, " ")
> PrintLine(3, "<H1><CENTER>My Main Company,
> Inc.</CENTER></H1>")
> PrintLine(3, " ")
> PrintLine(3, "<H3><CENTER>Daily Sales Information Reports
> for " & ReptMonth & " 20" & RunYear & "</CENTER></H3>")
>
>
> FileOpen(1, "c:\000Glen\DAORDSHP", OpenMode.Input)
> FileOpen(4, "c:\000Glen\ordshpbu\DA" & RunYear & RunMon &
> RunDay, OpenMode.Output)
> OutFile = 0
> Loop1:
> If EOF(1) Then GoTo EndThis
> z = LineInput(1)
> PrintLine(4, z)
>
> If VB.Left(z, 7) = "REPORT:" And InStr(z, "PAGE: 1") >
> 0 Then
>
> If OutFile > 0 Then FileClose(2)
> OutFile = OutFile + 1
> OFile = RunYear & RunMon & RunDay & VB.Right("00" &
> Mid(Str(OutFile), 2), 2) & ".txt"
> FileOpen(2, "c:\000Glen\" & OFile, OpenMode.Output)
> PrintLine(2, z)
> z = LineInput(1)
> PrintLine(4, z)
> RunDate = Mid(z, 11, 8)
> RepTitle = Trim(Mid(z, 20, 120))
> PrintLine(2, z)
> z = LineInput(1)
> PrintLine(4, z)
> RepDate = Mid(z, InStr(z, "MONTH:") + 17, 12)
> ' Print #2, z$
> PrintLine(3, " ")
> PrintLine(3, "<P>")
> If RepTitle = "TOTAL COMPANY SUMMARY REPORT" Then
> anchor(1) = "Move directly to day <A HREF=" &
> Chr(34) & "#" & VB.Left(OFile, 6) & Chr(34) & ">" & RunDate & "</A> "
> For j = 1 To AnchSeq - 1 Step 10
> Print(3, anchor(j) & anchor(j + 1) & anchor(j +
> 2) & anchor(j + 3) & anchor(j + 4) & anchor(j + 5) & anchor(j + 6)
> & anchor(j + 7) & anchor(j + 8) & anchor(j + 9))
> Next j
> PrintLine(3, " ")
> PrintLine(3, "<P>")
> PrintLine(3, "<A NAME=" & Chr(34) & VB.Left(OFile,
> 6) & Chr(34) & "></A>")
> End If
> PrintLine(3, "<A HREF=" & Chr(34) &
> "http://www.myserver.com/reports/" & OFile & Chr(34) & ">" &
> RepTitle & " - " & RepDate & " (" & RunDate & ")" & "</A>")
> End If
> If z <> "-----------------------------" And z <>
> "=============================" Then
> If VB.Left(z, 50) = New String("=", 50) Then z = New
> String("=", 140)
> PrintLine(2, z)
> End If
> GoTo Loop1
> EndThis:
> PrintLine(3, "<P>")
> FileOpen(5, "c:\000Glen\dasis2.htm", OpenMode.Input)
> Do While Not EOF(5)
> x = LineInput(5)
> PrintLine(3, x)
> Loop
> FileClose()
> For j = 1 To 100
> anchor(j) = ""
> Next j
> Kill("c:\000Glen\DAORDSHP")
> Kill("c:\000Glen\dasis.htm")
>
> 'Dim oFile As System.IO.File
> 'Dim oWrite As System.IO.StreamWriter
> 'oWrite = oFile.CreateText("C:\sample.txt")
> 'OpenText()
>
>
> 'Dim fs As New Scripting.FileSystemObject
> Dim iLine As String
> Dim oLine As String
> Dim fs As System.IO.File
> Dim fs2 As System.IO.File
> 'Dim f As Scripting.File
> Dim f As System.IO.StreamReader
> Dim f2 As System.IO.StreamWriter
> f = fs.OpenText("c:\000Glen\dasis6.htm")
> f2 = fs2.CreateText("c:\000Glen\dasis.htm")
>
>
> While f.Peek <> -1
> iLine = f.ReadLine()
> f2.WriteLine(iLine)
> End While
>
> f.Close()
> f2.Close()
>
>
>
> ExitCheck:
>
> End Sub
>

Try running the program as a console or windows form application.
Get that working first then paste it into your service. This will
help you figure out if there is a problem on how you are running the
service or your function.

How is your Check_for_file function called in your service? When is
it triggered? Are you starting a new thread in the service to run
the check_for_file?

Chris


Here's where I am checking:

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As
System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim MyLog As New EventLog ' create a new event log
' Check if the the Event Log Exists
If Not MyLog.SourceExists("mycompany Daily") Then
MyLog.CreateEventSource("mycompanyDaily", "mycompany
Daily") ' Create Log
End If

check_for_file()
MyLog.Source = "mycompanyDaily"
' Write to the Log
MyLog.WriteEntry("mycompany Daily Log", "This is log on " & _
CStr(TimeOfDay), EventLogEntryType.Information)

End Sub
The OnStart/OnStop events are:

Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should
set things
' in motion so your service can do its work.
Timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to
stop your service.
Timer1.Enabled = False
End Sub

This stuff would work, but all I had it doing originally was to write
events at a particular interval.

The timer is set for 480000 ticks, which should be around 5-8 minutes
or so.

Re your last question - I do not know if I am or not.

I will though, take a look at running the converted app to see what's
going on.

BC

As a general rule you should not do procssing inside the service
thread, which is what you are doing. I have always read that you
should start a new thread inside your timer_elapsed event and have the
worker thread do the work.

Someone smarter than me might want to comment on this issue.

Chris


It sounds like one of your mid statements is not valid. Try running
each of them in the immedient window to see which one is crashing, or do
something like:

anchor(AnchSeq) = "<A HREF="
anchor(AnchSeq) += Chr(34) & "#" &
anchor(AnchSeq) += Mid(x, 10, 6)

This way you'll find what is really causing the problem. Also, think
about replacing "Mid" with x.Substring(10, 6) it's the .net way of doing it.

Chris
Mar 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Barry | last post by:
object type cannot be converted to target type - i am getting this error message occuring numerous times in my task list, my project compiles and runs ok but it is a nuisance, I think Ihva eheard of...
2
by: Rob Richardson | last post by:
Greetings! I have a VB.Net 2003 project that was originally written in VB6, converted to VB.Net 2002, and then converted to VB.Net 2003. I am trying to handle a form's Resize event. I put a...
2
by: Jim in Arizona | last post by:
I'm learning form an ASP.NET 1.0 book and I tried out some code that returns this error: Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to...
0
by: John | last post by:
I'm attempting to launch a converted window through the drop down menu in order to assess the functionality that the conversion wizard was able to preserve. However, the function...
5
by: GaryDean | last post by:
(my original post was inaccurate but this post accurately describes what I think is a very bad vs2005 bug) short description... Deleting a dataset and recreating it from the dataadapter causes...
3
by: larpup | last post by:
I've written an app in A2003 only to find out that some customers are presently using A2000. Rather than place a runtime on their computer, it would be more convenient to convert appt to A2000 if...
8
by: rdemyan via AccessMonster.com | last post by:
I've converted my application from A2K format to A2003 format. I tried to follow Allen Browne's protocol in getting my app into A2003 (although I was unable to find informtion on the conversion...
9
imrosie
by: imrosie | last post by:
Hello, I have a form(PrintPreviewInvoices) that displays past invoices (in a listbox). I added a combo box control in order to filter timeframes;(today, this week, last week, this month, last...
6
by: vlsidesign | last post by:
Newbie question: 0 converted to 0.0 for float variable? If I have the following code, float myTotal; myTotal = 0; will C automatically add a decimal point and at least one zero to the right...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.