For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > beginner question: VBA --> VB?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author beginner question: VBA --> VB?
Abeness

2005-02-01, 8:59 pm

Hi, guys. I don't have VB yet, but need an answer to this sooner than I
can get it. I'm expert in Corel Script, which is used to automate Corel
Ventura, and is very similar to VB.

Could someone please be kind enough to tell me how the following
functional VBA code would look different in VB, in a standalone program?
I'd really appreciate example code.

Many thanks,

Abe

Sub VenturaTest()
Dim oV10 As New Ventura.VPAutoObj, sTemplate As String
Dim lLeft As Long, lTop As Long, lOffset As Long, i As Integer
Dim lFrameCount As Long, iret As Integer

sTemplate = "C:\Default.vp"
lOffset = 63500 '18pt

With oV10
.FileNew sTemplate
For i = 1 To 10
lLeft = i * lOffset
lTop = lLeft
.FormatCreateFrame lLeft, lTop, 254000, 254000, 0, "", False
Next
lFrameCount = .FrameCount(False)
End With
iret = MsgBox(lFrameCount, vbOKOnly + vbInformation, "Frame Count:")
oV10.SetVisible True, True
End Sub
Karl E. Peterson

2005-02-01, 8:59 pm

Hi Abe --

> Hi, guys. I don't have VB yet, but need an answer to this sooner than
> I can get it. I'm expert in Corel Script, which is used to automate
> Corel Ventura, and is very similar to VB.
>
> Could someone please be kind enough to tell me how the following
> functional VBA code would look different in VB, in a standalone
> program? I'd really appreciate example code.


Assuming you make an explicit reference to Ventura in your VB project, there's
nothing there that isn't fully supported by Classic VB.

> Sub VenturaTest()
> Dim oV10 As New Ventura.VPAutoObj, sTemplate As String
> Dim lLeft As Long, lTop As Long, lOffset As Long, i As Integer
> Dim lFrameCount As Long, iret As Integer
>
> sTemplate = "C:\Default.vp"
> lOffset = 63500 '18pt
>
> With oV10
> .FileNew sTemplate
> For i = 1 To 10
> lLeft = i * lOffset
> lTop = lLeft
> .FormatCreateFrame lLeft, lTop, 254000, 254000, 0, "", False
> Next
> lFrameCount = .FrameCount(False)
> End With
> iret = MsgBox(lFrameCount, vbOKOnly + vbInformation, "Frame Count:")
> oV10.SetVisible True, True
> End Sub


A few critiques on what's considered "good form", though. You'll want to get in the
habit of...

* Declare Subs as either Public or Private.
* Follow Next with the index variable in question.
* Don't hardcode path/filenames.

Otherwise, looks good.

Later... Karl
--
[Microsoft Basic: 1976-2001, RIP]


Ken Halter

2005-02-01, 8:59 pm

"Abeness" <news@nada.x> wrote in message
news:OfXEcCKCFHA.2828@TK2MSFTNGP10.phx.gbl...
> Hi, guys. I don't have VB yet, but need an answer to this sooner than I
> can get it. I'm expert in Corel Script, which is used to automate Corel
> Ventura, and is very similar to VB.
>
> Could someone please be kind enough to tell me how the following
> functional VBA code would look different in VB, in a standalone program?
> I'd really appreciate example code.
>
> Many thanks,
>
> Abe


If you're referring to VB Classic (VB.Not.Net), your code looks like it'll
run unchanged.

One note though (and you may already be aware)... that 'VPAutoObj' variable
is declared as a Variant since there's no type specified. Just pointing that
out since it's the only one with a missing type spec.

> Dim oV10 As New Ventura.VPAutoObj, sTemplate As String


In theory, you could start a new project (in VB), add a module, add a Sub
Main, set the project properties so it starts in Sub Main, optionally get
rid of the form (all new projects start with a form of some kind) and do
something like.....

Public Sub Main()
Call VenturaTest
End Sub '<--app ends when this runs (unless there are forms loaded)

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..


