Solved

Newbie ByRef Sub question

Posted on 2003-11-13
3
277 Views
Last Modified: 2010-05-03
VB.NET 2002

Form1.vb launches a custom dialog box form, Age.vb, to say ask for the users age:

frmAge = New Age(UserAge)
frmAge.Show
MsgBox("Hey you are: " & UserAge)

In Age.vb we have:

Public Sub New(ByRef UsersAge As Integer)
     MyBase.New()
     InitializeComponent()
End Sub

a TextBox1 where they enter their age and a Button_OK to exit the dialog

When the user presses the OK button I can validate the entry they put in the TextBox1 but I do not know how to get the entry from TextBox1 to pass back when the user presses OK because the variable "UsersAge" is local to the Sub "New" only.

How do I make it global so I can change it and pass it back?

If I try the following in the event handler for Button_OK.Click  :

UsersAge = CInt(TextBox1.Text)
Me.Close

I of course get a: Name 'UsersAge' is not declared , complaint from the IDE.

Thanks.

0
Comment
Question by:Craig_Sparks
3 Comments
 
LVL 2

Accepted Solution

by:
MaxPol earned 125 total points
ID: 9738397
Hi,

Try this:
In form1.vb, create a label called Agelbl
In the Age form, in the button, do the following:
sub Command1_OnClick()
form1.Agelbl.caption=text1.text
end sub

Agelbl.caption=""
frmAge = New Age
frmAge.Show 1 ' it should be modal or the next line will be executed immediatly after showing the form
MsgBox("Hey you are: " & Agelbl)

Hope it helps,

Max
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9739128
Define a global variable some where and use this global variable

0
 

Author Comment

by:Craig_Sparks
ID: 9741024
I was showing the dialog as non modal, so the modal thing fixed being able to read from it on return.

I tried the global thing at first but I can't seem to figure out how to make a global that spans all forms.

Public Shared VarName

atop form1

just gets me 'not declared' in all other forms.

Thanks all.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now