cancel
Showing results for 
Search instead for 
Did you mean: 

visa namespace between forms.

markcstephens
Member

visa namespace between forms.

Message contains an image

I am trying to pass visa namespace between forms and I am really stuck!

I cannot figure out why I can see the mainform property from the other form.

Can someone give me a shove in the right direction, Please?

Here is some psuedo code:

namespace instcontrol

class mainform

Public ReadOnly Property OpenedSession() As NationalInstruments.VisaNS.MessageBasedSession
    Get
        Return mbSession
    End Get
End Property

Private Sub btnOpenSession()
...
mbSession = CType(ResourceManager.GetLocalManager().Open(txtSelectedResource.Text), MessageBasedSession)
...
End Sub

Private Sub btnOtherForm()
        Dim Other as OtherForm = New OtherForm
        OtherForm.ShowDialog
EndSub

End Class

Class OtherForm

Private Sub OtherForm_Load()
If Not (InstrumentControl.MainForm.OpenedSession Is Nothing) Then
        PopulateSessionTreeView()
Else
       
Me.Close()
End If
End Sub

End Class

End Property

3 REPLIES 3
Highlighted
MissyS
Member

Re: visa namespace between forms.

Message contains an attachment
Attached is an example that shows passing strings across forms. It is done for VISA resource names in the Simple Write Read example, located in the following folder.
C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\Visa\SimpleReadWrite\VB
 
Check to see if your variable is public or private. In the Class View, you should see a lock if the variable is only accessible in its owning form. In the attached example, I declared a variable, PublicVariable, as public. You should be able to access it from Form1 (it is declared in Form2). The variable, TestVar, is private and is accessed to change values for the form using a property. It is not directly accessible by Form1 (it is also declared in Form2), but can be accessed through the public method. I hope this helps!
 
Regards,
Missy S.
Project Engineer
RoviSys
markcstephens
Member

Re: visa namespace between forms.

I did find another way to do it, and after seeing your example it all made perfect sense to this poor old vb6 programmer Smiley Happy

I did it my way comes to mind here, but your way is much simpler and elegant.

My Way:

Class Main

 
Public ReadOnly Property OpenedSession() As NationalInstruments.VisaNS.MessageBasedSession
    
Get
         
Return mbSession
    
End Get
 
End Property

  Private Sub btnBrowseVisaNS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseVisaNS.Click
    
Dim BrowseVisaNS As BrowseVisaNSForm = New BrowseVisaNSForm
     BrowseVisaNS.Owner =
Me
    
BrowseVisaNS.ShowDialog()
  End Sub
End Class

Class BrowseVisaNS
  
  Dim mbsession As MainForm
 
 
Private Sub BrowseVisaNS_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
mbsession = Me.Owner
    
If Not (mbsession.OpenedSession Is Nothing) Then
         
PopulateSessionTreeView()
    
Else
         
Me.Close()
    
End If
 
End Sub

End Class

Your Way:

.ShowDialog(Me)

Much less typing Smiley Happy

Thanks for pointing me in the right direction with that one, I would have wandered around aimlessly for days before figuring it out!

 

MissyS
Member

Re: visa namespace between forms.

Glad I could help! Happy programming! Smiley Happy
 
Regards,
Missy S.
Project Engineer
RoviSys