Russ Holsclaw

2005-02-01, 8:59 pm


"Abeness" <news@nada.x> wrote in message
news:OfXEcCKCFHA.2828@TK2MSFTNGP10.phx.gbl...
> Hi, guys. I don't have VB yet, but need an answer to this sooner than I
> can get it. I'm expert in Corel Script, which is used to automate Corel
> Ventura, and is very similar to VB.
>
> Could someone please be kind enough to tell me how the following
> functional VBA code would look different in VB, in a standalone program?
> I'd really appreciate example code.
>
> Many thanks,
>
> Abe
>
> Sub VenturaTest()
> Dim oV10 As New Ventura.VPAutoObj, sTemplate As String
> Dim lLeft As Long, lTop As Long, lOffset As Long, i As Integer
> Dim lFrameCount As Long, iret As Integer
>
> sTemplate = "C:\Default.vp"
> lOffset = 63500 '18pt
>
> With oV10
> .FileNew sTemplate
> For i = 1 To 10
> lLeft = i * lOffset
> lTop = lLeft
> .FormatCreateFrame lLeft, lTop, 254000, 254000, 0, "", False
> Next
> lFrameCount = .FrameCount(False)
> End With
> iret = MsgBox(lFrameCount, vbOKOnly + vbInformation, "Frame Count:")
> oV10.SetVisible True, True
> End Sub


The code you show *IS* VB, except that there's a reference to a Ventura
object library. I doubt that anyone here could translate that into a
non-Ventura-based form without complete knowledge of the Ventura library.
Your code doesn't have any comments (or at least very little) that gives
much of a clue as to what this code purports to do. I for one, never heard
of Ventura, and don't even know what sort of application it is.

You must learn to understand the distinction between a language's syntax
and the collection of object libraries that are used to interface with the
programming environment. These days, probably something like 90% of what
you have to know to use any given "language" isn't really the language
itself, but rather the set of object libraries with which one is provided.
This is why it is almost meaningless to say that you know VB, C, C++, Java,
or whatever, without also identifying the environment and the type of
programming being done. Most of the requisite knowledge has nothing to do
with the language as such.

....

Well, OK, I just looked up Corel Ventura, it's apparently one of those
desktop-publishing programs. The name sounds somewhat familiar to me now.
That gives me enough of a clue to say that, essentially, there is NO CODE
AT ALL in Visual Basic for Windows that is equivalent, since apparently
you're scripting some large application that lays out pages for publishing
or some such thing. Almost all of the functionality of this "Language"
lies in the underlying desktop publishing application. So, if you want to
know how easy it is to duplicate the function of a Ventura script, but
without Ventura, or an equivalent application, then I would have to say
that you've missed the whole idea. The standard VB object library does not
contain the equivalent of desktop-publishing functionality. It's there for
writing whole new applications.

Abeness

2005-02-02, 3:58 am

Thanks, guys. Responding to all in one post to keep things cleaner.

Karl E. Peterson wrote:
> Assuming you make an explicit reference to Ventura in your VB project, there's
> nothing there that isn't fully supported by Classic VB.


Excellent, thanks. By an explicit reference, do you mean referencing the
Ventura TLB? BTW, site, Karl. McKinney's book looks *excellent.*
Kudos for convincing the PTB to allow you to host it and for putting the
work into converting it. Looks great.

Thanks to Ken pointing out my omission to declare oV10 properly, I've
revised the VBA code to the following:

Dim oV10 As Object
Set oV10 = New Ventura.VPAutoObj

