×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Using loop'd variables

Using loop'd variables

Using loop'd variables

(OP)
I'm in the process of creating a program for NET SEND use. I'm trying to compare user input to one array. when looping through that array, I want to find a match, keep the index, and use that in another array.

CODE

sizeOfArray = 4
checked$ = "TRUE"
DIM users$(sizeOfArray)
users$(1) = "Krause"
users$(2) = "Fig"
users$(3) = "Williams"
users$(4) = "Griffith"

DIM usersComp$(1 TO sizeOfArray)
usersComp$(1) = "12"
usersComp$(2) = "18"
usersComp$(3) = "19"
usersComp$(4) = "20"

validateUser:
FOR i% = 1 TO sizeOfArray
 IF user$ = users$(i%) THEN
  compNum$ = usersComp$(i%)
  checked$ = "TRUE"
 ELSE
  checked$ = "FALSE"
 END IF
NEXT i%

in which I'm trying to keep compNum$ (the variable that is used in the NET SEND), but I'm having problems assigning the i% to it.

RE: Using loop'd variables

CODE

validateUser:
i% = 1
checked$="FALSE"

do
  if user$ = users$(i%) then
    compNum$ = usersComp$(i%)
    checked$ = "TRUE"             
  else
    i% = i% + 1
  endif   
loop while (i% <= sizeofArray) and (checked$ = "FALSE")

REM at this point if checked$ is TRUE then i% is the index to userComp$
 

RE: Using loop'd variables

(OP)
thanks so much. a few buddies (who asked me to do this) have been continuously pestering me for this since yesterday.

RE: Using loop'd variables

(OP)
This doesn't work correctly. Its still not saving that number :(

RE: Using loop'd variables

The code works as given. i% contains the index to the matched name in array users$().

Where are you using the variable i%? As given, i% scope is local to the code snippet given. You could always create a function and return the index.

RE: Using loop'd variables

Here is some rather inefficient code:

CODE

DECLARE FUNCTION ValidateUser% (user$)

DIM SHARED sizeOfArray

sizeOfArray = 4

DIM SHARED users$(sizeOfArray), UsersComp$(1 TO sizeOfArray)

users$(1) = "Krause"
users$(2) = "Fig"
users$(3) = "Williams"
users$(4) = "Griffith"

UsersComp$(1) = "12"
UsersComp$(2) = "18"
UsersComp$(3) = "19"
UsersComp$(4) = "20"

DIM ComputerIndex%, x%

CLS
RANDOMIZE TIMER

FOR x% = 1 TO 20
  y% = INT(RND * 6) + 1

  IF y% <= sizeOfArray THEN
    ComputerIndex% = ValidateUser%(users$(y%))
  ELSE
    ComputerIndex% = ValidateUser%("UNKNOWN")
  END IF

  PRINT "Index = "; ComputerIndex%,

  IF ComputerIndex% <> -1 THEN
    PRINT users$(ComputerIndex%), UsersComp$(ComputerIndex%)
  ELSE
    PRINT "Unknown User", "N/A"
  END IF
NEXT

FUNCTION ValidateUser% (user$)

DIM i%, Checked$


i% = 1
Checked$ = "FALSE"

DO
  IF user$ = users$(i%) THEN
    compNum$ = UsersComp$(i%)
    Checked$ = "TRUE"
  ELSE
    i% = i% + 1
  END IF
LOOP WHILE (i% <= sizeOfArray) AND (Checked$ = "FALSE")

REM at this point if checked$ is TRUE then i% is the index to userComp$

IF Checked$ = "FALSE" THEN i% = -1


ValidateUser% = i%

END FUNCTION

RE: Using loop'd variables

(OP)

CODE

REM Written by TheLostFaith (Alex Figueroa)
REM November 30th 2007
REM Inspired by Steele NCT's (08) lack of
REM work ethic.

sizeOfArray% = 4
DIM users$(1 TO sizeOfArray%)
users$(1) = "Krause"
users$(2) = "Fig"
users$(3) = "Williams"
users$(4) = "Griffith"

DIM usersComp%(1 TO sizeOfArray%)
usersComp%(1) = 12
usersComp%(2) = 18
usersComp%(3) = 19
usersComp%(4) = 20

validateUser:
i% = 1
checked$ = "FALSE"


DO
 IF user$ = users$(i%) THEN
  compNum% = usersComp%(i%)
  checked$ = "TRUE"
 ELSE
  i% = i% + 1
 END IF
LOOP WHILE (i% <= sizeOfArray%) AND (checked$ = "FALSE")

inquireUser:
IF checked$ = "FALSE" THEN
 PRINT "Invalid User"
 INPUT "Who"; user$
ELSE
 INPUT "Who"; user$
END IF
inquireMessage:
INPUT "Say what"; message$

sendMessage:
PRINT "NET SEND NCT" + compNum$ + " " + message$
SHELL ("NET SEND NCT" + compNum$ + " " + message$)

validateCheck:
IF checked$ = "TRUE" THEN
 GOTO sendMessage
ELSE
 GOTO inquireUser
END IF

RE: Using loop'd variables

(OP)
whoops.

thats what I'm working with.

compNum$ always comes up blank.

RE: Using loop'd variables

Where do you get the input for user$?

Lee

RE: Using loop'd variables

There are quite a few issues with the code as posted, one of which is the code under label validateUser:, which sets compNum$, is never executed after the code under label inquireUser: gets the user name into user$

If you step through the code, you will see other issues as well.

RE: Using loop'd variables

Shows how inattentive I am, I guess.  I was looking BEFORE the validation code for the input for user$.

Lee

RE: Using loop'd variables

Well yes, Lee, that would be the logical place to look.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close