ethnarch
asked on
Object Variable or With Block Variable Not Set
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).s toreName()
tmpStore.Address = DsStoreInfo.StoreInfo(i).a ddress()
tmpStore.City = DsStoreInfo.StoreInfo(i).c ity()
tmpStore.Zipcode = DsStoreInfo.StoreInfo(i).z ipCode()
tmpStore.Phone = DsStoreInfo.StoreInfo(i).p honeNumber ()
tmpStore.Fax = DsStoreInfo.StoreInfo(i).f ax()
tmpStore.State = DsStoreInfo.StoreInfo(i).s tate()
tmpStore.numBths = DsStoreInfo.StoreInfo(i).n umOfBooths ()
tmpStore.NewStore = DsStoreInfo.StoreInfo(i).n ewStore
tmpStore.StoreID = DsStoreInfo.StoreInfo(i).s toreID()
If DsStoreInfo.StoreInfo(i).n ewStore >= 1 Then
For k = 0 To DsCntrNums.CounterNumbers. Rows.Count - 1
If (DsStoreInfo.StoreInfo(i). storeID = DsCntrNums.CounterNumbers( k).storeID And DsStoreInfo.StoreInfo(i).n ewStore - 1 = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
End If
If (DsStoreInfo.StoreInfo(i). storeID = DsCntrNums.CounterNumbers( k).storeID And DsStoreInfo.StoreInfo(i).n ewStore = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
j += 1
End If
Next
End If
storeList.Add(tmpStore)
Next
'Where the error comes up
MsgBox(storeList(index).NC ntrNums(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.bo dy.innerht ml = boothTotals
InfoDisplayHtm.Document.bo dy.leftMar gin = 0
InfoDisplayHtm.Document.bo dy.topMarg in = 0
'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
tmpStore.Name = DsStoreInfo.StoreInfo(i).s
tmpStore.Address = DsStoreInfo.StoreInfo(i).a
tmpStore.City = DsStoreInfo.StoreInfo(i).c
tmpStore.Zipcode = DsStoreInfo.StoreInfo(i).z
tmpStore.Phone = DsStoreInfo.StoreInfo(i).p
tmpStore.Fax = DsStoreInfo.StoreInfo(i).f
tmpStore.State = DsStoreInfo.StoreInfo(i).s
tmpStore.numBths = DsStoreInfo.StoreInfo(i).n
tmpStore.NewStore = DsStoreInfo.StoreInfo(i).n
tmpStore.StoreID = DsStoreInfo.StoreInfo(i).s
If DsStoreInfo.StoreInfo(i).n
For k = 0 To DsCntrNums.CounterNumbers.
If (DsStoreInfo.StoreInfo(i).
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(
End If
If (DsStoreInfo.StoreInfo(i).
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(
j += 1
End If
Next
End If
storeList.Add(tmpStore)
Next
'Where the error comes up
MsgBox(storeList(index).NC
For i = 1 To storeList(index).NumBths
boothTotals += bTable + storeList(index).NCntrNums
Next
'close tables and html document
boothTotals += "</table></td></tr></table
'Display in web browser control
InfoDisplayHtm.Document.bo
InfoDisplayHtm.Document.bo
InfoDisplayHtm.Document.bo
ASKER
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
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
Try the CInt....datasets do not always convert things for you...
ASKER
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).n ewStore - 1 = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
End If
If (DsStoreInfo.StoreInfo(i). storeID = DsCntrNums.CounterNumbers( k).storeID And DsStoreInfo.StoreInfo(i).n ewStore = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
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).n ewStore - 1 = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.OCntrNums(j) = CInt(DsCntrNums.CounterNum bers(k).co unterNum)
End If
If (DsStoreInfo.StoreInfo(i). storeID = DsCntrNums.CounterNumbers( k).storeID And DsStoreInfo.StoreInfo(i).n ewStore = DsCntrNums.CounterNumbers( k).dNum) Then
tmpStore.NCntrNums(j) = CInt(DsCntrNums.CounterNum bers(k).co unterNum)
j += 1
End If
------I believe the problem is in one of the variables in these lines
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers( k).counter Num
-------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.
If (DsStoreInfo.StoreInfo(i).
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(
End If
If (DsStoreInfo.StoreInfo(i).
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(
j += 1
End If
------Changed to
For k = 0 To DsCntrNums.CounterNumbers.
If (DsStoreInfo.StoreInfo(i).
tmpStore.OCntrNums(j) = CInt(DsCntrNums.CounterNum
End If
If (DsStoreInfo.StoreInfo(i).
tmpStore.NCntrNums(j) = CInt(DsCntrNums.CounterNum
j += 1
End If
------I believe the problem is in one of the variables in these lines
tmpStore.OCntrNums(j) = DsCntrNums.CounterNumbers(
tmpStore.NCntrNums(j) = DsCntrNums.CounterNumbers(
ASKER
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.bo dy.innerht ml = boothTotals
InfoDisplayHtm.Document.bo dy.leftMar gin = 0
InfoDisplayHtm.Document.bo dy.topMarg in = 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) + " + "
For i = 1 To storeList(index).NumBths
boothTotals += bTable + storeList(index).NCntrNums
Next
'close tables and html document
boothTotals += "</table></td></tr></table
'Display in web browser control
InfoDisplayHtm.Document.bo
InfoDisplayHtm.Document.bo
InfoDisplayHtm.Document.bo
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
What is boothTotals defined as?
ASKER
a string
Strings...aren't they usually concatenated in VB.Net like
boothTotals = boothTotals & CStr(storeList(index.NCntr Nums(i)) & " + "
boothTotals = boothTotals & CStr(storeList(index.NCntr
You probably would not need the & " + "
ASKER
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.
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.
ASKER
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
tmpStore.NCntrNums(j) = 1234
it gives me the same error message
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Also...I don't see numBths in your structure???
tmpStore.numBths = Cint(DsStoreInfo.StoreInfo
tmpStore.NewStore = Cint(DsStoreInfo.StoreInfo
tmpStore.StoreID = Cint(DsStoreInfo.StoreInfo