473,473 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Object variable or With block variable not set.

hi.. just wondering what does this error means?

here's my vb code:
Imports System.Web.Security
Imports System.Data
Imports System.Data.OleDb

Public Class dpitem
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Protected WithEvents MyDataList As System.Web.UI.WebControls.DataList
Protected WithEvents mydatalist2 As System.Web.UI.WebControls.DataList
Protected WithEvents sc As System.Web.UI.WebControls.HyperLink
Protected WithEvents name As System.Web.UI.WebControls.Label
Protected WithEvents subs As System.Web.UI.WebControls.Label
Protected WithEvents qty As System.Web.UI.WebControls.Label
Protected WithEvents buyqty As System.Web.UI.WebControls.TextBox
Protected WithEvents add As System.Web.UI.WebControls.ImageButton
Protected WithEvents dg As System.Web.UI.WebControls.DataGrid
Protected WithEvents lblTotal As System.Web.UI.WebControls.Label
Dim pid As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
makeCart()
End If
Dim ds As DataSet
Dim ds2 As DataSet
Dim MyConnection As OleDbConnection
Dim MyCommand As OleDbDataAdapter
pid = Request.QueryString("pid")
Dim P As New PartyHouse

ds = P.getSub("*", "lydiasun_product", "pid", pid, "", "")
MyDataList.DataSource = ds.Tables("lydiasun_product").DefaultView
MyDataList.DataBind()

With ds.Tables("lydiasun_product").Rows(0)
name.Text = .Item("pname")
subs.Text = .Item("subcategory")
sc.Text = .Item("subcategory")
sc.NavigateUrl = "subcategory.aspx?subcategory=" & .Item
("subcategory")
qty.Text = P.sizing(.Item("allsizes"), .Item("small"), .Item
("medium"), .Item("large"))
End With

ds2 = P.getSub("distinct subcategory", "lydiasun_product",
"category", "Decoration & Props", "", "")

mydatalist2.DataSource = ds2.Tables("lydiasun_product").DefaultView
mydatalist2.DataBind()
End Sub

Dim objDT As DataTable
Dim objDR As DataRow

Sub addtocart(ByVal s As Object, ByVal e As ImageClickEventArgs)
'Dim pid As String = Request.QueryString("pid")

'Dim ds As DataSet
'Dim p As New PartyHouse
lblTotal.Text = "pid is:" & pid
Dim match As Boolean
objDT = Session("cart")
'ds = p.getSub("*", "lydiasun_product", "pid", pid, "", "")

If objDT.Rows.Count = 0 Then
objDR = objDT.NewRow
objDR("pid") = "dpp101"
objDR("qty") = CInt(Request.Form("buyqty"))
objDR("price") = 1.99
'With ds.Tables("lydiasun_product").Rows(0)
' objDR("pid") = .Item("pid")
' objDR("qty") = Request.Form("buyqty")
' objDR("img") = .Item("img")
' objDR("pname") = .Item("pname")
' objDR("pdesc") = .Item("pdesc")
' objDR("price") = .Item("price")
If Session("email") = "" Then
objDR("user") = "guest"
Else
objDR("user") = Session("email")
End If
'End With
'objDR("size") = "all size"

objDT.Rows.Add(objDR)
Else
For Each objDR In objDT.Rows
If objDR("pid") = pid Then
objDR("qty") += CInt(Request.Form("buyqty"))
match = True
Exit For
End If
Next
If Not match Then
objDR = objDT.NewRow
'With ds.Tables("lydiasun_product").Rows(0)
objDR("pid") = pid
objDR("qty") = CInt(Request.Form("buyqty"))
objDR("price") = 1.99
'objDR("img") = .Item("img")
'objDR("pname") = .Item("pname")
'objDR("pdesc") = .Item("pdesc")
'objDR("price") = .Item("price")
If Session("email") = "" Then
objDR("user") = "guest"
Else
objDR("user") = Session("email")
End If

'End With
'objDR("size") = "all size"

objDT.Rows.Add(objDR)
End If
End If
Session("cart") = objDT
dg.DataSource = objDT
dg.DataBind()
lblTotal.Text = lblTotal.Text & "<br>$" & GetItemTotal()

'Response.Write("<script>window.open('shoppingcart .aspx','mainmid')
;window.open('vtop.aspx','vtop');</script>")

