|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Clearing a custom arrayInstead 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 "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: What exactly is not working?> 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. \\\ 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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:utn51oWcGHA.3484@TK2MSFTNGP03.phx.gbl... > "Adam Honek" <AdamHo***@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/> When I try declare it as "New" it simply says arrays cannot be delcared with
the "New" keyword. Adam Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:utn51oWcGHA.3484@TK2MSFTNGP03.phx.gbl... > "Adam Honek" <AdamHo***@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/> "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: I suggest to post some code. Are you using VB6 or VB.NET? Note that this > When I try declare it as "New" it simply says arrays cannot be delcared > with the "New" keyword. 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/> 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 Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:OaIeNEccGHA.380@TK2MSFTNGP04.phx.gbl... > "Adam Honek" <AdamHo***@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/>
Show quote
Hide quote
"Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: The variable 'a' is not an array variable. As said previously, you may want > 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? 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/> 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 ) :-) RegardsMichel Posseth [MCP] Show quoteHide quote "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht news:emtbd%23VcGHA.3856@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 > This seems to work but is it not the same as saying here is a null pointer
to this array? Adam Show quoteHide quote "Michel Posseth [MCP]" <mic***@posseth.com> wrote in message news:uXn7oAecGHA.4932@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" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht > news:emtbd%23VcGHA.3856@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 >> > > 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] Show quoteHide quote "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht news:%23G1FZRfcGHA.2456@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]" <mic***@posseth.com> wrote in message > news:uXn7oAecGHA.4932@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" <AdamHo***@Webmaster2001.freeserve.co.uk> schreef in bericht >> news:emtbd%23VcGHA.3856@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 >>> >> >> > > "Michel Posseth [MCP]" <mic***@posseth.com> schrieb: It's true for reference types (arrays for example), but 'Nothing' has a > Yes it is the same as assigning null in C# ( C# Null = VB.Net > Nothing ) meaning for value types in VB.NET too. > It will efectively clear all the elements and is much faster as other Depends on how to define "clearing an array". Based on my understanding the > methods 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/> Herfried,
You mean something as Dim myString(100) as String For each myStr as String in MyString myStr = Nothing Next :-)) CorShow quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht news:u8xEHbgcGHA.4892@TK2MSFTNGP02.phx.gbl... > "Michel Posseth [MCP]" <mic***@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/> Cor,
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: Why not just use 'Array.Clear' as shown for this purpose?> You mean something as > > Dim myString(100) as String > For each myStr as String in MyString > myStr = Nothing > Next > > :-)) -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb: I just tried to show the difference and use of "IS" and "=" with the word >> 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? > > -- 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
'OpenFileDialog crashes for no reason?
SMTP won't send until thread terminates How getting eventhandler attached to an event? Which one is the Bluetooth DLL? regular expressions ADODB custom wrapper Silly combo box question Threading so restricted? Win32API - FindFirstFile() in VB.NET Text into HTML |
|||||||||||||||||||||||