Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial][Blitz] Arrays
Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jonos




PostPosted: Fri Feb 20, 2004 4:36 pm   Post subject: [Tutorial][Blitz] Arrays

>>Introduction
Well this is my first tutorial for Blitz Basic. I started learning it around 3 days ago, and its really fun. I will try to use proper grammar, sentence structure, spelling, and use of capitals to make this easy to understand.

>>Part 1
Many of you will already understand and know what arrays are, but for those who do not, an array is kindof like a group of variables all under the same name, which can be accessed. Arrays are very useful for holding similar types of data, like names of people in your class, like the ages of these people, etc.

What some people visualize an array as looking:
[][][][][] etc, with the little boxes being an element.

>>Part 2
In Blitz Basic arrays are declared by:
code:

Dim arrayName%(#ofelementsinarrary)


**Note: an array can be any data type ($,%,#), not %.

An example of this would be:
code:

Dim names%(5)


This would make an array with 5 elements (the "slots" in an array), with a data type of integer.

You may have noticed that you can't just declare an array like a variable (leaving the Dim part out), and this is because of some unknown reason which is not known by me.

Im sure shorthair or Cervantes can add stuff to this (like initializing the array, I don't know how to do that).

Also, I'm not sure about 2 dimensional/3 dimensional arrays.

I hope you liked my tutorial, I hope I didn't make myself seem too much of an idiot. Have fun in blitz.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Feb 20, 2004 5:18 pm   Post subject: (No subject)

dim.. like declaring any type of var in Visual Basic Razz

nice tutorial. Allow me to add my bit Smile

------------

With large arrays, its no help having an array if you have to call them individually. So we use the beloved For loop.

Here is a lovely example.

code:
Dim names$ (5)
For i = 1 To 5
 names(i) = Input$("What's your name?")
  Print "Hello " + names (i) + "."
Next
;;;;;;;;;
While Not KeyHit (1) ; While the escape key is not pressed
Wend ; closes the while loop. 
; This loop simply waits for the user to press esc
End ; closes the run window so we don't get the annoying "Program has ended" box.




However, if the user enters the number of names he wants to input, then you have to declare the array like so

code:
Dim [i]arrayname[/i] ([i]variable_name_that_stores_how_many_elements[/i])



and then for using that array:

code:

howmany = Input ("How many names? ")
Dim names$ (howmany)
For i = 1 To howmany
  names(i) = Input$("What's your name?")
  Print "Hello " + names (i) + "."
Next


Thanks shorthair Razz
shorthair




PostPosted: Fri Feb 20, 2004 5:31 pm   Post subject: (No subject)

This Is from My Target Game

This takes in the values of the mouse sensitivity for later use , it shows the taking in of an interger

code:
Print"Mouse Options"
Print"Sensitivity"
Print
Global sensex#=Input("Vertical (Default=5) :")
If sensex#=0 Then sensex#=5
Global sensey#=Input("Horizontal (Default=5) :")
If sensey#=0 Then sensey#=5
jonos




PostPosted: Fri Feb 20, 2004 8:23 pm   Post subject: (No subject)

nice job everyone. i was going to do the whole for loop initializing but i had to go to work. this is becoming an awesome forum.

Does anyone know about two dimensional or three dimensional arrays in blitz. I've never really used one, but its good to know.
Cervantes




PostPosted: Fri Feb 20, 2004 9:03 pm   Post subject: (No subject)

From playing around I learned that you declare 2d arrays like so

code:

Dim x (5,5)

Similar to Turing Very Happy
jonos




PostPosted: Fri Feb 20, 2004 9:33 pm   Post subject: (No subject)

so 3 dimensional arrays would dim a% (3, 3, 3)
polygon001




PostPosted: Fri Jun 20, 2008 4:08 pm   Post subject: RE:[Tutorial][Blitz] Arrays

Hmmm well i still don''t get arrays much. Nor do I get types. I don't get how people visualize jars in boxes. And i'm pretty sure this is important stuff so help me out.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: