Sign in to follow this  
gamechampionx

VB.net question

Recommended Posts

gamechampionx    140
I have, on a form called main: Public mainMenu As System.Windows.Forms.MainMenu . Then, I have a module called methods, with the following code: Private parent As System.Windows.Forms.Form ... Public Sub addMenu() MainMenu = New System.Windows.Forms.MainMenu ... End Sub ... Public Sub setParent(ByVal newParent As System.Windows.Forms.Form) parent = newParent End Sub In main: Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load methods.setParent(Me) ... methods.addMenu() End Sub How can I access mainMenu from the module? Despite being public, it does not show up in attribute lists for main or parent.

Share this post


Link to post
Share on other sites
alexmoura    450
You should be able to access parent.mainMenu in your module, inside method declarations - I've just tried it out and it works. Assuming you were checking for intellisense inside a method in the module the only other thing I can suggest is checking that the designer hasn't changed the access of mainMenu to protected or private.

Share this post


Link to post
Share on other sites
gamechampionx    140
OK, it still didn't work on my pc, but I changed my prog so it doesn't matter.

On a site note, how does one check the length of different dimensions of a 2d array in VB.net? The length of a 10 X 10 array is considered 100, and I can't find any methods that deal with the dimensions separately.

Share this post


Link to post
Share on other sites
alexmoura    450
Not sure if this is what you want:


Module Module1

Sub Main()
Dim arr(5, 10) As Integer
'first dimension
Console.WriteLine(UBound(arr, 1))
'second dimension
Console.WriteLine(UBound(arr, 2))
End Sub

End Module

Share this post


Link to post
Share on other sites
Sko44    144
Its a long time since I used vb.net but I wrote a little function to compute all the items in a multidimensional array here.



Module Module1
Public Function GetTotalItems(ByVal objects As Array) As Integer

Dim i As Integer

' Since multiplying with zero is not very helpfull we cheat
' by getting rank 1 manually outside the for loop.
GetTotalItems = objects.GetLength(0)

For i = 1 To objects.Rank - 1
' here we multiply by rank to get the total items.
GetTotalItems *= objects.GetLength(i)
Next

End Function
End Module




To test the code to as this


Module ModMain
Sub Main()

' test array
Dim testArray(,,,) As Byte

' resetting the size.
ReDim testArray(10 - 1, 10 - 1, 10 - 1, 10 - 1)

' writing out total array length.
Console.Out.WriteLine("Items : " + Module1.GetTotalItems(testArray).ToString())

End Sub
End Module


Share this post


Link to post
Share on other sites
alexmoura    450
I thought that hadn't changed:


Module Module1

Sub Main()
Dim arr(5, 10) As Integer
'first dimension
Console.WriteLine(UBound(arr, 1))
'second dimension
Console.WriteLine(UBound(arr, 2))

for i as integer = 0 to ubound(arr,1)
for j as integer = 0 to ubound(arr,2)
Console.Writeline(arr(i,j))
next
next

End Sub

End Module

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this