Converted code

B

Blasting Cap

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
 
C

Chris

Blasting said:
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
 
B

Blasting Cap

Chris said:
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
 
C

Chris

Blasting said:
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
 
B

Blasting Cap

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
 
C

Chris

Blasting said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top