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!

Using loop'd variables

Status
Not open for further replies.

afig

Programmer
Nov 30, 2007
39
US
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.
 
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$
 
thanks so much. a few buddies (who asked me to do this) have been continuously pestering me for this since yesterday.
 
This doesn't work correctly. Its still not saving that number :(
 
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.
 
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
 
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
 
whoops.

thats what I'm working with.

compNum$ always comes up blank.
 
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.
 
Shows how inattentive I am, I guess. I was looking BEFORE the validation code for the input for user$.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top