converting to .net

  • Thread starter Thread starter Ryan Epinos
  • Start date Start date
R

Ryan Epinos

How would i convert this on vb.net?

Open DestinFile For Input As #25
If LOF(25) > 0 Then
Close()
GoTo AllreadyE
End If
 
Dim lfsTemp As FileStream
Dim lbwTemp As BinaryWriter
Dim lbTemp() As Byte

Try
lfsTemp = New FileStream("MyFileName", FileMode.Create)
lbwTemp = New BinaryWriter(lfsTemp, System.Text.Encoding.Default)
lbTemp = System.Text.Encoding.Default.GetBytes(stringFileContent)
lbwTemp.Write(lbTemp)
lbwTemp.Close()
lfsTemp.Close()
lbwTemp = Nothing
lfsTemp = Nothing
Catch ex As Exception
MsgBox (string.Concat("Cannot write file, ", "MyFileName"))
End Try
 
Ryan,
How would i convert this on vb.net?

Seems like you're just checking if a file exists and has a non-zero
length, in which case you can do

Dim fi As new FileInfo(DestinFile)
If fi.Exists AndAlso fi.Length > 0 Then ...



Mattias
 
would you guys consider this:

Before:
Open DestinFile For Input As #25
If LOF(25) > 0 Then
Close()
GoTo AllreadyE
End If

After:

FileOpen(25, DestinFile, OpenMode.Output)
WriteLine(25, "DestinFile")
If LOF(25) > 0 Then
Close()
GoTo AllreadyE
End If
 
That makes it sound a bit like the OR operator...

Except that OR probably evaluates both expressions regardless...
 
Except that OR probably evaluates both expressions regardless...

Correct, but you also have OrElse for shortcuiting evaluation...
 
AndAlso...never heard of that. Is it the same as just And?

No its works differently (from msdn):

"A logical operation is said to be short-circuiting if the compiled code can
bypass the evaluation of one expression depending on the result of another
expression. If the result of the first expression evaluated determines the
final result of the operation, there is no need to evaluate the other
expression, because it cannot change the final result. Short-circuiting can
improve performance if the bypassed expression is complex, or if it involves
procedure calls."

"And" used to evaluate both expressions, "AndAlso" works as mentioned above.

Ab.
http://joehacker.blogspot.com
there are better things to discuss like :
http://www.msnbc.msn.com/id/7328143/
 

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

Back
Top