Solved

Newbie ByRef Sub question

Posted on 2003-11-13
3
276 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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

13 Experts available now in Live!

Get 1:1 Help Now