I hadn't glommed onto the proper syntax for Set, so I got an error and
got sloppy. :-(

Now that I just discovered that my C# IDE (SharpDevelop) also does
VB.NET, I've gotten it working there in a VB.NET project, too. Cool.
Mind you, I doubt I'll use VB myself, this is investigation for someone
else.

One problem is that I can't figure out how to detect whether Ventura is
already running, though that doesn't seem to matter insofar as

oV10 = New Ventura.VPAutoObj

doesn't create a second app instance if Ventura is already running, it
reuses the existing one. GetObject and CreateObject didn't work from
VBA--got the error "ActiveX component can't create object". Either a
syntax error, or a limitation of Ventura? Only the first app instance
can be controlled, FYI.

I did notice that, after my VB.NET EXE creates the new publication
(FileNew) and creates the frames (FormatCreateFrame), if I close the
publication it created, Ventura itself closes. Any way around that? Why
is this happening? I'm suspecting it's some new .NET garage cleanup
thing, since the EXE isn't listed in TaskMan when Ventura closes. How
would I tell the code to leave the app instance it created alone after
executing and the user closing the file it created?

> A few critiques on what's considered "good form", though.


*Always* appreciated.

> * Declare Subs as either Public or Private.


Thanks. No such thing in Corel Script. I've seen it in VBA, but haven't
done a whole lot in VBA.

> * Follow Next with the index variable in question.


OK. Out of curiosity, why is this necessary? Isn't it always assumed in
a For...Next statement?

> * Don't hardcode path/filenames.


It was quick and dirty for demo purposes... I know.

Russ Holsclaw wrote:
> The code you show *IS* VB, except that there's a reference to
> a Ventura object library. I doubt that anyone here could
> translate that into a non-Ventura-based form


That isn't what I asked--sorry if I wasn't clear. I know that I'm using
the Ventura TLB--that's what "Ventura.VPAutoObj" references--and I'm
quite clear on the distinction between an API and the syntax of the
language one uses to access that API. Thanks for confirming that the VB
syntax is the same as for VBA--I hadn't realized that.

Abe
Jeff Johnson [MVP: VB]

2005-02-02, 3:58 am


"Karl E. Peterson" <karl@mvps.org> wrote in message
news:%23dRFROKCFHA.3940@TK2MSFTNGP09.phx.gbl...

> A few critiques on what's considered "good form", though. You'll want to
> get in the
> habit of...


> * Follow Next with the index variable in question.


Yeesh! I DESPISE that!


Abeness

2005-02-02, 8:59 am

Jeff Johnson [MVP: VB] wrote:
>
>
> Yeesh! I DESPISE that!


Actually, I do too, but I'm willing to hear why it might be better to
specify it.
Björn Holmgren

2005-02-02, 8:59 am

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:#jE1yPKCFHA.2404@TK2MSFTNGP15.phx.gbl...
> One note though (and you may already be aware)... that 'VPAutoObj'

variable
> is declared as a Variant since there's no type specified. Just pointing

that
> out since it's the only one with a missing type spec.



You missed the dot between "Ventura" and "VPAutoObj", Ken.

--
Björn Holmgren



Jeff Johnson [MVP: VB]

2005-02-02, 4:02 pm


"Abeness" <news@nada.x> wrote in message
news:eQ0ZznPCFHA.3336@TK2MSFTNGP11.phx.gbl...

>
> Actually, I do too, but I'm willing to hear why it might be better to
> specify it.


Readability will be the answer. I think proper indenting serves the same
purpose.


Bob Butler

2005-02-02, 4:02 pm

"Abeness" <news@nada.x> wrote in message
news:uuP6NGOCFHA.4008@tk2msftngp13.phx.gbl
<cut>
> Now that I just discovered that my C# IDE (SharpDevelop) also does
> VB.NET, I've gotten it working there in a VB.NET project, too. Cool.
> Mind you, I doubt I'll use VB myself, this is investigation for
> someone else.


You do realize that VB and VB.Net are very different languages, right?
VB.Net questions should be asked in a group with 'dotnet' or 'vsnet' in the
name. The responses you've gotten so far apply to VB version 6 and earlier.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Ken Halter

2005-02-02, 4:02 pm

"Björn Holmgren" <bjohol@hotmail.com> wrote in message
news:eo0Md.19592$Of5.13151@nntpserver.swip.net...
>
> You missed the dot between "Ventura" and "VPAutoObj", Ken.
>
> --
> Björn Holmgren


Yep.... you're right.. darn "dots" look like dust on the screen <g>... time
to increase my font size and/or grab the window cleaner ;-)

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..


