Home > Software engineering >  Help: about VB import excle data display type does not match
Help: about VB import excle data display type does not match

Time:09-19

This is my code and forms, hoping to turn the table line 6 import vb but display type does not match in the array, who help and see what went wrong

CodePudding user response:

Variable is a "array", Print a () is not legal statements,
It should be:
For I=1 to 15: Print a (I) : Next


refer to the original poster weixin_41133222 response:
this is my code and forms, hoping to turn the table 6 import vb but display type does not match in the array, who help and see what went wrong

.

Should be "column 6"!
In addition, before using dynamic array, should first "distribution of array element data space,"
Before you For loop, be about to write: Redim a (15)
Here because you are the most used a (15), of course you use Redim (20) or a Redim a (500) can be, just wasted some memory space,


If how much you want to use an array element is "sure", can declare fixed array, so you don't need (or can't use the ) Redim allocate space,
You this, for example, the Dim (a) As String, into a Dim (15) As a String,

CodePudding user response:

reference 1st floor Chen8013 response:
variable a is "array", Print () is not a legal statement,
It should be:
For I=1 to 15: Print a (I) : Next


The
Quote: refer to the original poster weixin_41133222 response:

This is my code and forms, hoping to turn the table 6 import vb but display type does not match in the array, who help and see what went wrong

.

Should be "column 6"!
In addition, before using dynamic array, should first "distribution of array element data space,"
Before you For loop, be about to write: Redim a (15)
Here because you are the most used a (15), of course you use Redim (20) or a Redim a (500) can be, just wasted some memory space,


If how much you want to use an array element is "sure", can declare fixed array, so you don't need (or can't use the ) Redim allocate space,
You this, for example, the Dim (a) As String, into a Dim (15) As a String,


reference 1st floor Chen8013 response:
variable a is "array", Print () is not a legal statement,
It should be:
For I=1 to 15: Print a (I) : Next


The
Quote: refer to the original poster weixin_41133222 response:

This is my code and forms, hoping to turn the table 6 import vb but display type does not match in the array, who help and see what went wrong

.

Should be "column 6"!
In addition, before using dynamic array, should first "distribution of array element data space,"
Before you For loop, be about to write: Redim a (15)
Here because you are the most used a (15), of course you use Redim (20) or a Redim a (500) can be, just wasted some memory space,


If how much you want to use an array element is "sure", can declare fixed array, so you don't need (or can't use the ) Redim allocate space,
You this, for example, the Dim (a) As String, into a Dim (15) As a String,

I according to your changes, but in the process of debugging run to a (I - 1)=xlsheet. The Cells (I, 6) this part will show the error, and request object, this is what went wrong

CodePudding user response:

refer to the second floor weixin_41133222 response:
Quote: refer to 1st floor Chen8013 response:


The
Quote: refer to the original poster weixin_41133222 response:

This is my code and forms, hoping to turn the table 6 import vb but display type does not match in the array, who help and see what went wrong

.

Should be "column 6"!
In addition, before using dynamic array, should first "distribution of array element data space,"
Before you For loop, be about to write: Redim a (15)
Here because you are the most used a (15), of course you use Redim (20) or a Redim a (500) can be, just wasted some memory space,


If how much you want to use an array element is "sure", can declare fixed array, so you don't need (or can't use the ) Redim allocate space,
You this, for example, the Dim (a) As String, into a Dim (15) As a String,


I according to your changes, but in the process of debugging run to a (I - 1)=xlsheet. The Cells (I, 6) this part will show an error, the object and request, this is where the problem

Your "variable name" write wrong!
Before the For loop, you write the code: Set ExcelSheet =ExcelBook. Worksheets (SheetID)
Writing in the loop body, however, is: xlsheet . Cells (I, 6)
Xlsheet is undefined, the assignment of a variable, if it is used as a "object variables", then it is "null reference,"
When executed naturally "runtime error", "object",
You correct as: a) (I - 1=ExcelSheet. Cells (I, 6) should be ok,
But you'd better should be: a) (I - 1=ExcelSheet. Cells (I, 6). The Value
(I - 1) is a type String, and ExcelSheet. Cells (I, 6) is "object type,"
Impossible to make the "object" assign a value to a String variable, the assignment operation is only the "object attribute values assigned to a" (I - 1),
Code does not specify which attributes, so it is only given by the "default attribute values",
However, who can sure its default property is what! One thousand it's "default attributes" is not what you expected?
With implied the use of default attributes "is not easy to code" reading comprehension ", is more serious is that can cause unexpected results!
Why go to save the few characters, and bring some "potential danger"!!!!!!

Of course you effect is the "don't write" will be right here, but that is just "happened",
The key is: I don't think implied the use of default attributes ", is a good code style (or "programming habits),
This time, all you need is the "value", you don't write, is "value";
Next time, you need the width of the cell (or height, location coordinates, etc.), you also habits do not specify a specific attribute, that is not bad too far???????
  • Related