Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIM structure help
#1
i am making a program to asign 16 random number 1-16 to 16 inputed names. i cant figuer out how to set up the varriables. i know you need to use DIM names(16,16) or some thing like that.
Reply
#2
DIM names(1 TO 16) AS STRING
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][Image: safer.gif][/url]
END OF LINE.
Reply
#3
so that will set up 16 variables with the title of name that will hold the stings. now how would i asign a number to each name?
Reply
#4
What do you mean?

like this?
Code:
names(1) = "Billybob"
names(2) = "Bobbybill"
names(3) = "Bubba"

etc....

names(16) = "Bubba-Ray Jr"


Code:
PRINT names(3)
Will display Bubba. You just treat the array and subscript eg. names(#) as a normal variable (in this case, a string).
In a world without walls and doors, who needs Windows and Gates?
Reply
#5
i need a hash. like this.
bob 1
bill 2
joe 3
sue 4

the naems are printed out with their number.
Reply
#6
Code:
DIM names(1 TO 16) AS STRING

FOR i = 1 TO 16
   READ names(i)
NEXT

GOSUB printNames  
END

printNames:
FOR i = 1 TO 16
   PRINT names(i); i
NEXT
RETURN

DATA Adam, Bertha, Charles, Danielle, Eddie, Frances, Gary, Helen, Ian, Jackie, Karl, Lucy, Marcus, Nelly, Oscar, Paula
In a world without walls and doors, who needs Windows and Gates?
Reply
#7
please give us an example of when you would use something as useless as this.
.........next...............
Reply
#8
I'm not sure what you want, but here are two possible ways (untested so you may need to make corrections)
Code:
' This randomizes a list of names, so the index becomes a
' random number assigned to the name.

DIM Names(1 to16) AS STRING

Restore NameList   ' This isn't necessary unless you have multiple data lists
FOR j = 1 TO 16
  READ  Names(j)
NEXT

FOR j= 1 TO 16
  Temp$ = Names(j)
  r = INT(RND * 16 +1)
  Names(j) = Names(r)
  Names(r) = Temp$
NEXT

' your code

END

NameList:
DATA Alice,Bob,Cindy,Dave,and so on

Code:
' This randomizes a list of numbers
DEFINT A-Z
DIM Names(1 to16) AS STRING
DIM RndmNmbr(1 to 16)

Restore NameList   ' This isn't necessary unless you have multiple data lists
FOR j = 1 TO 16
  READ  Names(j)
  RndmNmbr(j) = j
NEXT

FOR j= 1 TO 16
  Temp = RndmNmbr(j)
  r = INT(RND * 16 +1)
  RndmNmbr(j) = RndmNmbr(r)
  RndmNmbr(r) = Temp
NEXT

' your code

END

NameList:
DATA Alice,Bob,Cindy,Dave,and so on
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Reply
#9
********WAIT*************
********WAIT*************
********WAIT*************

FIRST, a HASH is a MATHEMATICAL EQUATION that can be used to find the POSITION of an index... I think... er..... someone give me a good example.....

Now, for your program, here is how you do it:

Code:
DIM names.string$(1 TO 16) AS STRING
DIM names.index%(1 TO 16) AS INTEGER

'put in your names by assigning to an array manually or through a file...
'.........
'

FOR i% = 1 TO 16
SWAP names.index%(INT(RND*16)+1), names.index%(i%)
NEXT i%

FOR i% = 1 TO 16
PRINT names.string$(names.index%(i%)); names.index%(i%)
NEXT i%
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
hash mathmatical?? anyway thanks for the code. would show me how to input the names? like
Code:
for i = 1 to 16
input "student name: ",names.string$(i)
next
for a file would be some thing like this
Code:
OPEN "names" FOR INPUT AS #1
FOR i = 1 TO 16
WHILE NOT EOF(1)
INPUT #1 names.string$(i)
WEND
NEXT
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)