Abeness

2005-02-02, 4:02 pm

Bob Butler wrote:
> You do realize that VB and VB.Net are very different languages, right?
> VB.Net questions should be asked in a group with 'dotnet' or 'vsnet' in the
> name. The responses you've gotten so far apply to VB version 6 and earlier.


Yes, thanks, Bob. I managed to edit out a bunch of my discussion on
differences between the two as I was discovering them yesterday because
it wasn't germane in the end. I've started to explore the MSDN pages on
VB.net for VB6 people, I've also been exploring C++, C++.net, and C# a
bit. I'm far from knowledgeable about the differences between "notnet"
and dotnet, but am not a *complete* ignoramus in the matter. ;-)
Abeness

2005-02-02, 4:02 pm

Björn Holmgren wrote:
> You missed the dot between "Ventura" and "VPAutoObj", Ken.


So hang on: "Dim oV10 as New Ventura.VPAutoObj" DOES in fact take care
of both declaring it as an object type AND creating the object, both? Is
this because VPAutoObj is an object inside the Ventura type lib? Or is
it the dot that indicates the object nature? Sorry, I really don't have
the terminology yet.
Bob Butler

2005-02-02, 4:02 pm

"Abeness" <news@nada.x> wrote in message
news:ucOsrmUCFHA.3376@TK2MSFTNGP12.phx.gbl
> Björn Holmgren wrote:
>
> So hang on: "Dim oV10 as New Ventura.VPAutoObj" DOES in fact take care
> of both declaring it as an object type AND creating the object, both?
> Is this because VPAutoObj is an object inside the Ventura type lib?
> Or is it the dot that indicates the object nature? Sorry, I really
> don't have the terminology yet.


That syntax does declare the variable and create an instance but it is not a
good practice. Usign that syntax adds oerhead to your app as VB inserts
code to continually check the variable to ensure that it is created and it
can hide bugs because if you refer to the variable after releasing the
reference VB will just create a new one for you. The general consensus is
that it is much better to retain more control by using the separate lines:
Dim oV10 as Ventura.VPAutoObj
Set oV10 = New Ventura.VPAutoObj

--
Reply to the group so all can participate
VB.Net: "Fool me once..."

Paul Clement

2005-02-02, 4:02 pm

On Wed, 2 Feb 2005 06:40:12 -0800, "Bob Butler" <tiredofit@nospam.com> wrote:

¤ "Abeness" <news@nada.x> wrote in message
¤ news:uuP6NGOCFHA.4008@tk2msftngp13.phx.gbl
¤ <cut>
¤ > Now that I just discovered that my C# IDE (SharpDevelop) also does
¤ > VB.NET, I've gotten it working there in a VB.NET project, too. Cool.
¤ > Mind you, I doubt I'll use VB myself, this is investigation for
¤ > someone else.
¤
¤ You do realize that VB and VB.Net are very different languages, right?
¤ VB.Net questions should be asked in a group with 'dotnet' or 'vsnet' in the
¤ name. The responses you've gotten so far apply to VB version 6 and earlier.

....and yet the code looks practically identical in VB.NET. Kind of scary, eh? ;-)


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
Abeness

2005-02-02, 4:02 pm

Bob Butler wrote:
> That syntax does declare the variable and create an instance but it is not a
> good practice. Usign that syntax adds oerhead to your app as VB inserts
> code to continually check the variable to ensure that it is created and it
> can hide bugs because if you refer to the variable after releasing the
> reference VB will just create a new one for you.


Ahh, that wouldn't be good. Thanks for the explanation.

> Dim oV10 as Ventura.VPAutoObj


Why would I want to use this syntax instead of the more generic
"Dim oV10 As Object"?
Karl E. Peterson

2005-02-02, 4:02 pm

Abeness wrote:
> I've started to explore the MSDN pages on VB.net for VB6 people,


Well, be forewarned... They paint a *far* rosier picture than reality dictates.
Best link you can follow from any of them is the one in the first paragraph of the
article here:

