Solved

Object Variable or With Block Variable Not Set

Posted on 2004-10-08
13
792 Views
Last Modified: 2012-06-27
I keep getting this error "Object Variable or With Block Variable Not Set"  I am trying to take an integer from a database and then insert it into an array inside a structure.  I am trying to then putting this structure inside a collection, which contains many structures of the same type.  The problem comes when i am trying to use the values in the array. They do not display so then i used a msgBox to see if the value was even there.  That's when i get this error, I believe that error is the same reason i am not able to display the values in the web browser.

'Structure code
  Public Structure Store
        Public Name As String
        Public Address As String
        Public City As String
        Public State As String
        Public Zipcode As String
        Public Phone As String
        Public Fax As String
        Public NewStore As Integer
        Public OCntrNums() As Integer
        Public NCntrNums() As Integer
        Public StoreID As Integer
    End Structure

    Public storeList As New Collection()

'Putting the data base into the structure
        Dim i As Integer
        Dim k As Integer
        Dim j As Integer = 0
        Dim tmpStore As New Store()

        For i = 0 To DsStoreInfo.StoreInfo.Rows.Count - 1
            tmpStore.Name = DsStoreInfo.StoreInfo(i).storeName()
            tmpStore.Address = DsStoreInfo.StoreInfo(i).address()
            tmpStore.City = DsStoreInfo.StoreInfo(i).city()
            tmpStore.Zipcode = DsStoreInfo.StoreInfo(i).zipCode()
            tmpStore.Phone = DsStoreInfo.StoreInfo(i).phoneNumber()
            tmpStore.Fax = DsStoreInfo.StoreInfo(i).fax()
            tmpStore.State = DsStoreInfo.StoreInfo(i).state()
            tmpStore.numBths = DsStoreInfo.StoreInfo(i).numOfBooths()
            tmpStore.NewStore = DsStoreInfo.StoreInfo(i).newStore
            tmpStore.StoreID = DsStoreInfo.StoreInfo(i).storeID()

            If DsStoreInfo.StoreInfo(i).newStore >= 1 Then
                For k = 0 To DsCntrNums.CounterNumbers.Rows.Count - 1
                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore - 1 = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
                    End If
                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
                        j += 1
                    End If
                Next
            End If
            storeList.Add(tmpStore)
        Next

'Where the error comes up
MsgBox(storeList(index).NCntrNums(1))--->>I put this in here just to test the value and i get the error here
        For i = 1 To storeList(index).NumBths
            boothTotals += bTable + storeList(index).NCntrNums(i) + " + "

                  Next

        'close tables and html document
        boothTotals += "</table></td></tr></table></body>"

        'Display in web browser control
        InfoDisplayHtm.Document.body.innerhtml = boothTotals
        InfoDisplayHtm.Document.body.leftMargin = 0
        InfoDisplayHtm.Document.body.topMargin = 0
0
Comment
Question by:ethnarch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 7

Expert Comment

by:natloz
ID: 12260477
Try this...CINT()

Also...I don't see numBths in your structure???          

 tmpStore.numBths = Cint(DsStoreInfo.StoreInfo(i).numOfBooths())
            tmpStore.NewStore = Cint(DsStoreInfo.StoreInfo(i).newStore)
            tmpStore.StoreID = Cint(DsStoreInfo.StoreInfo(i).storeID())
0
 
LVL 2

Author Comment

by:ethnarch
ID: 12260507
sorry about that numbths is in the structure just a typo here the structure looks like this

  Public Structure Store
        Public Name As String
        Public Address As String
        Public City As String
        Public State As String
        Public Zipcode As String
        Public Phone As String
        Public Fax As String
        Public numBths As Integer
        Public NewStore As Integer
        Public OCntrNums() As Integer
        Public NCntrNums() As Integer
        Public StoreID As Integer
    End Structure
0
 
LVL 7

Expert Comment

by:natloz
ID: 12260523
Try the CInt....datasets do not always convert things for you...
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 2

Author Comment

by:ethnarch
ID: 12260595
I don't see how adding cInt to the lines you indicated was helping the problem with my array, but i tried it anyway and it did not work.

-------I did add it to these lines however which it seemed like it would fix the problem,but it did not
For k = 0 To DsCntrNums.CounterNumbers.Rows.Count - 1

                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore - 1 = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
                    End If
                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
                        j += 1
                    End If

