Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
US
i want my program to pop up a form that asks information like you name and such. then i want this information to be placed in other parts of code in my program. i dont know much about how to use variables, so can anyone help me out?
 
Hello !
First of all you must save you info you can do it with variables, with property of controls
if u wnat to use variables u must declare them as Public
for example
Public x as integer
and after this declaration u can use variable x in all parts of program
or u can use property of control. I guess user fill some text and other info into the controls and then u hide a form but u dont unload it and thus u can use form and all control on it
its easy
Sage


 
I think the best way to do this is to use a user defined type variable for your user details, then set a variable with global scope of type "user" and then you can access any of the user details from anywhere in your project.

I would do this by:
1) In a module put the following code:
Option Explicit

Public Type udtUser
Name As String
Age As Integer
Gender As String
' change the details of the user accordingly
End Type

Global uUser As udtUser

2) Set up your "user details" form to set the properties of your 'user' variable -
eg create a form with tree text boxes - Text1(0), Text1(1) and Text1(2) - and paste this code into the module:
Option Explicit

Private Sub Form_Load()

Text1(0).Text = uUser.Name
Text1(1).Text = uUser.Age
Text1(2).Text = uUser.Gender

End Sub

Private Sub Text1_Change(Index As Integer)

Select Case Index
Case 0
uUser.Name = Text1(Index).Text
Case 1
uUser.Age = Val(Text1(Index).Text)
Case 2
uUser.Gender = Text1(Index).Text
End Select

End Sub

3) From anywhere in your project you can now access user information by querying:
uUser.Name
uUser.Age
uUser.Gender

Hope this helps.

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top