Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

vb6 - vb.net 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Newman - 02 Jul 2007 21:02 GMT
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
Lloyd Sheen - 02 Jul 2007 21:11 GMT
>I have inherited this vb6 code which i am trying to rewrite using vb.net
>2005
[quoted text clipped - 24 lines]
> 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))
> 0 Then
           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
Kerry Moorman - 02 Jul 2007 21:36 GMT
Lloyd,

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

Kerry Moorman

> 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
rowe_newsgroups - 02 Jul 2007 23:56 GMT
On Jul 2, 4:36 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.com> wrote:
> Lloyd,
>
[quoted text clipped - 8 lines]
>
> > Lloyd Sheen

> 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
Cor Ligthert [MVP] - 03 Jul 2007 06:09 GMT
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

> On Jul 2, 4:36 pm, Kerry Moorman
> <KerryMoor...@discussions.microsoft.com> wrote:
[quoted text clipped - 22 lines]
>
> Seth Rowe
rowe_newsgroups - 03 Jul 2007 13:25 GMT
On Jul 3, 1:09 am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
> Lloyd,
>
[quoted text clipped - 33 lines]
>
> > Seth Rowe

> 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
Andrew Morton - 03 Jul 2007 13:32 GMT
> 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
Cor Ligthert [MVP] - 03 Jul 2007 06:08 GMT
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
///

>I have inherited this vb6 code which i am trying to rewrite using vb.net
>2005
[quoted text clipped - 24 lines]
> any help would be most appriacated
> Thank you

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.