Resolved Visual Basic Simple Scripting wont work.

DarkAngel

Member
Joined
Feb 19, 2010
Messages
5
Programming Experience
1-3
Alright, So ive returned to using vb after several years now. Ive programed in VB6.0 years ago and I was quite proficient at it.

However after returning to vb (now using Visual Studio 2010). Either Ive forgotten everything, or something has changed. For a university project. Im trying to write a program that takes a string of bits and encrypts it using DES Encryption.

The first step is to create an array.
In global, I wrote the following
VB.NET:
Public Class DES
    Dim PC1() As Integer
    Dim Counter As New Integer
Under DES_load I did the declaration of the array
VB.NET:
    Private Sub DES_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Declaration of PC1 Table
        PC1(0) = 57
        PC1(1) = 49
        PC1(2) = 41
        PC1(3) = 33
        PC1(4) = 25
        PC1(5) = 17
        PC1(6) = 9
        PC1(7) = 1
        PC1(8) = 58
        PC1(9) = 50
        PC1(10) = 42
        PC1(11) = 34
        PC1(12) = 26
        PC1(13) = 18
        PC1(14) = 10
        PC1(15) = 2
        PC1(16) = 58
        PC1(17) = 51
        PC1(18) = 43
        PC1(19) = 35
        PC1(20) = 27
        PC1(21) = 19
        PC1(22) = 11
        PC1(23) = 3
        PC1(24) = 60
        PC1(25) = 52
        PC1(26) = 44
        PC1(27) = 36
        PC1(28) = 63
        PC1(29) = 55
        PC1(30) = 47
        PC1(31) = 39
        PC1(32) = 31
        PC1(33) = 23
        PC1(34) = 15
        PC1(35) = 7
        PC1(36) = 62
        PC1(37) = 54
        PC1(38) = 46
        PC1(39) = 38
        PC1(40) = 30
        PC1(41) = 22
        PC1(42) = 14
        PC1(43) = 6
        PC1(44) = 61
        PC1(45) = 53
        PC1(46) = 45
        PC1(47) = 37
        PC1(48) = 29
        PC1(49) = 21
        PC1(50) = 13
        PC1(51) = 5
        PC1(52) = 28
        PC1(53) = 20
        PC1(54) = 12
        PC1(55) = 4

        Counter = 55
        Label1.text = pc1(Counter)
    End Sub

The reasoni created label1 was to check that it is assigning those values to the PC1 array. But instead on loading the page. I get the following error.

"Object reference not set to an instance of an object."
VB.NET:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Encryption.DES.DES_Load(Object sender, EventArgs e) in C:\Users\DarkAngel\Documents\Network Security\Encryption\Encryption\DES.vb:line 7
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 (B2Rel.021006-0100)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.21006/mscorlib.dll
----------------------------------------
Encryption
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/DarkAngel/Documents/Network%20Security/Encryption/Encryption/bin/Debug/Encryption.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 10.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 (B2Rel.021006-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 (B2Rel.021006-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.21006.1 built by: B2Rel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Im starting to think that Ive forgotten more than I thought. When i learned VB using VB 6.0, I never had to declare variables with "new" before the variable type. Could someone jog my memory a bit?

Cheers,
DAS
 
Last edited:

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
Dim PC1() as Integer creates doesn't actually make the array it just says "we're going to need room for an array we don't how much yet just that we will need to make one".
What you need to do is make the array
Dim PC1(55) as Integer, now you explicitly have said my array is going to be this big.
 

DarkAngel

Member
Joined
Feb 19, 2010
Messages
5
Programming Experience
1-3
Dim PC1() as Integer creates doesn't actually make the array it just says "we're going to need room for an array we don't how much yet just that we will need to make one".
What you need to do is make the array
Dim PC1(55) as Integer, now you explicitly have said my array is going to be this big.

Wow this one error caused me a ton of grief lol. I forgot to define the array size.

Thank you very much.
 
Top Bottom