Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.net - Passing variants by reference when Byref doesn't work in this case - Urgent.

Posted on 2006-11-27
8
Medium Priority
?
480 Views
Last Modified: 2012-05-05
I want to access variants "by reference", because I want to be able to access and modify those variants.  But I haven't found a way to do it yet in the case I am working on.  

I am working with a relatively complex structure of datas. I want to access a particular variant, that is into a sub-structure somewhere, and once I have the right variant, I want to be able to modify it, without having to re-access it every time, since the algorythm to find the variant I want is relatively complex.

My problem : Sorting
-I would like to be able to do something like that :
-In VB.Net 2003

dim Data1 as V_Data1

Public Structure V_Data1
   
    Public Datas2() as V_Data2
    Public NbDatas2 as long
   
    Public function Data2(Index,Sort as boolean) as object
          Data2=Datas2(Index)
          'In fact, this funciton is a lot more complex, because it gets the object needed after sorting all the Datas2()  
               'array in different ways
    End Function

End Structure

Public Structure V_Data2
     Public Name as string
End Structure
   
Public Sub ChangeName
     Data1.Data2(3,SortAscending).Name="YesSir"
End Sub

Thanks,

Gabriel

0
Comment
Question by:gahilo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 18020039
You should probably be using a Class instead of a Structure...
0
 

Author Comment

by:gahilo
ID: 18030853
I have never really worked with Classes before.  I started to change my code to use Classes instead of Structures.  It begin to work, but I am actually stopped by the following problem, that comes back to my original problem : I can’t find a way to work on my original object through another variant that contains my original object.

Here is my problem :

Public Class Class1
      Public Text1 as String
End Class

Public Sub Sub1
      Dim Inst1 as New Class1
      Inst1.Text1=”MyText”
      
      Sub2(Inst1)
End Sub


=>And then, this sub doesn’t work :

Public Sub Sub2(Obj as Object) ‘This is because I want that sub to process many  
                                                 ‘different objects(Instances of different classes)
      Select Case Obj.GetType.Name
            Case “Class1”
                  Msgbox(Obj.Text1) ‘=>I get up to here, but this line doesn’t work
      End Select
End Sub

=>While executing my code, I can see that the variant “Obj” really contains the “Inst1” object, but I don’t find the way to access it

=>If I do the following, it works, but I don’t want to do it

Public Sub Sub2(Obj as Object)
      Dim TempInst as New Class1
      Select Case Obj.GetType.Name
            Case “Class1”
                  TempInst=Obj
                  Msgbox(TempÎnst.Text1)
      End Select
End Sub

Why??????????

Thanks,

Gabriel
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18030895
Do you have Option Strict On?

If you turn it OFF, then it will work...of course when you have a variable declared as "Object", then the Intellisense in the IDE won't be able to tell anything about that object.  It should work at run-time though.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:gahilo
ID: 18030932
Option Strict is already Off
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18031009
It's working for me with VB.Net 2005 Express:

Public Class Form1

    Public Class Class1
        Public Text1 As String
    End Class

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Inst1 As New Class1
        Inst1.Text1 = "MyText"

        Sub2(Inst1)
    End Sub

    Public Sub Sub2(ByVal Obj As Object)
        Select Case Obj.GetType.Name
            Case "Class1"
                MsgBox(Obj.Text1)
        End Select
    End Sub

End Class


I get a MsgBox with "MyText" in it...
0
 

Author Comment

by:gahilo
ID: 18031053
I don't know if it can help...  When I look at the Locals window, here is what I have for the "Obj" and "TempInst" trees.

Name                        Value

-Obj                        {Class1}
  --[Class1]                  {Class1}      =>Why is there this line in the tree??
      --Text1                  MyText

-TempInst                        {Class1}
  --Text1                        MyText
0
 

Author Comment

by:gahilo
ID: 18031178
Forget that problem, I am sometimes stupid...
0
 

Author Comment

by:gahilo
ID: 18031438
Thanks, everything is working now.

Another fast question :

All my classes make a "structure" of data.  I want to show all this information into treeviews.  I already have a code that does that, but I want it to be integrated into my classes that contains all my information, and I want the treeviews to self-modify dynamically, when my objects get modified, without always collapsing.  

In other words, I would like to have something like a property in my classes of data that link the data to it's corresponding treenode, and in the other way, link the treenode to it's corresponding instance of class.  I have tried a lot of things, but haven't found a solution for that up to now.

Do you have a cue for me???

Thanks
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question