473,395 Members | 1,670 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

With block variable not set, error

Hi,

I'm converting a bit of POP3 VB6 code to VB2005, and have run into this
error with the following code.

Can someone help me find out what I'm missing/doing wrong?

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With block
variable not set." Error

Console.WriteLine(" Attach Block Type=" &
AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

Thanks, Al G
Sep 24 '07 #1
5 3238
"Al G" <ag*******@nospam.charter.netschrieb
Hi,

I'm converting a bit of POP3 VB6 code to VB2005, and have run
into this error with the following code.

Can someone help me find out what I'm missing/doing wrong?

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With
block variable not set." Error

Console.WriteLine(" Attach Block Type=" &
AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

I can not explain /this/ error because there is no With statement in your
code. If you got an IndexOutOfRange exception, I would recommend to create
an array that is not empty (Redim statement). Currently, you have an empty
array, but you are trying to access the first item in the array.
Armin

Sep 24 '07 #2

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Al G" <ag*******@nospam.charter.netschrieb
>Hi,

I'm converting a bit of POP3 VB6 code to VB2005, and have run
into this error with the following code.

Can someone help me find out what I'm missing/doing wrong?

'holds the attachments
snip for brevity, see below...
>>
Console.Read()

End Sub


I can not explain /this/ error because there is no With statement in your
code. If you got an IndexOutOfRange exception, I would recommend to create
an array that is not empty (Redim statement). Currently, you have an empty
array, but you are trying to access the first item in the array.
Armin
Thank you for taking the time, this is all a little new for me. I went
back,
and added a redim statement,

Module Module1

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

ReDim AttachBlock(20)

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With

' block variable not set." Error

Console.WriteLine(" Attach Block Type=" & AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

End Module

The actual error is:

System.NullReferenceException was unhandled
Message="Object variable or With block variable not set."
Source="Microsoft.VisualBasic"


Al G
Sep 24 '07 #3
"Al G" <ag*******@nospam.charter.netschrieb
>
"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Al G" <ag*******@nospam.charter.netschrieb
Hi,
>
I'm converting a bit of POP3 VB6 code to VB2005, and have run
into this error with the following code.
>
Can someone help me find out what I'm missing/doing wrong?
>
'holds the attachments
>
snip for brevity, see below...
>
Console.Read()
>
End Sub

I can not explain /this/ error because there is no With statement
in your code. If you got an IndexOutOfRange exception, I would
recommend to create an array that is not empty (Redim statement).
Currently, you have an empty array, but you are trying to access
the first item in the array.
Armin

Thank you for taking the time, this is all a little new for me. I
went back,
and added a redim statement,

Module Module1

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

ReDim AttachBlock(20)

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With

' block variable not set." Error

Console.WriteLine(" Attach Block Type=" &
AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

End Module

The actual error is:

System.NullReferenceException was unhandled
Message="Object variable or With block variable not set."
Source="Microsoft.VisualBasic"

First, enable Option Strict and correct the syntax error. One valid syntax
is

Public AttachBlock As attachmentBlockParameter()

This declares an array variable but it doesn't create an array, yet. The
array is created by the ReDim statement and the reference to the array is
stored in variable AttachBlock.

After using Redim, you can store 21 references (indexes 0 to 20) in the
array. Each item can point to an object of type attachmentBlockParameter.
Currently, all 21 items don't contain references. They are "Nothing". You
must create an object and store the object reference in the array:

AttachBlock(1) = New attachmentBlockParameter

After this you can store values in the object's properties:

AttachBlock(1).cTypeAttach = "Base64"

Note that only the item at index position 1 points to an object. All other
items in the array are still Nothing. You'd have to create objects in a loop
and store them - to be exact, only the object references - in the array.

(Also note that the length of an array can not be changed. If you want to
keep the number of items dynamic, you can also use an Arraylist instead. Or,
starting with VB 2005, there is also a generic List.)
Armin

Sep 25 '07 #4
Now the array is dimensioned to 20, which is good, but each array entry needs
to be initialized to a new object. The array initialization only opens the
array space.

Between the redim and using AttachBlock(1), insert this line:

AttachBlock (1) = New attachmentBlockParameter

Also, it should be noted that AttachBlock(1) is actually the second array
element. AttachBlock(0) is the first.
"Al G" wrote:
>
"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Al G" <ag*******@nospam.charter.netschrieb
Hi,

I'm converting a bit of POP3 VB6 code to VB2005, and have run
into this error with the following code.

Can someone help me find out what I'm missing/doing wrong?

'holds the attachments
snip for brevity, see below...
>
Console.Read()

End Sub

I can not explain /this/ error because there is no With statement in your
code. If you got an IndexOutOfRange exception, I would recommend to create
an array that is not empty (Redim statement). Currently, you have an empty
array, but you are trying to access the first item in the array.
Armin

Thank you for taking the time, this is all a little new for me. I went
back,
and added a redim statement,

Module Module1

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

ReDim AttachBlock(20)

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With

' block variable not set." Error

Console.WriteLine(" Attach Block Type=" & AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

End Module

The actual error is:

System.NullReferenceException was unhandled
Message="Object variable or With block variable not set."
Source="Microsoft.VisualBasic"


Al G
Sep 25 '07 #5
Thank You. This group has been wonderful.

Al G

"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Al G" <ag*******@nospam.charter.netschrieb
>>
"Armin Zingler" <az*******@freenet.dewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Al G" <ag*******@nospam.charter.netschrieb
Hi,

I'm converting a bit of POP3 VB6 code to VB2005, and have run
into this error with the following code.

Can someone help me find out what I'm missing/doing wrong?

'holds the attachments
snip for brevity, see below...
>
Console.Read()

End Sub
I can not explain /this/ error because there is no With statement
in your code. If you got an IndexOutOfRange exception, I would
recommend to create an array that is not empty (Redim statement).
Currently, you have an empty array, but you are trying to access
the first item in the array.
Armin

Thank you for taking the time, this is all a little new for me. I
went back,
and added a redim statement,

Module Module1

'holds the attachments

Class attachmentBlockParameter

Public cTypeAttach As String

Public cEncoding As String

Public cFileName As String

Public cAttachment As String

End Class

Public AttachBlock() = New attachmentBlockParameter() {}

Sub Main()

ReDim AttachBlock(20)

AttachBlock(1).cTypeAttach = "Base64"

' The previous line generates an "Object variable or With

' block variable not set." Error

Console.WriteLine(" Attach Block Type=" &
AttachBlock(1).cTypeAttach)

Console.Read()

End Sub

End Module

The actual error is:

System.NullReferenceException was unhandled
Message="Object variable or With block variable not set."
Source="Microsoft.VisualBasic"


First, enable Option Strict and correct the syntax error. One valid syntax
is

Public AttachBlock As attachmentBlockParameter()

This declares an array variable but it doesn't create an array, yet. The
array is created by the ReDim statement and the reference to the array is
stored in variable AttachBlock.

After using Redim, you can store 21 references (indexes 0 to 20) in the
array. Each item can point to an object of type attachmentBlockParameter.
Currently, all 21 items don't contain references. They are "Nothing". You
must create an object and store the object reference in the array:

AttachBlock(1) = New attachmentBlockParameter

After this you can store values in the object's properties:

AttachBlock(1).cTypeAttach = "Base64"

Note that only the item at index position 1 points to an object. All other
items in the array are still Nothing. You'd have to create objects in a
loop
and store them - to be exact, only the object references - in the array.

(Also note that the length of an array can not be changed. If you want to
keep the number of items dynamic, you can also use an Arraylist instead.
Or,
starting with VB 2005, there is also a generic List.)
Armin

Sep 25 '07 #6

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
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...
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...
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...
16
by: HillBilly | last post by:
This is freaking me out. I'm using Membership and trying to determine if the database is online. The GetConnectionString( ) method returns a connection string as expected but not when used in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.