alix
Junior Member
Posts: 57
|
Post by alix on Jan 20, 2008 6:09:02 GMT -5
With RB, functions cannot have any wait command in them. So instead of creating a function, I thought of using the RUN command instead. I have the main project as follow :
run "UserValidation", #v render #v
And the called project "UserValidation":
' ' Variables and arrays ' global ThisUser$ usertot=4 dim user$(usertot,2) user$(1,1)="me" user$(1,2)="a" user$(2,1)="you" user$(2,2)="b" user$(3,1)="us" user$(3,2)="c" user$(4,1)="them" user$(4,2)="d" userok=0 userno=0 ' ' Check username ' [ValidUserCheck] cls input "Username";username$ for i=1 to usertot if username$ = user$(i,1) then userno=i userok=1 exit for end if next ' ' Check password ' if userok = 0 then cls print "Invalid username" goto [ValidUserCheck] else userok=0 cls print "Password ?" print passwordbox #pw, "" link #action, "Submit", [ValidPasswordCheck] wait end if [ValidPasswordCheck] pass$= #pw CONTENTS$() if pass$ = user$(userno,2) then print print print "**** welcome ";username$;" !" ThisUser$="ok" else goto [ValidUserCheck] ThisUser$="nogood" end if wait
My problem is that I don't know how to tell the main project if the user has been validated or not. How do I return the variable ThisUser$ to the main project ?
|
|
|
Post by Jerry Muelver on Jan 20, 2008 7:55:17 GMT -5
You could do it the way we did back in the days of 16k memory boards -- have the module write the value out to a file, and the main program read the file when the module is done.
|
|
alix
Junior Member
Posts: 57
|
Post by alix on Jan 21, 2008 12:13:42 GMT -5
ok, good idea But when I try it, it does not work Here the main project : run "UserValidation", #v render #v open DefaultDir$ + "\public\validation.txt" for input as #f line input #f, a$ close #f print print "validation =";a$ wait and here is the called UserValidation project: '
' Variables and arrays
'
global DefaultDir$ 'bug in RB to be fixed
usertot=4
dim user$(usertot,2)
user$(1,1)="me"
user$(1,2)="a"
user$(2,1)="you"
user$(2,2)="b"
user$(3,1)="us"
user$(3,2)="c"
user$(4,1)="them"
user$(4,2)="d"
userok=0
userno=0
'
' Check username
'
[ValidUserCheck]
cls
input "Username";username$
for i=1 to usertot
if username$ = user$(i,1) then
userno=i
userok=1
exit for
end if
next
'
' Check password
'
if userok = 0 then
cls
print "Invalid username"
goto [ValidUserCheck]
else
userok=0
cls
print "Password ?"
print
passwordbox #pw, ""
link #action, "Submit", [ValidPasswordCheck]
wait
end if
[ValidPasswordCheck]
pass$= #pw CONTENTS$()
if pass$ = user$(userno,2) then
ThisUser$="ok"
call SavetoFile ThisUser$ wait
else
ThisUser$="nogood"
call SavetoFile ThisUser$ wait
end if
wait
'*****************************************************************
' SUBS AND FUNCTIONS
'*****************************************************************
Sub SavetoFile ThisUser$
open DefaultDir$ + "\public\validation.txt" for output as #f
print #f, ThisUser$
close #f
End Sub
And that does not work. It does work if I put everything in one project : '
' Variables and arrays
'
global DefaultDir$ 'bug in RB to be fixed
usertot=4
dim user$(usertot,2)
user$(1,1)="me"
user$(1,2)="a"
user$(2,1)="you"
user$(2,2)="b"
user$(3,1)="us"
user$(3,2)="c"
user$(4,1)="them"
user$(4,2)="d"
userok=0
userno=0
'
' Check username
'
[ValidUserCheck]
cls
input "Username";username$
for i=1 to usertot
if username$ = user$(i,1) then
userno=i
userok=1
exit for
end if
next
'
' Check password
'
if userok = 0 then
cls
print "Invalid username"
goto [ValidUserCheck]
else
userok=0
cls
print "Password ?"
print
passwordbox #pw, ""
link #action, "Submit", [ValidPasswordCheck]
wait
end if
[ValidPasswordCheck]
pass$= #pw CONTENTS$()
if pass$ = user$(userno,2) then
ThisUser$="ok"
call SavetoFile ThisUser$ wait
else
ThisUser$="nogood"
call SavetoFile ThisUser$ wait
end if
wait
'*****************************************************************
' SUBS AND FUNCTIONS
'*****************************************************************
Sub SavetoFile ThisUser$
open DefaultDir$ + "\public\validation.txt" for output as #f
print #f, ThisUser$
close #f open DefaultDir$ + "\public\uploads\validation.txt" for input as #f
line input #f, a$
close #f
print
print "validation =";a$
End Sub
|
|
|
Post by Jerry Muelver on Jan 21, 2008 15:02:15 GMT -5
In you Main program, change this: open DefaultDir$ + "\public\uploads\validation.txt" for input as #f
to this: open DefaultDir$ + "\public\validation.txt" for input as #f
|
|
alix
Junior Member
Posts: 57
|
Post by alix on Jan 21, 2008 16:04:07 GMT -5
Thanks Jerry, but that doesn't help, I just copied the wrong code source to the forum. Even with your change (inserted now in my first post), it does not work.
@+
|
|
|
Post by Jerry Muelver on Jan 21, 2008 17:30:49 GMT -5
Hmm... Well, I got it working here. I got the file building reports of "no good", and showing that on the screen. Main code is: run "UserValidation", #v render #v open DefaultDir$ + "\public\validation.txt" for input as #f line input #f, a$ close #f print print "validation =";a$
wait
File-building code from UserValidation is: Sub SavetoFile ThisUser$ open DefaultDir$ + "\public\validation.txt" for output as #f print #f, ThisUser$ close #f
Showing on the screen: Password ? (passwordbox) Submit validation =nogood Try again, this time with correct password: whoops..... Doesn't come back from UserValidation, although the file builds "ok" when I used the right password, goes to "nogood" when I'm wrong. I guess I don't know how to make the WAIT and END stuff cooperate to get back from the module to the main.....
|
|