• 0

VB.NET - How do I use pointers to pointers (if even possible)


Question

Hi

I want to use the New function for an object with array of objects as parameters something like this - 

Sub New(varPar () as Object)

End Sub

In my Class I have several objects that can be initialized.

I'm trying to make a the code general so the calling code will put in the varPar array the objects it wants to init and I will use something like this - 

Dim obj1 as <type1>

Dim obj2 as <type2>

.

.

.

dim objN as <typeN>

 

Sub New(varPar () as Object)

 if  varPar is nothing then

      return

end if       

if varPar.Length > 0 then

      obj1 = varPar(0)

if varPar.Length > 1 then

      obj1 = varPar(1)

 etc...      

End Sub

 

I want to do that in a loop like this

Dim obj1 as <type1>

Dim obj2 as <type2>

.

.

.

dim objN as <typeN>

dim varArray() as object = { obj1,obj2,obj3.......objN}

 

Sub New(varPar () as Object)

 if  varPar is nothing then

      return

end if       

for i = 0 to varPar.Lentgh -1 

      varArray(i) = varPar(i)

next

End Sub

 

This will init the varArray but not obj1 obj2 obj3 etc.

Does anyone know how I can achieve this?

It is trivial in C, but in VB I don't know if it is possible or not.

Thanks

3 answers to this question

Recommended Posts

  • 0
  On 05/07/2018 at 11:29, Ophir said:

Hi

I want to use the New function for an object with array of objects as parameters something like this - 

 

<snipped>

 

This will init the varArray but not obj1 obj2 obj3 etc.

Does anyone know how I can achieve this?

It is trivial in C, but in VB I don't know if it is possible or not.

Thanks

Expand  

I'm not sure I fully understand the question. So here are some questions of my own :)

 

The array injected in the constructor always has the same amount of elements as the internal array?

Are you trying to make each element of the internal array point to the corresponding element of the array injected in the constructor?

 

Could you maybe tell us which problem this construction is trying to solve? There might be a more efficient way of doing that in VB.NET.

  • 0
  On 05/07/2018 at 12:10, Raphaël G. said:

I'm not sure I fully understand the question. So here are some questions of my own :)

 

The array injected in the constructor always has the same amount of elements as the internal array?

Are you trying to make each element of the internal array point to the corresponding element of the array injected in the constructor?

 

Could you maybe tell us which problem this construction is trying to solve? There might be a more efficient way of doing that in VB.NET.

Expand  

The Array injected does not have to have the same amount of elements as the internal one.

I want to initialize the class variables obj1 obj2 obj3 etc in a loop instead of one by one while checking the Injected Array length.

 

In C I will put the Address of obj1 obj2 obj3 etc in the Internal Array and do something like this

 

void *varArray[] = { &obj1, &obj2, &obj3......&objN}

 

for(i = 0; i < <Injected Array>.length; i++)

{

        *varArray=varPar;    //By that I actually Initializing obj1, obj2, obj3 etc

}

 

I hope it is clearer now.

 

Do not know why when I submit the square parenthesis are removed.

Edited by Ophir
  • 0
  On 05/07/2018 at 14:35, Ophir said:

The Array injected does not have to have the same amount of elements as the internal one.

I want to initialize the class variables obj1 obj2 obj3 etc in a loop instead of one by one while checking the Injected Array length.

 

In C I will put the Address of obj1 obj2 obj3 etc in the Internal Array and do something like this

 

void *varArray[] = { &obj1, &obj2, &obj3......&objN}

 

for(i = 0; i < <Injected Array>.length; i++)

{

        *varArray=varPar;    //By that I actually Initializing obj1, obj2, obj3 etc

}

 

I hope it is clearer now.

 

Do not know why when I submit the square parenthesis are removed.

Expand  

If I'd convert what you posted here into vb.net, :

 

 

Dim list() As String = {"something", "something2"}


            For Each item In list

                'Then simply call the item

            Next

 

If you want to track each item, I usually make my own classes, for example let's say a standard name/value keypair:

 

Public class NameValueKeyPair

        public name as string

        public value as string

end class

 

Then, in a sub/function:

 

dim NameValueKeyPairList as new list(of NameValueKeyPair)

Dim NameValueKeyPair as new NameValueKeyPair

NameValueKeyPair.name = "name"

NameValueKeyPair.value = "value"

Namevaluekeypairlist.add(namevaluekeypair)

 

Do that in a loop, and then you can loop through the list to find what you need, for example:

 

For each item in NameValueKeyPairList

      If item.name = "name" then

             'Found it!

      End if