------Changed to
For k = 0 To DsCntrNums.CounterNumbers.Rows.Count - 1

                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore - 1 = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.OCntrNums(j) = CInt(DsCntrNums.CounterNumbers(k).counterNum)
                    End If
                    If (DsStoreInfo.StoreInfo(i).storeID = DsCntrNums.CounterNumbers(k).storeID And DsStoreInfo.StoreInfo(i).newStore = DsCntrNums.CounterNumbers(k).dNum) Then
                        tmpStore.NCntrNums(j) = CInt(DsCntrNums.CounterNumbers(k).counterNum)
                        j += 1
                    End If

------I believe the problem is in one of the variables in these lines
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(k).counterNum
0
 
LVL 2

Author Comment

by:ethnarch
ID: 12260708
I think maybe i should specify further once the values are inside the storeList(i).NCntrNums(i) i am then trying to display them in a web control as html.  These values do not show up however in the html with this code

For i = 1 To storeList(index).NumBths
            boothTotals += bTable + storeList(index).NCntrNums(i) + " + "

                  Next

        'close tables and html document
        boothTotals += "</table></td></tr></table></body>"

        'Display in web browser control
        InfoDisplayHtm.Document.body.innerhtml = boothTotals
        InfoDisplayHtm.Document.body.leftMargin = 0
        InfoDisplayHtm.Document.body.topMargin = 0


It is as if they are not added to booth totals, do in order to figure this out i decided to test the value in storeList(i).NCntrNums(i) using a msg box but i got back this error "Object Variable or With Block Variable Not Set"

I also realise now my for loop was wrong
For i = 1 To storeList(index).NumBths
should be
For i = 0 To storeList(index).NumBths

i do however still get the error only now i get it inisde the for loop at
 boothTotals += bTable + storeList(index).NCntrNums(i) + " + "
0
 
LVL 7

Expert Comment

by:natloz
ID: 12260774
What is boothTotals defined as?
0
 
LVL 2

Author Comment

by:ethnarch
ID: 12260972
a string
0
 
LVL 7

Expert Comment

by:natloz
ID: 12260999
Strings...aren't they usually concatenated in VB.Net like

boothTotals = boothTotals & CStr(storeList(index.NCntrNums(i))  & " + "
0
 
LVL 7

Expert Comment

by:natloz
ID: 12261020
You probably would not need the & " + "
0
 
LVL 2

Author Comment

by:ethnarch
ID: 12261144
the " + " i could take out but i am using the character + to add something visually so that it prints
something + something, but that's not really important.

Thankyou for the help i do appreciate it, but my problem like i said is in the assignment of the database value to the array in the structure, for some reason i cannot put the database value into the structure. I am thinking maybe i should repost this question because i think maybe i lead you in the wrong direction.

0
 
LVL 2

Author Comment

by:ethnarch
ID: 12261429
ok it definitly has to do with the way the array is assigned in the structure, because i can't even do this
tmpStore.NCntrNums(j) = 1234
it gives me the same error message
0
 
LVL 18

Accepted Solution

by:
mdougan earned 50 total points
ID: 12261702
Hi ethnarch,

The problem is that you are creating empty arrays with the OCntrNums() and NCntrNums() structure members... and you're never initializing them with any array items... now, under VB6 you would do something like:

Dim tmpStore as New Store()
Redim tempStore.OCntrNums(10) as Integer
Redim TempStore.NCntrNums(10) as Integer

Then, you could put stuff in them....  TempStore.NCntrNums(0) = 55

I'm not sure if Redim works the same way in VB.NET   Maybe if you just dimensioned them in your structure... but if you need a dynamic array, then you're going to have to look up how to add or redimension an array in VB.NET because I think it's different... I only know how to initialize an array with an assignment:

Dim myStrings() As String = {"bob", "ted", "sally"}

Cheers!
0
 
LVL 2

Author Comment

by:ethnarch
ID: 12261896
Thanks mdougan I actually just figured that out right before your post, i came up with another solution however though.  

I found i couldn't dimension the array inside the structure, vb. net wasn't allowing me to.  So i just made the structure into a class and then added a  dimension of 50 to the array,like this:

Public NCntrNums(50) As Integer

 however this is incorrect to because i am going to run into trouble later when i need to search through the array.  vb.net doesn't seem to allow me to declare a dynamic array inside the class or the structure.

So i used your method to re dimension the arrays in the structure as i create them and it seems to work find I hope.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question