2010-11-20 52 views
0

我今天学习vba,我是一个新手,我有几个关于代码的问题以及它的写法。我已经下载了一个例子,我试图理解它。我知道C的一些概念。我也想说我不是母语的,我很抱歉在英语中有任何错误。VBA疑惑初学者

下面的代码:

Set rg = Worksheets("TabPaciente").Range("Paciente") 

i = 0 
glQtdPaciente = 0 
Do While rg.Cells(i + 3, 1) <> "" 
i = i + 1 
Loop 
glQtdPaciente = i 

ReDim mPaciente(glQtdPaciente) 
p = Worksheets("TabFila").Range("p") 

InstCheg = 0 
For i = 1 To glQtdPaciente 
mPaciente(i).CodPaciente = rg.Cells(i + 2, 1) 

If Rnd < p Then 
    mPaciente(i).PriorPaciente = 1 
Else 
    mPaciente(i).PriorPaciente = 2 
End If 

mPaciente(i).IntvChegDistr = rg.Cells(i + 2, 2) 
mPaciente(i).Par1 = rg.Cells(i + 2, 3) 
mPaciente(i).Par2 = rg.Cells(i + 2, 4) 
mPaciente(i).Par3 = rg.Cells(i + 2, 5) 
mPaciente(i).Par4 = rg.Cells(i + 2, 6) 

现在我得到了一些问题,我会很高兴,如果有人能帮助我。

当我写

Set rg = Worksheets("TabPaciente").Range("Paciente") 

1)形式现在每次它是写rg.somethingelsehere它会选择工作表“TabPaciente”和范围“Paciente”?它类似于C中#define的概念吗?

Do While rg.Cells(i + 3, 1) <> "" 

2日)由于RG被“定义”像上面这行我能理解像这个问题:“去到工作表TabPaciente和选择范围Paciente,并选择单元格(行,列)?这个怎么样<> "",我不明白这一点的想法。

If Rnd < p Then 
    mPaciente(i).PriorPaciente = 1 
Else 
    mPaciente(i).PriorPaciente = 2 
End If 

3日)这是什么mPaciente(i)和PriorPaciente意味着什么吗?我的意思是他们的概念,是像工作表和范围,我不这么认为,因为我没有工作表名为mPaciente。

在此先感谢您的帮助。

+0

如果您只针对每个问题提出一个问题,则更有可能得到答案。 – BenV 2010-11-21 05:06:40

回答

1

1:A.是的。 B. #define用于为常量创建一个有意义的名称,RG是对对象的引用。

2:所述第一线与所述回路关键字之间

Do While rg.Cells(i + 3, 1) <> "" 

Loop 

任何将被重复,直至标准rg.Cells第(i + 3,1)<> “” 被满足。 <>手段不等于,或=的相反。 “”意味着单元格是空的。

3:您显示的代码仅在mPaciente重新定义时显示,因此我无法告诉您它是类型。在整个代码示例中找到它,然后你就可以看到它是什么。