http://msdn.microsoft.com/library/e...html/vs04k1.asp

:-)
--
[Microsoft Basic: 1976-2001, RIP]


Karl E. Peterson

2005-02-02, 4:02 pm

Jeff Johnson [MVP: VB] wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote ...
>
>
>
> Yeesh! I DESPISE that!


Coffee or tea? Yes. :-)

Classic programmer ambiguity. You hate the naked Next, or the trailing index?
--
[Microsoft Basic: 1976-2001, RIP]


Karl E. Peterson

2005-02-02, 4:02 pm

Abeness wrote:
> Thanks, guys. Responding to all in one post to keep things cleaner.
>
> Karl E. Peterson wrote:
>
> Excellent, thanks. By an explicit reference, do you mean referencing
> the Ventura TLB?


Right. Project menu, References... I don't have Ventura, so I can't point to the
right box in that list.

> BTW, site, Karl. McKinney's book looks
> *excellent.* Kudos for convincing the PTB to allow you to host it and
> for putting the work into converting it. Looks great.


Thanks! :-)

> One problem is that I can't figure out how to detect whether Ventura
> is already running, though that doesn't seem to matter insofar as
>
> oV10 = New Ventura.VPAutoObj
>
> doesn't create a second app instance if Ventura is already running, it
> reuses the existing one. GetObject and CreateObject didn't work from
> VBA--got the error "ActiveX component can't create object". Either a
> syntax error, or a limitation of Ventura? Only the first app instance
> can be controlled, FYI.


Is this still an issue? Could be something really simple, or could be that library
isn't very amenable to outside automation.

> I did notice that, after my VB.NET EXE creates the new publication
> (FileNew) and creates the frames (FormatCreateFrame), if I close the
> publication it created, Ventura itself closes. Any way around that?
> Why is this happening?


It totally depends on that host application, and how it reacts to the methods it
exposes for you to call.

> I'm suspecting it's some new .NET garbage cleanup thing,


If this only happens from VFred, and not ClassicVB, automation, well, yeah, you could
very well be looking at an issue related to the lack of reference counting and
lifetime control. (This happens to be one of the principle reasons many cite for not
migrating to .NET, even if it did support ClassicVB syntax!)

>
> OK. Out of curiosity, why is this necessary? Isn't it always assumed
> in a For...Next statement?


It's not necessary, but makes the code far more readable. Especially with nested
loops. (Rule#1 in MSBasic-Land: Never trust default behaviors! <g> If you have the
opportunity to be explicit, grab it!)

>
> It was quick and dirty for demo purposes... I know.


Figured, but couldn't resist. ;-)

Later... Karl
--
[Microsoft Basic: 1976-2001, RIP]


Jeff Johnson [MVP: VB]

2005-02-02, 4:02 pm


"Karl E. Peterson" <karl@mvps.org> wrote in message
news:ufvU3tVCFHA.1260@TK2MSFTNGP12.phx.gbl...

>
> Coffee or tea? Yes. :-)
>
> Classic programmer ambiguity. You hate the naked Next, or the trailing
> index?


The trailing index. Whenever I see someone do that I also expect to see
things like "Let A = 1".


Karl E. Peterson

2005-02-02, 9:02 pm

Jeff Johnson [MVP: VB] wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote in message
> news:ufvU3tVCFHA.1260@TK2MSFTNGP12.phx.gbl...
>
>
> The trailing index. Whenever I see someone do that I also expect to
> see things like "Let A = 1".


LOL!

For i = 1 To 100
For j = 1 To 100
' Whatever
Next j, i

Boooooooooo! :-P
--
[Microsoft Basic: 1976-2001, RIP]


Abeness

2005-02-02, 9:02 pm

Karl E. Peterson wrote:
> Abeness wrote:
>
>
>
> Well, be forewarned... They paint a *far* rosier picture than reality dictates.


As would be expected of MS... <g> thanks for the alert and the ref.
Rick Rothstein

