dcsimg
Results 1 to 15 of 15

Thread: VB6 Property to VB.net

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    VB6 Property to VB.net

    Hey Guys,

    So I have the following property

    Code:
    	Property Get Terminals										' Prop. Terminals --------------------------
    
    		If( terms_init ) Then									' if initialized, then
    			Set Terminals = terms_								' immediately available
    			Exit Property
    		End If
    
    		e3.PutInfo 0, "gathering teminals ..."					' [4rk]
    		Set terms_	= CreateObject( "Scripting.Dictionary" )	' Terminals
        Dim cnt, ids, i, obj, id
    		cnt = app.GetTerminalIds( ids )							' get them all
    		For i = 1 To cnt
    			Device.SetId ids(i)
    			If Device.IsTerminalBlock = 1 Then
    				Set obj = GetDevice( ids(i) )
    				terms_.Add obj, obj
    			End If
    		Next
    		terms_init = True
    		Set Terminals = terms_
    
    	End Property
    Just wanted a second opinion. Is this what is translates to in vb.net --> ?

    Code:
        Property Terminals                                     ' Prop. Terminals --------------------------
            Get
                If (terms_init) Then                                   ' if initialized, then
                    Return terms_                              ' immediately available
                    Exit Property
                End If
    
                e3.PutInfo(0, "gathering teminals ...")                  ' [4rk]
                terms_ = CreateObject("Scripting.Dictionary")    ' Terminals
                Dim cnt, ids, i, obj, id
                cnt = app.GetTerminalIds(ids)                         ' get them all
                For i = 1 To cnt
                    Device.SetId(ids(i))
                    If Device.IsTerminalBlock = 1 Then
                        obj = GetDevice(ids(i))
                        terms_.Add(obj, obj)
                    End If
                Next
                terms_init = True
                Return terms_
            End Get
        End Property

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    671

    Re: VB6 Property to VB.net

    Yes.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: VB6 Property to VB.net

    Quote Originally Posted by David Anton View Post
    Yes.
    Thanks

    One more question, would you know how to convert

    Code:
    	Property Let count( val )
    		cnt = CDbl(cnt) + val
    	End Property
    is it the same as set ? never heard of it before

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,706

    Re: VB6 Property to VB.net

    You don't need this line:

    Exit Property

    As soon as execution hits the Return statement, it returns, so the line will never even be reached, nor is it needed.

    Also, you should take a look at this line:

    Dim cnt, ids, i, obj, id

    What are the types of those variables? There was one default in VB6, but I think it is quite a bit different in .NET, and that difference matters. It'll still run, it just won't be efficient.
    My usual boring signature: Nothing

  5. #5
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    671

    Post Re: VB6 Property to VB.net

    VB6 used both 'Let' and 'Set' properties.
    In VB.NET you just use a 'Set':
    Code:
        Public WriteOnly Property count() As Integer
            Set(value As Integer)
                cnt = CDbl(cnt) + value
            End Set
        End Property
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,706

    Re: VB6 Property to VB.net

    As for the second question, it is pretty much the same as Set. Val shouldn't be used as an argument name, since it is the name of a function, but Set will use 'value' be default.

    There is something odd going on in the statement, though. What possible purpose could CDbl serve? If cnt is type Double already, then it would convert a double to a double, which does nothing. If cnt is not a Double, then it will be converted to a Double, then val will be added. This will result in a Double, which will be assigned back to cnt. If cnt is type Double, then the CDbl isn't needed. If cnt is NOT type Double, then you will either have an inefficient, implicit conversion, or possibly cnt will be type Object, which is even worse.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: VB6 Property to VB.net

    Quote Originally Posted by Shaggy Hiker View Post
    You don't need this line:

    Exit Property

    As soon as execution hits the Return statement, it returns, so the line will never even be reached, nor is it needed.

    Also, you should take a look at this line:

    Dim cnt, ids, i, obj, id

    What are the types of those variables? There was one default in VB6, but I think it is quite a bit different in .NET, and that difference matters. It'll still run, it just won't be efficient.
    tbh I have no idea what those variables are.

    Here is what I am doing. We have a 3rd Party program that allows the use of VB scripts to interact with it but we want to develop an application that works with it.

    In all of their script they have a set of Classes/Property and subroutines that I am taking and porting into a vb.net class so I have an environment to work with.

    Quote Originally Posted by David Anton View Post
    VB6 used both 'Let' and 'Set' properties.
    In VB.NET you just use a 'Set':
    Code:
        Public WriteOnly Property count() As Integer
            Set(value As Integer)
                cnt = CDbl(cnt) + value
            End Set
        End Property
    Quote Originally Posted by Shaggy Hiker View Post
    As for the second question, it is pretty much the same as Set. Val shouldn't be used as an argument name, since it is the name of a function, but Set will use 'value' be default.
    Thanks
    Last edited by Crzyrio; Apr 15th, 2013 at 02:52 PM.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,706

    Re: VB6 Property to VB.net

    VBScript is horrid. Every variable is a variant in that language, so they didn't even bother with any typing. Doing the same thing in .NET would be pretty bad, though it may work to some extent. In that case, every variable would be an object and you'd be relying on late binding. None of that is good if you can avoid it.

    Both i and cnt should be type Integer. The ids variable appears to be an array of whatever type those ids are, so it may be:

    ids() As Integer, or ids() As String, or something like that.

    Obj appears to be whatever GetDevice returns. It might be just Object, and can remain as such, but it would be best if it could be identified a bit more specifically than that.

    The final variable, id, doesn't appear to be used at all.
    My usual boring signature: Nothing

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,681

    Re: VB6 Property to VB.net

    Quote Originally Posted by Shaggy Hiker View Post
    VBScript is horrid. Every variable is a variant in that language...
    I believe VBScript was inspired by JavaScript which is dynamically typed also. I do agree however that it is horrid. JavaScript is really a pain in the ass to program in because of its dynamic typing. Give me strong typing with compile time checking any day.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,706

    Re: VB6 Property to VB.net

    VBScript is old, but it may well be inspired by JavaScript...which is also old.

    There is a new TypeScript, which is essentially an extension of JavaScript, but creates strongly typed JavaScript and gives you the IDE advantages that come with a strongly typed language (a whole lot more type safety checking and some intellisense-like things). You can already get it as an add-on for VS.
    My usual boring signature: Nothing

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    5,681

    Re: VB6 Property to VB.net

    Yea, I found out about it quite recently when I typed something like "compile to JavaScript" in Google. At the time it hit me that it would be very easy wrap a strongly typed language around JavaScript by using a compiler to translate.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: VB6 Property to VB.net

    I know vbs is horrid lol.

    I am going to see if this application works and how it goes. It everything is well and we plan on using it then I will for sure change as much over.

    Anyone have experience converting vbs to .net?

  13. #13
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VB6 Property to VB.net

    Quote Originally Posted by Crzyrio View Post
    Just wanted a second opinion. Is this what is translates to in vb.net --> ?

    Code:
        Property Terminals                                     ' Prop. Terminals --------------------------
            Get
                If (terms_init) Then                                   ' if initialized, then
                    Return terms_                              ' immediately available
                    Exit Property
                End If
    
                e3.PutInfo(0, "gathering teminals ...")                  ' [4rk]
                terms_ = CreateObject("Scripting.Dictionary")    ' Terminals
                Dim cnt, ids, i, obj, id
                cnt = app.GetTerminalIds(ids)                         ' get them all
                For i = 1 To cnt
                    Device.SetId(ids(i))
                    If Device.IsTerminalBlock = 1 Then
                        obj = GetDevice(ids(i))
                        terms_.Add(obj, obj)
                    End If
                Next
                terms_init = True
                Return terms_
            End Get
        End Property
    Actually, no! If you don't have any Property Set then the property must be marked as ReadOnly. The property should also have a type, however I'm unsure what type terms_ is?.
    Code:
    Public ReadOnly Property Terminal As TheTypeYouWantThisPropertyToReturn
      Get
        '... code
      End Get
    End Property
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  14. #14
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VB6 Property to VB.net

    Quote Originally Posted by Niya View Post
    I believe VBScript was inspired by JavaScript which is dynamically typed also.
    That's not really true. Microsoft had been working on a script version of VB for a while, and it was intended to be released for server side scripting in the up and coming new technology for IIS which became known as Active Server Pages (or ASP) when Netscape introduced JavaScript (or LiveScript as it was first named) in their browser back in November 1995. Since it quickly gained popularity Microsoft adopted their version of JavaScript (that was later renamed JScript) to their already ready to be released scripting engine and introduced it together with VBScript as part of Microsoft Windows Script Technologies when they released IE 3 in August 1996. ASP was introduced the same year with the new release of IIS.

    I don't really agree that VBScript is a terrible language either. It would be terrible to create a gigantic n-tier business line application with it but that is not what it's intended to be used for. It was intended to be used as an administrative tool, as a new batch scripting language for Windows. For the server side, it really was intended to read database values as dynamically produce HTML pages.

    JavaScript was intended to be used for HTML Form validations and to create simple dynamic pages in the browser (such as showing a live clock).

    JavaScript today though is turning into a terrible language since it's used in larger and larger types of applications and the language doesn't scale that well. Especially since it's so hard to debug such an application when you don't have type information.

    My point is simply this: A language is never terrible if you use it for what it was designed for. Just because you technically can use it for other things doesn't make it a good idea to do so. Technically you can breed horses by stacking them in a silo but that doesn't make it a good idea.
    Last edited by Joacim Andersson; Apr 16th, 2013 at 12:03 AM.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: VB6 Property to VB.net

    Quote Originally Posted by Joacim Andersson View Post
    That's not really true. Microsoft had been working on a script version of VB for a while, and it was intended to be released for server side scripting in the up and coming new technology for IIS which became known as Active Server Pages (or ASP) when Netscape introduced JavaScript (or LiveScript as it was first named) in their browser back in November 1995. Since it quickly gained popularity Microsoft adopted their version of JavaScript (that was later renamed JScript) to their already ready to be released scripting engine and introduced it together with VBScript as part of Microsoft Windows Script Technologies when they released IE 3 in August 1996. ASP was introduced the same year with the new release of IIS.

    I don't really agree that VBScript is a terrible language either. It would be terrible to create a gigantic n-tier business line application with it but that is not what it's intended to be used for. It was intended to be used as an administrative tool, as a new batch scripting language for Windows. For the server side, it really was intended to read database values as dynamically produce HTML pages.

    JavaScript was intended to be used for HTML Form validations and to create simple dynamic pages in the browser (such as showing a live clock).

    JavaScript today though is turning into a terrible language since it's used in larger and larger types of applications and the language doesn't scale that well. Especially since it's so hard to debug such an application when you don't have type information.

    My point is simply this: A language is never terrible if you use it for what it was designed for. Just because you technically can use it for other things doesn't make it a good idea to do so. Technically you can breed horses by stacking them in a silo but that doesn't make it a good idea.
    Quiet an informative post! Thanks

    Unfortunately I think I am going to give up my mission to convert all the vb script classes to vb.net, they are all interlinked and just to many errors to go through.

    I am going to have to let me application call vb scripts instead. Any reason this would be a bad way of doing it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width