Next

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • With Sony basically owning EVO, this device isn't that big of a surprise. Though I'm sure the price tag will be, we'll see.
    • wtf are you talking about... kinda ironic of you saying it looks dumb because you clearly have problems with your eyes. I get that you misread FIGHT as FLIGHT but how can you look at the actual device and still think it has anything to do with planes... have you never seen an arcade cabinet?
    • I don't usually complain about articles here, but this is just ridiculous, you couldn't ask your precious AI to write something about tech instead? This literally has nothing to do with tech.
    • Microsoft's "Athena" AI: A blueprint for your own dev team's productivity boost by Paul Hill Last month, Microsoft made many developer-oriented announcements at its annual BUILD conference. One of the tools that it announced at the time was called Athena, an artificial intelligence agent that lives in Microsoft Teams and aims to speed up product development processes. Now, however, Microsoft has released the blueprint of Athena so anyone can begin implementing a similar helper for their work. Rather than just another chatbot, Athena is a deeply integrated agent accessible through Teams that helps to connect people, tools, and data throughout the product development process. Athena is smart enough to work out what needs to happen next and helps team members get it done without having to go to different applications - Athena controls it all from Teams and you just have to communicate in natural language. Athena can be embedded in several developer workflows including Teams, Azure DevOps, and GitHub. Perhaps the greatest thing about Athena is that it’s not a new product being sold by Microsoft, but rather a methodology and open-source template (Dex) that organizations or individuals can take to build their own AI agents, allowing for more customization. To get started with Athena, you'll want to set up the Dex agent. Microsoft has also published a breakout session video about Athena so you can take a deeper dive. Who it affects, and how The primary beneficiaries of Microsoft’s decision to release Athena open source are engineering teams everywhere who will be freed from boring, repetitive tasks such as pull request (PR) reviews, work item management, and security checks. This will let them get on with coding new features and innovating - something that Microsoft has been pushing hard for since the start of the latest AI revolution. For product managers and engineering leaders, Athena also looks set to be incredibly useful as they will get better real-time visibility into the status of projects, if a release is truly ready for launch, and to ensure the team is aligned. Organizations from small to large will be able to benefit from using Athena. Due to its open-source nature, Athena can be tailored to meet specific development processes. This could unlock faster delivery cycles and improve code quality across the board. Why it's happening Athena is already being used internally at Microsoft by over 2,000 of its engineers. The Redmond giant explained that this has led to “measurable gains” in speed, quality, and focus. Aside from faster review cycles for developers, Athena is also surfacing release-blocking bugs earlier, enabling the consistent completion of security and privacy workflows, and providing quicker health assessments so that teams can gauge the overall health of their software delivery. By handling all these more boring tasks, Athena can free up developers to build more features into their projects. It also has the potential to speed up delivery times so that end users can use the new software faster, and with potentially less bugs. We often hear the term “democratization” in tech, a process that makes technologies more accessible and affordable. According to this definition, Microsoft’s release of Athena delivers on democratizing AI for developers as its open source and allows people to integrate AI Into their workflows, without starting from scratch. The move also aligns with Microsoft's AI strategy, that is, putting it all throughout its products. Copilot is probably the most notorious for its omnipresence in essentially every Microsoft product including Windows and Edge. Unlike Copilot, developers get a bit more freedom with Athena, but it’s still tied up with Microsoft products, namely Teams and GitHub. Caveats and what to watch for While it’s great that Microsoft is making its Athena blueprint accessible, one issue is that developers may still find it a bit complex to implement as there are still specific customizations organizations will want to make. Additionally, this solution involves a more involved setup process as outlined in the GitHub README. Another thing organizations should be wary about is data privacy and security implications when it comes to integrating with sensitive internal systems. Organizations that are working on secretive projects probably wouldn’t want to use Athena as this could put sensitive code in the hands of third parties. It’s not only technical issues that need considering either, there is also the human element. Some people may have concerns about AI hallucinating or ethical concerns around job security that could hurt adoption. To this end, Microsoft has reaffirmed that Athena is supposed to assist teams only, not replace team members. While Athena can be extremely useful, as shown by the results internally at Microsoft, human oversight and judgment will still be vital. Complex decision and creative problem-solving in development are some areas where a human still needs to be involved. Source: Microsoft
  • Recent Achievements

    • First Post
      James courage Tabla earned a badge
      First Post
    • Reacting Well
      James courage Tabla earned a badge
      Reacting Well
    • Apprentice
      DarkShrunken went up a rank
      Apprentice
    • Dedicated
      CHUNWEI earned a badge
      Dedicated
    • Collaborator
      DarkShrunken earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      383
    2. 2
      +FloatingFatMan
      176
    3. 3
      ATLien_0
      169
    4. 4
      snowy owl
      169
    5. 5
      Xenon
      133
  • Tell a friend

    Love Neowin? Tell a friend!