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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Variable not working

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
I have a public variable with the values being set on my loggin screen with the following code

SELECT user_setup
LOCAL myglobalclass
username = ALLTRIM(Thisform.User_name.Value)
userdepartment = ALLTRIM(Thisform.department.Value)


LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
Thisform.Release()
DO FORM current_user

ELSE
MESSAGEBOX("The User Name or Password is incorrect.","Please try again.")
Thisform.password.Value = ""
Thisform.user_name.SETFOCUS
ENDIF



In my main prg I declare the values

oGlobal = CREATEOBJECT('myGlobalClass')
Public myGlobalClass
DEFINE CLASS myGlobalClass AS CUSTOM
username =""
userdepartment =""
ENDDEFINE


When the current_user form loads if I click the button on the form for change password i have to first click in the current_user field to retrieve the value. For some reason it shows it but i have to click the field first.

When the current_user form load if I click the menu bar it gives me the error userdepartment not found then if i click the userdepartment field on the current user form first it shows only the values in the menu for the department.

So my values work, I just need to click the fields first. The two fields on the current user form have thier values being set by the varialbes. Why will it set them here and then make me click the fields before it will allow others to use them
 
LOCAL myglobalclass makes the class LOCAL. In other words, you have a public version, and another version that is local to the form. Try this:

myglobalclass.username = ;
ALLTRIM(Thisform.User_name.Value)
myglobalclass.userdepartment = ;
ALLTRIM(Thisform.department.Value)
Dave S.
 
it says myglodalclass is not an object. Yeah I changed the local to public, I noticed it after rereading this post. Still doesnt work though.
 
yeah but the public one is the one setting the form values. So it sets those fine, its when you go to run them in ex. menu bar skips and stuff.
 
If your login form is running before the main.prg. It looks like you have your myglobalclass declared as local. then in main you now decalare it as public. you need to run main.prg first and in there make your class public and declare the var's.
Attitude is Everything
 

oGlobal = CREATEOBJECT('myGlobalClass')
Public myGlobalClass
DEFINE CLASS myGlobalClass AS CUSTOM
username =""
userdepartment =""
ENDDEFINE


This is wrong, it should be:
Code:
Public oGlobal
oGlobal = CREATEOBJECT('myGlobalClass')
DEFINE CLASS myGlobalClass AS CUSTOM
   username =""
   userdepartment =""
ENDDEFINE

And the idea, is to store the "found" passwords and usernames in the oGlobal object, from the login screen:
Code:
IF FOUND()
  oGlobal.username = users.username && Or whatever the name of your login table is.
  oGlobal.userdepartment = users.departement
ENDIF
 
the idea is to store the user_name to username and thier department to userdepartment
 
the idea is to store the user_name to username and thier department to userdepartment

Which are properties of the oGlobal object, hence you store
them in the oGlobal object:
IF FOUND()
oGlobal.username = users.username && Or whatever the name of your login table is.
oGlobal.userdepartment = users.departement
ENDIF

 
NEW APPROUCH ON THIS TOPIC....


How would you recommend passing a username and department through out a program. Currently I have my main.prg with the following code in it


_SCREEN.WindowState = 2
_SCREEN.Caption = ""
_SCREEN.BackColor = 8421504
SET NULLDISPLAY TO "Unknown"
ON SHUTDOWN quit
SET MESSAGE TO ""
SET SYSMENU OFF
DO FORM login_screen
READ EVENTS
******By: Ryan J. Lashway
******A.K.A Jester4281
Public oGlobal
oGlobal = CREATEOBJECT('myGlobalClass')
DEFINE CLASS myGlobalClass AS CUSTOM
username =""
userdepartment =""
ENDDEFINE


From there it brings you to the login in form with this code in the command button


PUBLIC myglobalclass

LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
username = user_setup.user_name
userdepartment = user_setup.department
Thisform.Release()
DO FORM current_user

