Marcelo
Marcelo

Reputation: 1553

VBA doubts beginner

I'm learning vba today, I'm a newbie and I have a few questions about the code and how it's written. I've downloaded an example and I'm trying to understand it. I know a few concepts of C. I also want to say that I'm no native speaker, and I'm sorry in advance for any mistake in English.

Here's the code:

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)

Now I got some questions, and I'd be glad if someone can help me.

When I write

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

1st)Form now on everytime it's written rg.somethingelsehere it'll be selecting worksheet "TabPaciente" and Range "Paciente"? It this similar to the concept of #define in C ?

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

2nd) Since rg was "defined" like the question above this line I can understand like "Go to worksheet TabPaciente and select range Paciente, and select the cells(line, column) ? What about this <> "" , I don't get it's idea.

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

3rd) What does mPaciente(i) and PriorPaciente means ? I mean their concept, is it like Worksheet and Range, I don't think so because I have no Worksheet named mPaciente.

Thanks in advance for you help.

Upvotes: 0

Views: 511

Answers (1)

NoAlias
NoAlias

Reputation: 9193

1: A. Yes. B. #define is for making a meaningful name to a constant, RG is a reference to an object.

2:

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

Loop

Anything between the first line and the Loop keyword will be repeated until the criteria rg.Cells(i + 3, 1) <> "" is met. <> means does not equal, or the opposite of =. "" means that the cell is empty.

3: The code you displayed only shows when mPaciente was redefined, so I won't be able to tell you it's type. Do a find in the whole code example for it and you'll be able to see what it is.

Upvotes: 1

Related Questions