• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro Questions

GN0001

Member
Question: Which of the two following Visual BASIC statements is incorrect? Why?

x = x + 1

a + b = c + d


For the foregoing Dim statements, you could not include the line

a = “October 1, 1998”

This would result in an error message, because you’re telling the computer to put a square

peg in a round hole; that is, you’re telling it to store a string constant in a real, single

precision memory location. If you do this, the program will not execute and you’ll get an

error message.


then how should we enter a?

if say:

dim as a constant

will this be correct?


Arrays:

It says, instead of subscripts, parenthesis is used.


b1=a11*x1 + a12*x2


b(1) = a(1, 1) * x(1) + a(1, 2) * x(2)


We know a12 means that a to be multiplied by itself 12 time.

What does a11 mean?


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=

An array defined as


Dim a (10, 10)


What does it say? Does it mean the array is two dimensional and it has 10 elements?
 
Guity


You can't use a line like

a + b = c + d


If you know either a or b you can re-arrange the equation to be

a = (c + d) - b

b = (c + d) - a


x = x + 1

Is quite a valid line which is adding 1 to the current value of x and storing that in a variable called x


=====


If you want to store “October 1, 1998” in a as a String you can either


Dim a as String

or

Dim a as Variant


If you want to store a as a Date serial number


Dim a as Double

a = 36069

or

a = #September 1, 1998#


=====

b1=a11*x1 + a12*x2


b(1) = a(1, 1) * x(1) + a(1, 2) * x(2)


a(1, 2) does not mean a12 or a * a 12 times

a(1, 2) means that the data is stored in an array

an array is like a range and in this case the data is from the First Row, Second Column


If someone has used b1 = a11*x1 + a12*x2

it does not mean a*11 * x*1 + a*12 * x*2

a11, x1, a12 and x2 are all discrete variables

unless thay have written that as a short hand form of writing

b(1) = a(1, 1) * x(1) + a(1, 2) * x(2)


a11 may be stored in a(1, 1)

x1 may be stored in x(1) etc

but a11 may just as validly be stored in a(100,24)


=====


Dim a (10, 10)

means that an array a is 2 dimensional with 10 elements in each direction ie: 10 x 10


Dim a (10, 10, 10)

means that an array a is 3 dimensional with 10 elements in each direction ie: 10 x 10 x 10

=====


Hope that helps
 
Hui,


a11 may be stored in a(1, 1)

x1 may be stored in x(1) etc

but a11 may just as validly be stored in a(100,24)


Are you saying that a11 may be stored in row 100 and column 24?

As you say a11 means a variable with a one row and with a one column? is this right?


The pamphlet you have sent me page 9 says:


Dim a(10, 10), b(10)

This sets aside 100 and 10 memory locations for the variables a and b, respectively.


but you say:

Dim a (10, 10)

means that an array a is 2 dimensional with 10 elements in each direction ie: 10 x 10


Hui, whatever you send us is a big, big help for us.

Guity
 
a11 is an abbreviation for a(1,1)


If it is a name it could be assigned to any location from an array, but either way it is a name of an address


=====


Dim a(10,10) tells Excel to put aside 100 places (10 x 10) for data

It is put aside in a 10 row x 10 column matrix


You could also put aside 100 places by

Dim a(100)

or Dim a(50,2)


It all depends on how your data is formatted and how you want to store it


Generally you would put aside data based on its structure and so you may store 300 records in a 100 x 3 array

Dim a(100,3)

indicating you have say 100 records of 3 fields eg: Date, Name, Age
 
Back
Top