1

ok first of all i have 1 array here

  Dim JD = {"0", "LIE"} 

then i have 3 textboxes that i put in array too

  Dim ColJD1 As TextBox() = {Me.JD1_1, Me.JD1_2, Me.JD1_3}

then i use those arrays in a subroutine :

     Sub fillword(ByVal num1, ByVal qtychar, ByVal num2, ByVal i, ByVal Coltxtbox)

     If Strings.Mid(My.Computer.FileSystem.ReadAllText("SAVE.txt"), Strings.InStr(My.Computer.FileSystem.ReadAllText("SAVE.txt"), num1), qtychar) = num2 & ".True" Then

        For test = 1 To Strings.Len(JD(i))
            For Each txtbox In Coltxtbox
                Dim a As String = Strings.Mid(JD(i), test, 1)
                MsgBox(a)
                txtbox.Text = i     => here is the problem
                i = i + 1
            Next
        Next
    End If

  End Sub

   Sub loadgame1()
      fillword("1", 6, "1", 1, ColJD1)
   End Sub

   Private Sub Button_click bla bla 
      loadgame1()
   End Sub

It's throwing error : "Object variable or With block variable not set."

any kind of help is greatly appreciated

@w0051977 actually the variable name is "test" and not "uji"

After receiving Hans suggestion i did modify the code but it still throws error : i changed the code :

    Dim JD = {"0", "RIA"}
    Dim ColJD1 As TextBox()

    Sub fillarray()
     InitializeComponent()
        ColJD1 = {JD1_1, JD1_2, JD1_3}
    End Sub

     Sub fillword(ByVal num1, ByVal qtychar, ByVal num2, ByVal i, ByVal Coltxtbox)
     fillarray()
      If Strings.Mid(My.Computer.FileSystem.ReadAllText("SAVE.txt"), Strings.InStr(My.Computer.FileSystem.ReadAllText("SAVE.txt"), num1), qtychar) = num2 & ".True" Then
       For test = 1 To Strings.Len(JD(i))
               For Each txtbox In Coltxtbox => Now the problem moves here , it throws error "Object reference not set to an instance of an object."
                  Dim a As String = Strings.Mid(JD(i), test, 1)
                  MsgBox(a)
                  txtbox.Text = i     
                  i = i + 1
               Next
            Next
         End If
      End Sub

      Sub loadgame1()
         fillword("1", 6, "1", 1, ColJD1)
      End Sub

      Private Sub Button_click bla bla 
        loadgame1()
      End Sub
1
  • What is the variable: uji for? Commented Apr 12, 2014 at 17:18

1 Answer 1

1

Use the debugger, you can inspect the variables to find the one that is Nothing.

Which is pretty likely to be the ColJD1 array, can't see the scope to make the call but it is very common mistake. Members like Me.JD1_1 don't get a value until after the InitializeComponent() method runs. The variable is getting initialized too soon, before that method runs. So it will just contain elements that are Nothing. You need to write it like this instead:

Dim ColJD1 As TextBox()

Public Sub New
    InitializeComponent()
    ColJD1 = {Me.JD1_1, Me.JD1_2, Me.JD1_3}
End Sub

Where Sub New is the constructor that needs to be added.

Sign up to request clarification or add additional context in comments.

2 Comments

Dear sir , it still throws "Object reference not set to an instance of an object", i'm still clueless where should I add "New" on the array declaration
ok disregard my last comment, the code works like a charm, thank you @Hans Passant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.