VBA continue

K

kramer31

Hi. I'm coming to VBA from a C/C++/Java background (and the syntax
makes me want to throw up, by the way--I plan to discontinue using VBA
as soon as possible--it would be nice if MS would give another language
option for scripting Office).

Anyway, can anyone tell me a VBA operator which jumps to the next
iteration of a loop similar to the C operator 'continue'?
 
B

Bob O`Bob

kramer31 said:
Hi. I'm coming to VBA from a C/C++/Java background (and the syntax
makes me want to throw up, by the way--I plan to discontinue using VBA
as soon as possible--it would be nice if MS would give another language
option for scripting Office).

Anyway, can anyone tell me a VBA operator which jumps to the next
iteration of a loop similar to the C operator 'continue'?

GoTo
Honestly, it's likely the best - just add a label at the bottom of your loop.

Or you could define a block structure within the loop by using one of
the /other/ loop constructs, and then "Exit For" or "Exit Do" when you
need to. That's what I usually do.



Bob
--
 
G

Guest

Go back to C. There is no such operator in VBA, the closest that you can come
is GoTo. Something like this:
For cnt = 1 to 4
If cnt = 2 Then GoTo Nextcnt
Nextcnt:
Next
 
K

kramer31

I'll just use an If block, I have a pretty firm personal rule against
using gotos.

I'd love to go back to C, but I have to write some scripts in Excel.

Why doesn't MS offer a better language for scripting Office? It would
be awesome if I could use Perl to script Office. Do you guys know how
powerful that language is?
 
B

Bob Phillips

You just create a condition that only does the stuff if TRUE

For i = 1 To 100
If some_condition Then
'do your stuff
End If
Next i

so you always do the next iteration, but only do something before the
iteration is the condition is met.

--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
J

Jim Cone

visual basic script (VBS) works well in Office...
Microsoft Windows Script 5.6 Documentation
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"kramer31" <[email protected]>
wrote in message
I'll just use an If block, I have a pretty firm personal rule against
using gotos.
I'd love to go back to C, but I have to write some scripts in Excel.
Why doesn't MS offer a better language for scripting Office? It would
be awesome if I could use Perl to script Office. Do you guys know how
powerful that language is?
 
T

Toby Erkson

If not abused, there's nothing wrong with a GOTO. If you insist on not
using it and would rather labor over code to bypass it, code on!

Each language has its pluses and minuses. Personally, I can't stand C. But
that doesn't mean I really like VB ;-)

Have you looked into the .NET languages?
 
K

kramer31

visual basic script (VBS) works well in Office...

It works well enough, but the syntax is completely revolting ... and it
you don't gain any power for the disgusting syntax.

Perl is much more powerful and what would be wrong with offering
multiple scripting languages.
 
R

RB Smissaert

Obviously you are more familiar with C, but what exactly is wrong with VBA?

RBS
 
G

Guest

So just so we are all on the same page... On one hand you are asking for our
help and on the other hand you are belittling the language were we have
chosen to gain our expertise... Does that strike you as odd.

I have worked in C, C++, Java, VB, ... and I can say that there is good and
bad in all of them. I feel that VB is well suited to being a scripting
language for Excel as it is very english like in it's synatax and relatively
easy to write and debug. It does all of the memory handling and it is very
user friendly when creating userforms... Is it perfect. Heck no. But either
are the other languages.

Bob Phillips posted a perfectly good response to your question. It is simple
and it will work. It does not use goto's and it is not far off what you would
have written in C/C++.
 
J

Jim Cone

Your welcome. By the way, do you know "Aaron"?
Sincerely,
Jim Cone


"kramer31" <[email protected]>
wrote in message> visual basic script (VBS) works well in Office...

It works well enough, but the syntax is completely revolting ... and it
you don't gain any power for the disgusting syntax.
Perl is much more powerful and what would be wrong with offering
multiple scripting languages.
 
C

Chip Pearson

Depending on exactly what you are doing, you might want to investigate
"Visual Studio Tools For Office". This allows you to write code in any of
the NET languages, including (managed) C++.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
 
K

kramer31

RB said:
Obviously you are more familiar with C, but what exactly is wrong with VBA?

RBS

A lot of it is my familiarity. I hate learning a new language when it
is actually less functional than one that I already know. Especially
when it uses funky syntax like VB. There are a whole huge family of
languages that use C syntax and it's great. I'm not sure why I want to
type 'End If' when I can type '}'.

I don't necessarily think that C is appropriate for a scripting
language for Office, but Perl would be brilliant.

The built in hash capability would be awesome to use in Excel.
 
C

Chip Pearson

I should have added that if you are working on an add-in, or can change the
nature of your project to an add-in, you can write a COM Add-In in any
language you want.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)
 
R

RB Smissaert

Still not clear what is wrong with VBA.
I am sure there must be some way to use the functionality of a hash table.

RBS
 
G

Guest

I thought "GoTo" was created for people who cannot think logically, so they
would have a way out of the mess they got themselves into.
 
G

gimme_this_gimme_that

Stop complaining and get with the WORLD STANDARD!

If you think VBA is bad just wait til you see VBScript.
 
J

Jim Cone

If you have coherent vbs code, in an appropriate module, Excel will run it.
You have to either...
1. Set a reference to the "MicrosoftScriptingRuntime" library in
Tools | References (in the VBE).
Then this works...Set oFso = Scripting.FileSystemObject
-or-
2. Use "CreateObject" to tell Excel what your code is referring to.
...Set oFso = CreateObject("Scripting.FileSystemObject")

Excel will then recognize all of the properties and methods of the object.
You can then intermix it with your regular vba code.
The help file I referenced in my previous post has good examples and
most English proficient users can easily discern what the code does
by just reading it.

Also, there is a MS newsgroup devoted to vbs.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


<[email protected]>
wrote in message
Hi Jim, how do you tell Excel to use VBS instead of VBA?
 
G

Guest

I can't think why I would want to type ";" at the end of every line when I
could type nothing :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top