2005-02-02, 9:02 pm

> >>>> A few critiques on what's considered "good form", though. You'll
>
> LOL!
>
> For i = 1 To 100
> For j = 1 To 100
> ' Whatever
> Next j, i
>
> Boooooooooo! :-P


10 Let I% = I% + 1
20 If I% > 100 Then GoTo 100
30 Let J% = J% + 1
40 If J% > 100 Then GoTo 10
50 '
55 '
60 ' Whatever
65 '
70 '
80 GoTo 30
90 End

<g>

Rick
Karl E. Peterson

2005-02-02, 9:02 pm

Rick Rothstein wrote:
>
> 10 Let I% = I% + 1
> 20 If I% > 100 Then GoTo 100
> 30 Let J% = J% + 1
> 40 If J% > 100 Then GoTo 10
> 50 '
> 55 '
> 60 ' Whatever
> 65 '
> 70 '
> 80 GoTo 30
> 90 End
>
> <g>
>
> Rick


Now *that* is _really_ tasteless... <bg>
--
[Microsoft Basic: 1976-2001, RIP]


Rick Rothstein

2005-02-02, 9:02 pm

> > 10 Let I% = I% + 1
>
> Now *that* is _really_ tasteless... <bg>


Damn, an error (due to bad editing).

The GoTo in Line 20 should have been to 90, not 100.

(Just trying to keep the archives accurate.<g> )

Rick
Jeff Johnson [MVP: VB]

2005-02-02, 9:02 pm


"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:OB3FUbWCFHA.1932@TK2MSFTNGP14.phx.gbl...

> 10 Let I% = I% + 1
> 20 If I% > 100 Then GoTo 100
> 30 Let J% = J% + 1
> 40 If J% > 100 Then GoTo 10


50 REM
55 REM
60 REM Whatever
65 REM
70 REM

> 80 GoTo 30
> 90 End
>
> <g>
>
> Rick



Rick Rothstein

2005-02-02, 9:02 pm

> > 10 Let I% = I% + 1
>
> 50 REM
> 55 REM
> 60 REM Whatever
> 65 REM
> 70 REM


Ahh! That's right, the apostrophe wasn't a valid comment indicator in
the way-back days, was it.

Rick

Ken Halter

2005-02-02, 9:02 pm

"Karl E. Peterson" <karl@mvps.org> wrote in message
news:erfiDtVCFHA.3416@TK2MSFTNGP09.phx.gbl...
> Abeness wrote:
>
> Well, be forewarned... They paint a *far* rosier picture than reality
> dictates.
> Best link you can follow from any of them is the one in the first
> paragraph of the
> article here:
>
> http://msdn.microsoft.com/library/e...html/vs04k1.asp
>
> :-)
> --
> [Microsoft Basic: 1976-2001, RIP]
>


"Fortunately, .NET 2.0 doesn't have the same shocks in store. Instead, it
refines the language without breaking any of your existing code"

Obviously, that means.... doesn't break existing .Net code eh? <g> Pretty
tricky wording though.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..


Karl E. Peterson

2005-02-02, 9:02 pm

Ken Halter wrote:
> "Karl E. Peterson" <karl@mvps.org> wrote in message
> news:erfiDtVCFHA.3416@TK2MSFTNGP09.phx.gbl...
>
> "Fortunately, .NET 2.0 doesn't have the same shocks in store.
> Instead, it refines the language without breaking any of your
> existing code"
>
> Obviously, that means.... doesn't break existing .Net code eh? <g>
> Pretty tricky wording though.


Yeah, they need to draw out the suspense for 3.0, eh?
--
[Microsoft Basic: 1976-2001, RIP]


Jeff Johnson [MVP: VB]

2005-02-03, 4:01 am


"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:uYB20oWCFHA.3548@TK2MSFTNGP11.phx.gbl...

>
> Ahh! That's right, the apostrophe wasn't a valid comment indicator in
> the way-back days, was it.


Not waaaay back, but it is relatively old. And remember, ' doesn't simply
mean "REM"; it means ":REM"!