ELSE

MESSAGEBOX("The User Name or Password is incorrect.","Please try again.")
Thisform.password.Value = ""
Thisform.user_name.SETFOCUS
ENDIF

If all info checks fine you go to the form current user. This is to show what user is logged in. From here the user can change thier password by clicking the admin button with this code in it

DO FORM account_info

In account info the INIT has this

SET EXACT ON
SELECT user_setup
SET FILTER TO user_setup.user_name = username
LOCATE FOR user_setup.user_name = username
This.Caption = username


While this is all happening I need the user to be able to select the menu that is filtered by the skip event to only match thier department.

AT PRESENT THEY ALL WORK IF YOU CLICK IN BOTH THE USERNAME FIELD AND DEPARTMENT FIELD ON CURRENT USER FORM. I NEED IT TO NOT HAVE TO BE CLICKED.
 
PUBLIC myglobalclass && This is not required

LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
oGlobal.username = user_setup.user_name This should read
oGobal.userdepartment = user_setup.department This should read
Thisform.Release()
DO FORM current_user

ELSE

MESSAGEBOX("The User Name or Password is incorrect.","Please try again.")
Thisform.password.Value = ""
Thisform.user_name.SETFOCUS
ENDIF

You should only load your menu after a successfull login, that way they will not have access to any menu until they are logged in. And since you are using a global object to store the username and departement, if you want to limit the menu items you have to refer to the oGobal.departement property, something like (in the skip for)
oGlobal.departement <> &quot;IT&quot; && This will skip the pad if the value is not equal to IT.
 
When I try to load the menu after it doesnt show before i has DO toq.mpr in there if statement and it wouldnt show anything
 
the code returns object global is not found
 

the code returns object global is not found



Public oGlobal && are you talking about oGlobal?
oGlobal = CREATEOBJECT('myGlobalClass')
DEFINE CLASS myGlobalClass AS CUSTOM
username =&quot;&quot;
userdepartment =&quot;&quot;
ENDDEFINE
 
in the login button the

LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
oGlobal.username = user_setup.user_name This should read
oGlobal.userdepartment = user_setup.department This should read
Thisform.Release()
DO FORM current_user


is giving error when it hits the oGlobal saying it cannot find the object
 
>is giving error when it hits the oGlobal saying it cannot find the object

LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
SET STEP ON && Use the debugger to see if if oGlobal exist here
oGlobal.username = user_setup.user_name This should read
oGlobal.userdepartment = user_setup.department This should read
Thisform.Release()
DO FORM current_user

 
returns no values for the oglobal.username but it does for the record user_setup.user_name
 
try:
STORE ALTTRIM(user_setup.user_name) TO oGlobal.username
STORE ALLTRIM(user_setup.department) TO oGlobal.userdepartment
And put the SET STEP ON right after and see if you get a value in the oGlobal.username
 
still not showing a value in the oglobal, any idea why
 
Yes, it's very strange because if you create a small program with this:
Code:
PUBLIC oGlobal
oGlobal = CREATEOBJECT('myGlobalClass')
STORE ALLTRIM(&quot;IT   &quot;) TO oGlobal.userdepartment
STORE ALLTRIM(&quot;Mike   &quot;) TO oGlobal.username
messagebox(TRANSFORM(oglobal.userdepartment))
messagebox(TRANSFORM(oglobal.username))
DEFINE CLASS myGlobalClass AS CUSTOM
   username =&quot;&quot;
   userdepartment =&quot;&quot;
ENDDEFINE
Which is the same as you use I get two messagebox showing the correct values.
Try something else:
LOCATE FOR UPPER(user_setup.user_name) = UPPER(ALLTRIM(Thisform.User_name.Value))
IF FOUND() AND ALLTRIM(user_setup.password) = ALLTRIM(Thisform.password.Value)
BROWSE && try a browse window and see if you have the right record and there is info in the fields.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top