469,913 Members | 2,683 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

Clearing a custom array

Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.

Any suggestions?

Thanks,
Adam
May 6 '06 #1
13 2655
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.


What exactly is not working?

\\\
Private Structure Test
Public Name As String
Public Number As Integer

Public Sub New( _
ByVal Name As String, _
ByVal Number As Integer _
)
Me.Name = Name
Me.Number = Number
End Sub
End Structure
....
Dim a() As Test = _
{ _
New Test("Hello", 12), New Test("Bla", 2) _
}
Array.Clear(a, 0, a.Length)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 7 '06 #2
Hmmm,

It's not a VB.NET array.

It's a structure (VB6 Type) that gets put into an array hence:

Structure HelloWorld
dim Message as string
dim date as string
end structure

public LetsTry as HellowWorld()

It will compile as below but fall over when it tries to run that code:

'Before we start filling the email accounts array lets make sure it's nice
and clean
Array.Clear(LetsTry, 0, LetsTry.Length)

I guess it's because I'm not doing the {} array format your example below
shows.

Adam

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.


What exactly is not working?

\\\
Private Structure Test
Public Name As String
Public Number As Integer

Public Sub New( _
ByVal Name As String, _
ByVal Number As Integer _
)
Me.Name = Name
Me.Number = Number
End Sub
End Structure
...
Dim a() As Test = _
{ _
New Test("Hello", 12), New Test("Bla", 2) _
}
Array.Clear(a, 0, a.Length)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #3
When I try declare it as "New" it simply says arrays cannot be delcared with
the "New" keyword.

Adam

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.


What exactly is not working?

\\\
Private Structure Test
Public Name As String
Public Number As Integer

Public Sub New( _
ByVal Name As String, _
ByVal Number As Integer _
)
Me.Name = Name
Me.Number = Number
End Sub
End Structure
...
Dim a() As Test = _
{ _
New Test("Hello", 12), New Test("Bla", 2) _
}
Array.Clear(a, 0, a.Length)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #4
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
When I try declare it as "New" it simply says arrays cannot be delcared
with the "New" keyword.


I suggest to post some code. Are you using VB6 or VB.NET? Note that this
group is dedicated to VB.NET programming.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #5

maybe to simple ..... but why do you not assign a Nothing pointer ??? to the
var to clear it`s contents ( should work in VB6 and VB.Net )

:-)

Regards

Michel Posseth [MCP]
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:em****************@TK2MSFTNGP03.phx.gbl...
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.

Any suggestions?

Thanks,
Adam

May 7 '06 #6
This seems to work but is it not the same as saying here is a null pointer
to this array?

Adam

"Michel Posseth [MCP]" <mi****@posseth.com> wrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...

maybe to simple ..... but why do you not assign a Nothing pointer ??? to
the var to clear it`s contents ( should work in VB6 and VB.Net )

:-)

Regards

Michel Posseth [MCP]
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:em****************@TK2MSFTNGP03.phx.gbl...
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.

Any suggestions?

Thanks,
Adam


May 7 '06 #7
This is all VB.NET 2005, no VB6.

Basically:

Public Structure EmailAccount
Dim sDesiredName As String

Dim sPOP3Server As String

Dim sSMTPServer As String

Dim sAccountName As String

Dim sAccountPassword As String

Dim sUserName As String

Dim sEmailAddress As String

End Structure

And then:

Dim a as EmailAccount.

How does one remove an entry from this array?

Adam
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oa*************@TK2MSFTNGP04.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
When I try declare it as "New" it simply says arrays cannot be delcared
with the "New" keyword.


I suggest to post some code. Are you using VB6 or VB.NET? Note that this
group is dedicated to VB.NET programming.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #8
Yes it is the same as assigning null in C# ( C# Null = VB.Net
Nothing )

It will efectively clear all the elements and is much faster as other
methods

regards

Michel Posseth [MCP]

"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:%2****************@TK2MSFTNGP04.phx.gbl...
This seems to work but is it not the same as saying here is a null pointer
to this array?

Adam

"Michel Posseth [MCP]" <mi****@posseth.com> wrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...

maybe to simple ..... but why do you not assign a Nothing pointer ??? to
the var to clear it`s contents ( should work in VB6 and VB.Net )

:-)

Regards

Michel Posseth [MCP]
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schreef in bericht
news:em****************@TK2MSFTNGP03.phx.gbl...
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?

The .clear isn't a member of it by default.

Any suggestions?

Thanks,
Adam



May 7 '06 #9
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Public Structure EmailAccount
Dim sDesiredName As String

Dim sPOP3Server As String

Dim sSMTPServer As String

Dim sAccountName As String

Dim sAccountPassword As String

Dim sUserName As String

Dim sEmailAddress As String

End Structure

And then:

Dim a as EmailAccount.

How does one remove an entry from this array?


The variable 'a' is not an array variable. As said previously, you may want
to use 'System.Collections.ArrayList' or 'System.Collections.Generic.List(Of
EmailAccount)' instead of the array.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #10
"Michel Posseth [MCP]" <mi****@posseth.com> schrieb:
Yes it is the same as assigning null in C# ( C# Null = VB.Net
Nothing )
It's true for reference types (arrays for example), but 'Nothing' has a
meaning for value types in VB.NET too.
It will efectively clear all the elements and is much faster as other
methods


Depends on how to define "clearing an array". Based on my understanding the
OP didn't want to remove the items from the array, he wanted to reset them
to their default values.

In addition, I suggest to check out the 'Erase' keyword :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 7 '06 #11
Herfried,

You mean something as

Dim myString(100) as String
For each myStr as String in MyString
myStr = Nothing
Next

:-))

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:u8**************@TK2MSFTNGP02.phx.gbl...
"Michel Posseth [MCP]" <mi****@posseth.com> schrieb:
Yes it is the same as assigning null in C# ( C# Null = VB.Net
Nothing )


It's true for reference types (arrays for example), but 'Nothing' has a
meaning for value types in VB.NET too.
It will efectively clear all the elements and is much faster as other
methods


Depends on how to define "clearing an array". Based on my understanding
the OP didn't want to remove the items from the array, he wanted to reset
them to their default values.

In addition, I suggest to check out the 'Erase' keyword :-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 8 '06 #12
Cor,

"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
You mean something as

Dim myString(100) as String
For each myStr as String in MyString
myStr = Nothing
Next

:-))


Why not just use 'Array.Clear' as shown for this purpose?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 8 '06 #13
> "Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
You mean something as

Dim myString(100) as String
For each myStr as String in MyString
myStr = Nothing
Next

:-))


Why not just use 'Array.Clear' as shown for this purpose?

--

I just tried to show the difference and use of "IS" and "=" with the word
Nothing,

I even would not think about using what I was showing, even if there was not
an Array.Clear I would instance a new array at the same address myself. I
never look at ILS, but I just think that this is in fact happening with
Array.Clear.

Cor
May 8 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Terry Andersen | last post: by
10 posts views Thread by Liz - Newbie | last post: by
13 posts views Thread by Michael Kennedy [UB] | last post: by
65 posts views Thread by Steven Watanabe | last post: by
2 posts views Thread by J R M | last post: by
3 posts views Thread by Martin | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.