HELP Converting vbScript to Visual basic 2010

  • (2 Pages)
  • +
  • 1
  • 2

26 Replies - 2490 Views - Last Post: 13 February 2013 - 06:26 PM Rate Topic: -----

#1 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 12:48 PM

Hi,

I want to convert a vbscript to vb.net

when i turn off Option script and explicit i run into these errors:

Code first:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Const HKEY_LOCAL_MACHINE = &H80000002
        strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        strValueName = "DigitalProductId"
        strComputer = "."
        Dim iValues()
        oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
              strComputer & "\root\default:StdRegProv")
        oReg.GetBinaryValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, iValues)
        Dim arrDPID
        arrDPID = Array()
        For i = 52 To 66
            ReDim Preserve arrDPID(UBound(arrDPID) + 1)
            arrDPID(UBound(arrDPID)) = iValues(i)
        Next

        Dim arrChars As Array
        arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")

        For i = 24 To 0 Step -1
            k = 0
            For j = 14 To 0 Step -1
                k = k * 256 Xor arrDPID(j)
                arrDPID(j) = Int(k / 24)
                k = k Mod 24
            Next
            strProductKey = arrChars(k) & strProductKey
            ' <------- add the "-" between the groups of 5 Char -------->
            If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
        Next
        strFinalKey = strProductKey
        '

        strComputer = "."
        objWMIService = GetObject("winmgmts:" _
           & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        colOperatingSystems = objWMIService.ExecQuery _
           ("Select * from Win32_OperatingSystem")
        For Each objOperatingSystem In colOperatingSystems
            strOS = objOperatingSystem.Caption
            strBuild = objOperatingSystem.BuildNumber
            strSerial = objOperatingSystem.SerialNumber
            strRegistered = objOperatingSystem.RegisteredUser
        Next
        wshShell = CreateObject("wscript.shell")
        strPopupMsg = strOS & vbNewLine & vbNewLine
        strPopupMsg = strPopupMsg & "Build Number:  " & strBuild & vbNewLine
        strPopupMsg = strPopupMsg & "PID:  " & strSerial & vbNewLine & vbNewLine
        strPopupMsg = strPopupMsg & "Registered to:  " & strRegistered & vbNewLine & vbNewLine & vbNewLine
        strPopupMsg = strPopupMsg & "Your Windows Product Key is:" & vbNewLine & vbNewLine & strFinalKey
        strPopupTitle = "Microsoft Windows License Information"
        wshShell.Popup(strPopupMsg, , strPopupTitle, vbCancelOnly + vbInformation)
    End Sub



Error:
'Array' is a type and cannot be used as an expression.
'Array' is a type and cannot be used as an expression.


On lines 18 and 25 respectively.
I tried to declare as in vb.net (maybe i did it wrong cause i don't do much work with arrays...

Is This A Good Question/Topic? 0
  • +

Replies To: HELP Converting vbScript to Visual basic 2010

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,512
  • Joined: 12-December 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 01:06 PM

The line numbers you mention don't quite correspond with your posted code.

You should do a little reading on how Arrays work in VB.NET, then you'll be able to modify the code:

http://msdn.microsof...CreatingAnArray

Something like:

        Dim arrDPID() 'As Array (not necessary)
        ReDim arrDPID(50)

        Dim arrChars = {"A", "B", "C"}

This post has been edited by andrewsw: 07 February 2013 - 01:17 PM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 01:10 PM

Sure - it's all about the syntax!

    '-- not this
        Dim arrChars As Array
        arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")

        '-- throwing the () after the variable name says "hey.. I am an array of what ever data type this is"
        Dim arrChar() As Char
        '-- by putting a discrete list inbetween braces the compiler knows how to assign that to the array you declared above.
        arrChars = {"B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9"}

Was This Post Helpful? 0
  • +
  • -

#4 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:36 PM

View Postmodi123_1, on 07 February 2013 - 01:10 PM, said:

Sure - it's all about the syntax!

    '-- not this
        Dim arrChars As Array
        arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")

        '-- throwing the () after the variable name says "hey.. I am an array of what ever data type this is"
        Dim arrChar() As Char
        '-- by putting a discrete list inbetween braces the compiler knows how to assign that to the array you declared above.
        arrChars = {"B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R", "T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9"}


I tried to do that but it gives me: "(" Expression expected, like i can only use one letter, like "B", not "B", "C" (etc), why is that?

I'm sure i will read more about arrays, i only tried if it worked without other problems... but apparently..
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:40 PM

So. let's see the code where you tried to implement lines 5-8.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,512
  • Joined: 12-December 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:42 PM

The new array is named arrChar not arrChars, but I assume you corrected this.

arrChar = {"B"c, "C"c, "D"c

You need to append each character with the c character-qualifier in order to convert the string "B", etc., to a Char. Otherwise, you might use an array of string(s).
Was This Post Helpful? 0
  • +
  • -

#7 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:45 PM

I just used what you posted...

I can't show you right now... my brother needed my laptop and i'm on my old pc now, with no VS ://>/>


Edit: yes i did correct that, and i was not aware of that, even though i tried declare it as simple "Array" instead of Char as i assume it'll would work, but for what i've seen, it doesn't.
I'll try tomorrow, don't have my laptop right now...

Thanks for the help

This post has been edited by HeBTeMy: 07 February 2013 - 02:46 PM

Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,512
  • Joined: 12-December 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:51 PM

If you had

Dim arrChar()
arrChar = {"B", "C", "D", "F", "G",

with the setting Option Strict Off then type-inference would be used and this would become an array of strings. It is preferable to leave Option Strict On and do things properly :) [The default is Off]

This post has been edited by andrewsw: 07 February 2013 - 02:55 PM

Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:56 PM

Quote

do things properly


pffsst.. real programmers do it explicitly! :D
Was This Post Helpful? 0
  • +
  • -

#10 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:56 PM

But if i leave it on then it'll be multiple errors if i'm not mistaken, or is that or is Option explicit...
I only put it off cause i've tried to search how to convert a vbs to vb.net and read a topic that it said to turn off...
I know native neat code is better, but i was looking for a "easier way" if there was such thing. :D/>

but like i said, i can't test it now...

Edit; If the default is off, then its explicit that gives such errors, if i'm not mistaken.

This post has been edited by HeBTeMy: 07 February 2013 - 02:57 PM

Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9393
  • View blog
  • Posts: 35,273
  • Joined: 12-June 08

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 02:57 PM

Ah.. no.. those errors will exist and require the compiler to make some sort of guess on what your intent is.. it maybe right or the compiler maybe wrong... either way until you are more proficient you need to turn on those options and *KEEP* them on until you know .NET substantially more. Just glossing over your errors isn't good programming.
Was This Post Helpful? 1
  • +
  • -

#12 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,512
  • Joined: 12-December 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 03:05 PM

FWIW the c letter after "A"c is called literal type character (MSDN) although I prefer the term type-qualifier (which I made up) :)
Was This Post Helpful? 0
  • +
  • -

#13 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,099
  • Joined: 02-July 08

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 03:15 PM

Explicit:

Dim str() As String


Is a string array.

Dim ints() As Integer


Is an Integer array

Inferred:

Dim o = 1

Was This Post Helpful? 0
  • +
  • -

#14 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 07 February 2013 - 04:12 PM

View PostHeBTeMy, on 07 February 2013 - 03:45 PM, said:

I just used what you posted...

Edit: yes i did correct that, and i was not aware of that, even though i tried declare it as simple "Array" instead of Char as i assume it'll would work, but for what i've seen, it doesn't.
I'll try tomorrow, don't have my laptop right now...

Note that the "B"c,"C"c, ... are enclosed in CURLY braces { }, not parentheses ( ). Curly braces are the ones above the square brackets [ ] on most keyboards.
Was This Post Helpful? 0
  • +
  • -

#15 HeBTeMy  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 299
  • Joined: 05-October 12

Re: HELP Converting vbScript to Visual basic 2010

Posted 08 February 2013 - 05:20 PM

View Postlar3ry, on 07 February 2013 - 04:12 PM, said:

View PostHeBTeMy, on 07 February 2013 - 03:45 PM, said:

I just used what you posted...

Edit: yes i did correct that, and i was not aware of that, even though i tried declare it as simple "Array" instead of Char as i assume it'll would work, but for what i've seen, it doesn't.
I'll try tomorrow, don't have my laptop right now...

Note that the "B"c,"C"c, ... are enclosed in CURLY braces { }, not parentheses ( ). Curly braces are the ones above the square brackets [ ] on most keyboards.


Yeah, that was the error, didn't know that... thanks.

btw, that's why i turned off these "Option"'s , http://prntscr.com/s1rxs

Maybe some will give error when i get there... or run it, but right know it only has one...

And since i didn't make this vbscript i'm not able to correct it, cause i don't know what it is...

"Operator 'Xor' is not defined for types 'Object' and 'System.Array'."

Because i don't know what is does, i just wanted what this vbScript does in vb.net, i cannot figure out without base knowledge on this.. and of course i cannot ask "you" to convert this entirely in vb.net

But thanks anyone who tries/ed to help.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2