End Sub

Function makeCart()
If Nothing(Session("cart")) Then

objDT = New DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1

objDT.Columns.Add("pid", GetType(String))
objDT.Columns.Add("qty", GetType(Integer))
'objDT.Columns.Add("img", GetType(String))
'objDT.Columns.Add("pname", GetType(String))
'objDT.Columns.Add("pdesc", GetType(String))
objDT.Columns.Add("price", GetType(Decimal))
objDT.Columns.Add("user", GetType(String))

Session("Cart") = objDT
End If
End Function

Function GetItemTotal() As Decimal

Dim intCounter As Integer
Dim decRunningTotal As Decimal

For intCounter = 0 To objDT.Rows.Count - -1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("price") * objDR("qty"))
Next

Return decRunningTotal

End Function

End Class

-----------------------------------

helpp... im so desperate..

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
3 2815
Looks like you have missed a new somewhere and are using a variable without
creating the object.

Rgds,
Anand M
http://www.dotnetindia.com
"sista via DotNetMonster.com" wrote:
hi.. just wondering what does this error means?

here's my vb code:
Imports System.Web.Security
Imports System.Data
Imports System.Data.OleDb

Public Class dpitem
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Protected WithEvents MyDataList As System.Web.UI.WebControls.DataList
Protected WithEvents mydatalist2 As System.Web.UI.WebControls.DataList
Protected WithEvents sc As System.Web.UI.WebControls.HyperLink
Protected WithEvents name As System.Web.UI.WebControls.Label
Protected WithEvents subs As System.Web.UI.WebControls.Label
Protected WithEvents qty As System.Web.UI.WebControls.Label
Protected WithEvents buyqty As System.Web.UI.WebControls.TextBox
Protected WithEvents add As System.Web.UI.WebControls.ImageButton
Protected WithEvents dg As System.Web.UI.WebControls.DataGrid
Protected WithEvents lblTotal As System.Web.UI.WebControls.Label
Dim pid As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
makeCart()
End If
Dim ds As DataSet
Dim ds2 As DataSet
Dim MyConnection As OleDbConnection
Dim MyCommand As OleDbDataAdapter
pid = Request.QueryString("pid")
Dim P As New PartyHouse

ds = P.getSub("*", "lydiasun_product", "pid", pid, "", "")
MyDataList.DataSource = ds.Tables("lydiasun_product").DefaultView
MyDataList.DataBind()

With ds.Tables("lydiasun_product").Rows(0)
name.Text = .Item("pname")
subs.Text = .Item("subcategory")
sc.Text = .Item("subcategory")
sc.NavigateUrl = "subcategory.aspx?subcategory=" & .Item
("subcategory")
qty.Text = P.sizing(.Item("allsizes"), .Item("small"), .Item
("medium"), .Item("large"))
End With

ds2 = P.getSub("distinct subcategory", "lydiasun_product",
"category", "Decoration & Props", "", "")

mydatalist2.DataSource = ds2.Tables("lydiasun_product").DefaultView
mydatalist2.DataBind()
End Sub

Dim objDT As DataTable
Dim objDR As DataRow

Sub addtocart(ByVal s As Object, ByVal e As ImageClickEventArgs)
'Dim pid As String = Request.QueryString("pid")

'Dim ds As DataSet
'Dim p As New PartyHouse
lblTotal.Text = "pid is:" & pid
Dim match As Boolean
objDT = Session("cart")
'ds = p.getSub("*", "lydiasun_product", "pid", pid, "", "")

If objDT.Rows.Count = 0 Then
objDR = objDT.NewRow
objDR("pid") = "dpp101"
objDR("qty") = CInt(Request.Form("buyqty"))
objDR("price") = 1.99
'With ds.Tables("lydiasun_product").Rows(0)
' objDR("pid") = .Item("pid")
' objDR("qty") = Request.Form("buyqty")
' objDR("img") = .Item("img")
' objDR("pname") = .Item("pname")
' objDR("pdesc") = .Item("pdesc")
' objDR("price") = .Item("price")
If Session("email") = "" Then
objDR("user") = "guest"
Else
objDR("user") = Session("email")
End If
'End With
'objDR("size") = "all size"