Abeness

2005-02-03, 4:01 am

Karl E. Peterson wrote:
>
>
> This gives you what's called "early binding", which is (arguably) more efficient at
> runtime. It also -- major bonus -- gives you intellisense at designtime.


Intellisense during design is good. Unfortunately, Ventura does not
support early binding.
Abeness

2005-02-03, 4:01 am

Karl E. Peterson wrote:
> Right. Project menu, References... I don't have Ventura, so I can't point to the
> right box in that list.


No need, we're on the same page.

>
>
> Is this still an issue? Could be something really simple, or could be that library
> isn't very amenable to outside automation.


I suspect the latter, from my experience with Ventura. I mean, Ventura
is highly automatable, but there are some quirks that make this here
quirk unsurprising. Does not appear to be an issue, insofar as using New
doesn't create a new app instance if one already exists.

> It totally depends on that host application, and how it reacts to the methods it
> exposes for you to call.


I'll have to check it from C++ or C#. It does not behave this way when
automated from Corel Script (uncompiled script or EXE).

> If this only happens from VFred, and not ClassicVB


Since I don't have classic VB, I may never know.

>
>
> It's not necessary, but makes the code far more readable. Especially with nested
> loops. (Rule#1 in MSBasic-Land: Never trust default behaviors! <g> If you have the
> opportunity to be explicit, grab it!)


I can definitely see the value in nested loops, in fact I'm pretty sure
I've done so myself for clarity, despite the usual indenting, but with a
single loop it seems pretty clear to me. I do agree with not trusting
default behaviors as a general rule, particularly with more complex
application commands. But with such common structures as For...Next and
..TextParaDown (assumes one paragraph and not selecting), I expect it to
be highly unlikely that the default behavior would change. Perhaps I
live dangerously... fact is, I'm becoming more paranoid, and more often
specifying even basic parameters than not.
Abeness

2005-02-03, 4:01 am

Abeness wrote:
> Since I don't have classic VB, I may never know.


Whoops. Read, I don't have a classic VB compiler...
Paul Clement

2005-02-03, 4:02 pm

On Tue, 01 Feb 2005 23:42:07 -0500, Abeness <news@nada.x> wrote:


¤ One problem is that I can't figure out how to detect whether Ventura is
¤ already running, though that doesn't seem to matter insofar as
¤
¤ oV10 = New Ventura.VPAutoObj
¤
¤ doesn't create a second app instance if Ventura is already running, it
¤ reuses the existing one. GetObject and CreateObject didn't work from
¤ VBA--got the error "ActiveX component can't create object". Either a
¤ syntax error, or a limitation of Ventura? Only the first app instance
¤ can be controlled, FYI.
¤
¤ I did notice that, after my VB.NET EXE creates the new publication
¤ (FileNew) and creates the frames (FormatCreateFrame), if I close the
¤ publication it created, Ventura itself closes. Any way around that? Why
¤ is this happening? I'm suspecting it's some new .NET garage cleanup
¤ thing, since the EXE isn't listed in TaskMan when Ventura closes. How
¤ would I tell the code to leave the app instance it created alone after
¤ executing and the user closing the file it created?
¤

Not sure where your object variable is defined but it could be that it's going out of scope. Ventura
seems to behave a bit differently than I would expect with respect to automation.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
Paul Clement

2005-02-03, 4:02 pm

X-Newsreader: Forte Agent 1.8/32.548
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Newsgroups: microsoft.public.vb.syntax
NNTP-Posting-Host: 198.153.231.97
Path: TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
Lines: 1
Xref: TK2MSFTNGP08.phx.gbl microsoft.public.vb.syntax:85421

On Wed, 02 Feb 2005 14:02:58 -0500, Abeness <news@nada.x> wrote:

