Dim Statement

New to FreeBASIC? Post your questions here.
Post Reply
RodSnow
Posts: 37
Joined: Nov 12, 2008 5:23

Dim Statement

Post by RodSnow »

How would I best do the following:
Dim c101 through c120, c201 through c220, ... c801 through c820 as integers and to be used by all of the program.
I have tried to use for next statements but it will not work. The only way that I have been able to do it is to list each one individually (tremoundous amount of typeing) , but it cannot be used throughout the program.
I apologize if this is not the right place for this type of question.
voodooattack
Posts: 605
Joined: Feb 18, 2006 13:30
Location: Alexandria / Egypt
Contact:

Post by voodooattack »

Code: Select all

dim as string code_buffer = "dim shared as integer "

for i as integer = 101 to 120
    code_buffer &= "c" & i & ", "
next

for i as integer = 201 to 220
    code_buffer &= "c" & i & ", "
next

for i as integer = 801 to 820
    code_buffer &= "c" & i
    if i < 820 then code_buffer &= ", "
next

print code_buffer

sleep

Code: Select all

dim shared as integer c101, c102, c103, c104, c105, c106, c107, c108, c109, c110, _
c111, c112, c113, c114, c115, c116, c117, c118, c119, c120, c201, c202, c203, c204, _
c205, c206, c207, c208, c209, c210, c211, c212, c213, c214, c215, c216, c217, c218, _
c219, c220, c801, c802, c803, c804, c805, c806, c807, c808, c809, c810, c811, c812, _
c813, c814, c815, c816, c817, c818, c819, c820
RodSnow
Posts: 37
Joined: Nov 12, 2008 5:23

Thank You

Post by RodSnow »

Thank You for Your help. It worked exactly as advertised.
McLovin
Posts: 82
Joined: Oct 21, 2008 1:15
Contact:

Post by McLovin »

You need to use arrays in this situation. Individual variables is not the best solution.

Code: Select all

Dim Shared myArray1(101 to 120) As Inteegr
Dim Shared myArray2(201 to 220) As Integer
Dim Shared myArray8(801 to 820) As Integer
... or use a two dimension array

Code: Select all

Dim Shared myArray1( 1 to 8, 101 to 120) As Inteegr
Post Reply