objDT.Rows.Add(objDR)
Else
For Each objDR In objDT.Rows
If objDR("pid") = pid Then
objDR("qty") += CInt(Request.Form("buyqty"))
match = True
Exit For
End If
Next
If Not match Then
objDR = objDT.NewRow
'With ds.Tables("lydiasun_product").Rows(0)
objDR("pid") = pid
objDR("qty") = CInt(Request.Form("buyqty"))
objDR("price") = 1.99
'objDR("img") = .Item("img")
'objDR("pname") = .Item("pname")
'objDR("pdesc") = .Item("pdesc")
'objDR("price") = .Item("price")
If Session("email") = "" Then
objDR("user") = "guest"
Else
objDR("user") = Session("email")
End If

'End With
'objDR("size") = "all size"

objDT.Rows.Add(objDR)
End If
End If
Session("cart") = objDT
dg.DataSource = objDT
dg.DataBind()
lblTotal.Text = lblTotal.Text & "<br>$" & GetItemTotal()

'Response.Write("<script>window.open('shoppingcart .aspx','mainmid')
;window.open('vtop.aspx','vtop');</script>")

End Sub

Function makeCart()
If Nothing(Session("cart")) Then

objDT = New DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1

objDT.Columns.Add("pid", GetType(String))
objDT.Columns.Add("qty", GetType(Integer))
'objDT.Columns.Add("img", GetType(String))
'objDT.Columns.Add("pname", GetType(String))
'objDT.Columns.Add("pdesc", GetType(String))
objDT.Columns.Add("price", GetType(Decimal))
objDT.Columns.Add("user", GetType(String))

Session("Cart") = objDT
End If
End Function

Function GetItemTotal() As Decimal

Dim intCounter As Integer
Dim decRunningTotal As Decimal

For intCounter = 0 To objDT.Rows.Count - -1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("price") * objDR("qty"))
Next

Return decRunningTotal

End Function

End Class

-----------------------------------

helpp... im so desperate..

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #2

sista via DotNetMonster.com wrote:
hi.. just wondering what does this error means?
It usually means you've used an object variable that hasn't been
initialized. Can you tell us which line the error occurs on ?
Function makeCart()
If Nothing(Session("cart")) Then


I don't know what this actually does (if anything!) but I strongly
suspect that what you mean is

If Session("cart") Is Nothing Then

To the group: Why does the original compile? What does it mean?

--
Larry Lard
Replies to group please

Nov 21 '05 #3
Larry,

You found the error in all that code.

On your question, try this.

If DirectCast(Nothing, Object) Is Nothing Then
Response.Write("I am just an object")
End If

With Option Strict Off it compiles as always in this kind of situation.

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
10
by: Michael McCracken | last post by:
Hi, I have a problem with unittest.TestCase that I could really use some help with. I have a class File in module File. The important thing about File for this discussion is that it's simple -...
8
by: Lauren Quantrell | last post by:
I get the following error: "Object variable or Width block variable not set error" trying to run this in my Access2000 .ADP database: CurrentDb.Properties.Append...
8
by: Mark Neilson | last post by:
1. What is the best way to make a single instance of my top level class (DLL) internally available to all other members of the assembly? The top level object is where all other access is made in...
6
by: Neo Geshel | last post by:
I am trying to deal with an image in code-behind. I consistently get the following error: Server Error in '/' Application. Object variable or With block variable not set. Description: An...
44
by: petermichaux | last post by:
Hi, I have been using the following line of code to create an object called "Serious" if it doesn't already exist. if (Serious == null) {var Serious = {};} This works in the scripts I use...
3
by: Richard Hollenbeck | last post by:
I've marked the line in this subroutine where I've been getting this error. It may be something stupid but I've been staring at this error trying to fix it for over an hour. I'm pretty sure the...
1
by: abhijmenbumca07 | last post by:
Object variable or With block variable not set. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
4
by: BrianAdev | last post by:
Why It throw an error of <Object variable or With block variable not set> set objAccess = GetObject(strMdbPath) objAccess.DoCmd.SetWarning False objAccess.DoCmd.OpenReport strReportName, 0 'It...
3
by: Newbie19 | last post by:
I'm trying to get a list of all subfolders in a folder on a share drive, but I keep on getting this error message: Object variable or With block variable not set. Description: An unhandled...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.