Solved

Newbie ByRef Sub question

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

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