vb6 - vb.net 2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have inherited this vb6 code which i am trying to rewrite using vb.net 2005
I need to be able to get this working as we cannot issue out new end user
software at the moment

Public Function Decript(String1) As String
Dim n, K As Integer
Dim OutText As String

If InStr(1, Left(String1, 2), Chr(7)) > 0 Then
String1 = Mid(String1, 2)
End If

If RandCode = True Then
n = Rnd(Int(DateDiff("d", ToDate, "01/01")))
Randomize (Val(Right("279", 2)))
End If

For n = 1 To Len(String1)
K = Int((117 - 6 + 3) * Rnd + 8)
OutText = OutText + Chr(Asc(Mid(String1, n, 1)) - K)
Next
Decript = OutText

End Function


any help would be most appriacated
Thank you
 
Peter Newman said:
I have inherited this vb6 code which i am trying to rewrite using vb.net
2005
I need to be able to get this working as we cannot issue out new end user
software at the moment

Public Function Decript(String1) As String
Dim n, K As Integer
Dim OutText As String

If InStr(1, Left(String1, 2), Chr(7)) > 0 Then
String1 = Mid(String1, 2)
End If

If RandCode = True Then
n = Rnd(Int(DateDiff("d", ToDate, "01/01")))
Randomize (Val(Right("279", 2)))
End If

For n = 1 To Len(String1)
K = Int((117 - 6 + 3) * Rnd + 8)
OutText = OutText + Chr(Asc(Mid(String1, n, 1)) - K)
Next
Decript = OutText

End Function


any help would be most appriacated
Thank you


First you must import:

Imports Microsoft.VisualBasic.Strings


Then use the following code:

Public Function Decript(ByVal String1) As String
Dim n, K As Integer
Dim OutText As String

If InStr(1, Microsoft.VisualBasic.Strings.Left(String1, 2), Chr(7))
String1 = Mid(String1, 2)
End If

If RandCode = True Then
n = Rnd(Int(DateDiff("d", ToDate, "01/01")))
Randomize(Val(Microsoft.VisualBasic.Strings.Right("279", 2)))
End If

For n = 1 To Len(String1)
K = Int((117 - 6 + 3) * Rnd() + 8)
OutText = OutText + Chr(Asc(Mid(String1, n, 1)) - K)
Next
Return OutText

End Function

I don't know what RandCode or ToDate are supposed to be but other than that
it should work identically.

Notice that in VB.Net you use the return verb rather than assign the value
of the return to the function name as in VB6.

Hope this helps.

Lloyd Sheen
 
Lloyd,

In VB.Net, both methods of returning a value from a function work identically.

Kerry Moorman
 
Lloyd,

In VB.Net, both methods of returning a value from a function work identically.

Kerry Moorman





In VB.Net, both methods of returning a value from a function work identically.

Yes, but return is much better when you rename a function - a feature
I sorely missed in vb classic.

Thanks,

Seth Rowe
 
Peter,

I am absolute no VB6 guy anymore, however just with as less changes as
possible.

You can change the Left, Mid by substring, which is in my idea easier and
common to use
string1.substring(starting where indexer is zero, length)

\\\
Public Function Decript(ByVal String1 As String, ByVal RandCode As Boolean)
As String
Dim n, K As Integer
Dim OutText As String

If InStr(1, Microsoft.VisualBasic.Left(String1, 2), Chr(7)) > 0 Then
String1 = Mid(String1, 2)
End If

If RandCode = True Then
n = CInt(Rnd(Int(DateDiff("d", Today, "01/01"))))
Randomize(Val(Microsoft.VisualBasic.Right("279", 2)))
End If

For n = 1 To Len(String1)
K = CInt(Int((117 - 6 + 3) * Rnd() + 8))
OutText = OutText + Chr(Asc(Mid(String1, n, 1)) - K)
Next
Decript = OutText

End Function
///
 
Lloyd,
Yes, but return is much better when you rename a function -

I would not write "better", in my idea is it your personal preference, as it
is mine too.

:-)

Cor
 
Lloyd,


I would not write "better", in my idea is it your personal preference, as it
is mine too.

:-)

Cor





I would not write "better", in my idea is it your personal preference, as it
is mine too.

Oops, I guess I forgot my IMO tag in my previous statement.

Besides, if you and I actually agree it has to be correct right?

:-)

Thanks,

Seth Rowe
 
Kerry said:
In VB.Net, both methods of returning a value from a function work
identically.

Not quite - from the help:
"Return is equivalent to assigning the expression to the function name as
the return value and then executing an Exit Function statement"

Andrew
 
Back
Top