¤ Bob Butler wrote:
¤ > That syntax does declare the variable and create an instance but it is not a
¤ > good practice. Usign that syntax adds oerhead to your app as VB inserts
¤ > code to continually check the variable to ensure that it is created and it
¤ > can hide bugs because if you refer to the variable after releasing the
¤ > reference VB will just create a new one for you.
¤
¤ Ahh, that wouldn't be good. Thanks for the explanation.
¤
¤ > Dim oV10 as Ventura.VPAutoObj
¤
¤ Why would I want to use this syntax instead of the more generic
¤ "Dim oV10 As Object"?

Just to clarify, if you're using VB.NET there is no performance penalty when using the single line
declare w/instantiation. As a matter of fact it is commonplace.

However, there still is a small performance penalty when using late binding. You also lose
design-time/compile-time syntax checking in addition to the Intellisense that Karl mentioned.


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
Karl E. Peterson

2005-02-03, 4:02 pm

Abeness wrote:
> Karl E. Peterson wrote:
>
> Intellisense during design is good. Unfortunately, Ventura does not
> support early binding.


Bummer. I think Acrobat is somewhat similar. Very frustrating.
--
[Microsoft Basic: 1976-2001, RIP]


Karl E. Peterson

2005-02-03, 4:02 pm

Abeness wrote:
> But with such common structures as For...Next, I expect it
> to be highly unlikely that the default behavior would change.


Yeah, lots of us expected as much. :-(
--
[Microsoft Basic: 1976-2001, RIP]


Abeness

2005-02-09, 4:01 pm

Karl E. Peterson wrote:
> Abeness wrote:
>
>
>
> Yeah, lots of us expected as much. :-(


Mmmm. Hmmmm. Crap!
Abeness

2005-02-09, 4:01 pm

Paul Clement wrote:
> Not sure where your object variable is defined but it could be that it's going out of scope.


Thanks, I'll consider that.
Abeness

2005-02-09, 4:01 pm

Paul Clement wrote:
> Just to clarify, if you're using VB.NET there is no performance penalty when using the single line
> declare w/instantiation. As a matter of fact it is commonplace.
>
> However, there still is a small performance penalty when using late binding. You also lose
> design-time/compile-time syntax checking in addition to the Intellisense that Karl mentioned.


Thanks again, Paul.
Ken Halter

2005-02-09, 4:01 pm

"Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> wrote in message
news:6f2201l8okrg6l60ji6os22tgn4pamj5is@
4ax.com...
> ¤ You do realize that VB and VB.Net are very different languages, right?
> ¤ VB.Net questions should be asked in a group with 'dotnet' or 'vsnet' in
> the
> ¤ name. The responses you've gotten so far apply to VB version 6 and
> earlier.
>
> ...and yet the code looks practically identical in VB.NET. Kind of scary,
> eh? ;-)


That's one of the problems... the code "looks" the same but acts completely
different. <g>

> Paul ~~~ pclement@ameritech.net
> Microsoft MVP (Visual Basic)



--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..


Paul Clement

2005-02-09, 9:00 pm

On Wed, 9 Feb 2005 10:10:45 -0800, "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote:

¤ "Paul Clement" <UseAdddressAtEndofMessage@swspectrum.com> wrote in message
¤ news:6f2201l8okrg6l60ji6os22tgn4pamj5is@
4ax.com...
¤ > ¤ You do realize that VB and VB.Net are very different languages, right?
¤ > ¤ VB.Net questions should be asked in a group with 'dotnet' or 'vsnet' in
¤ > the
¤ > ¤ name. The responses you've gotten so far apply to VB version 6 and
¤ > earlier.
¤ >
¤ > ...and yet the code looks practically identical in VB.NET. Kind of scary,
¤ > eh? ;-)
¤
¤ That's one of the problems... the code "looks" the same but acts completely
¤ different. <g>

Not in this instance. Fibber! ;-)


Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
Karl E. Peterson

2005-02-10, 4:00 am

Ken Halter wrote:
> "Paul Clement" wrote ...
>
> That's one of the problems... the code "looks" the same but acts
> completely different. <g>


Horrors!!! (IOW, Paul finally got it right! ;-)
--
[Microsoft Basic: 1976-2001, RIP]


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com