Discussion:
What do you think of this newbie to VB6 error checking routine?
(too old to reply)
xyzzy
2012-08-09 08:49:34 UTC
Permalink
Hi guys,

I wrote this standard module, NumericInputErrorCheck, used to validate that the input from a text box is a numeric integer between the values of MinVal & MaxVal:



Option Explicit
Dim Message As Integer, N As Integer

Public Function NumericInputErrorCheck(TextInput As TextBox, MinVal As Integer, MaxVal As Integer) As Boolean

NumericInputErrorCheck = True

For N = 1 To Len(TextInput)
If Asc(Mid(TextInput, N, 1)) < 48 Or Asc(Mid(TextInput, N, 1)) > 57 Then NumericInputErrorCheck = False: Exit For
Next N

If TextInput = "" Or Val(TextInput) < MinVal Or Val(TextInput) > MaxVal Or Val(TextInput) <> Int(Val(TextInput)) Or NumericInputErrorCheck = False Then
Message = MsgBox("Please enter an integer between " & MinVal & " and " & MaxVal & ".", vbExclamation, "Error")
NumericInputErrorCheck = False
TextInput.SetFocus
TextInput.Text = ""
End If

End Function



Which seems to work a treat when I call from a textbox subroutine:

Private Sub txtInput_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then If NumericInputErrorCheck(txtInput, 1, 10) Then Print "Correct!"
End Sub


BUT I have a few queries...
1) Do you think this is the best was of error checking for an integer value?
2) Why does my system beep when I hit return? Any way of stopping it?
3) In the standard module is it necessary to declare Option Explicit?
4) In the standard module should the variables Message & N be declared within the function itself?
5) Why does 'If KeyCode = vbKeyReturn Then If NumericInputErrorCheck....' work but 'If KeyCode = vbKeyReturn and NumericInputErrorCheck....' calls the function any time a key is pressed? I thought the whole point of AND was that both arguments had to be valid.

Your feedback would be much appreciated guys :)
DaveO
2012-08-09 09:10:01 UTC
Permalink
Post by xyzzy
Hi guys,
<snip>
Post by xyzzy
BUT I have a few queries...
1) Do you think this is the best was of error checking for an integer value?
2) Why does my system beep when I hit return? Any way of stopping it?
3) In the standard module is it necessary to declare Option Explicit?
4) In the standard module should the variables Message & N be declared
within the function itself?
5) Why does 'If KeyCode = vbKeyReturn Then If NumericInputErrorCheck....'
work but 'If KeyCode = vbKeyReturn and >NumericInputErrorCheck....' calls
the function any time a key is pressed? I thought the whole point of AND
was that both arguments >had to be valid.
Your feedback would be much appreciated guys :)
You might want to look at the IsNumeric function, it'll save you a bit of
effort.



You can suppress the beep by adding:

If KeyAscii = vbKeyReturn Then KeyAscii = 0

to the KeyPress event



ALWAYS use Option Explicit, without it typing errors can go undetected



Scope: If a variable is only used in one routine then it should be declared
in that routine, if a variable spans multiple routines then as a module
variable.



AND does work that way, all parameters have to be evaluated - even if the
first one fails any subsequent ones will still be worked out.



DaveO
xyzzy
2012-08-09 10:12:28 UTC
Permalink
On Thursday, August 9, 2012 10:10:01 AM UTC+1, DaveO wrote:

<snip>
Post by DaveO
You might want to look at the IsNumeric function, it'll save you a bit of
effort.
Right. See below.
Post by DaveO
If KeyAscii = vbKeyReturn Then KeyAscii = 0
to the KeyPress event
That's brilliant!

If KeyAscii = vbKeyReturn Then KeyAscii = 0: If
NumericInputErrorCheck(txtInput, 1, 10) Then Print "Correct!"

Works a treat.
Post by DaveO
ALWAYS use Option Explicit, without it typing errors can go undetected
Sure.
Post by DaveO
Scope: If a variable is only used in one routine then it should be declared
in that routine, if a variable spans multiple routines then as a module
variable.
OK. There is only the one function in the standard module.
Post by DaveO
AND does work that way, all parameters have to be evaluated - even if the
first one fails any subsequent ones will still be worked out.
Gotcha. So Vesion 2:

Option Explicit

Public Function NumericInputErrorCheck(TextInput As TextBox, MinVal As
Integer, MaxVal As Integer) As Boolean

Dim Message As Integer

If (Not IsNumeric(TextInput)) Or (Val(TextInput) < MinVal) Or (Val
(TextInput) > MaxVal) Or (Val(TextInput) <> Int(Val(TextInput))) Then
Message = MsgBox("Please enter an integer between " & MinVal & " and " &
MaxVal & ".", vbExclamation, "Error!")
TextInput.SetFocus
TextInput.Text = ""
Exit Function
End If

NumericInputErrorCheck = True

End Function

BTW note that I have enclosed each comparison operation within brackets so it's easier to undersand at a glance. Is this considered bad programming practice?

Also, can we not declare Message as type Byte (seems to work ok) or by convention you declare it as an integer?

Thanks for your help!
Deanna Earley
2012-08-09 10:45:24 UTC
Permalink
Post by xyzzy
Also, can we not declare Message as type Byte (seems to work ok) or
by convention you declare it as an integer?
It should actually be VbMsgBoxResult which is an enum (internally an
integer type)
Post by xyzzy
Message = MsgBox("Please enter an integer between " & MinVal & " and
" & MaxVal & ".", vbExclamation, "Error!")
But as you're not asking a question, why both with the answer?
Post by xyzzy
MsgBox "Please enter an integer between " & MinVal & " and " & MaxVal
& ".", vbExclamation, "Error!"
Would work just as well.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
xyzzy
2012-08-09 11:28:04 UTC
Permalink
Post by Deanna Earley
It should actually be VbMsgBoxResult which is an enum (internally an
integer type)
Interesting. Enumerations look useful.
Post by Deanna Earley
Post by xyzzy
Message = MsgBox("Please enter an integer between " & MinVal & " and
" & MaxVal & ".", vbExclamation, "Error!")
But as you're not asking a question, why both with the answer?
Post by xyzzy
MsgBox "Please enter an integer between " & MinVal & " and " & MaxVal
& ".", vbExclamation, "Error!"
Would work just as well.
Well I always wondered this. My Learn VB manual says that although VB6 still suppoerts the MgsBox statement, Microsoft recommends using the MsgBox function for its ability to return values - but as Microsoft no longer suppoerts VB6 what the hell!
Deanna Earley
2012-08-09 11:44:05 UTC
Permalink
Post by xyzzy
Post by Deanna Earley
Post by xyzzy
Message = MsgBox("Please enter an integer between " & MinVal & " and
" & MaxVal & ".", vbExclamation, "Error!")
But as you're not asking a question, why both with the answer?
Post by xyzzy
MsgBox "Please enter an integer between " & MinVal & " and " & MaxVal
& ".", vbExclamation, "Error!"
Would work just as well.
Well I always wondered this. My Learn VB manual says that although
VB6 still suppoerts the MgsBox statement, Microsoft recommends using
the MsgBox function for its ability to return values - but as
Microsoft no longer suppoerts VB6 what the hell!
It's still a function, you're just ignoring the return value.
The Manual doesn't list it as a statement:
http://msdn.microsoft.com/en-us/library/aa338155(v=vs.60).aspx

Also, why are you learning a 15 year old language and obsoleted 5 (very
soon to be 6?) times IDE?

While there is still a large pool of VB6 code out there, I wouldn't want
to get into the maintenance market at this stage.
There are many more capable and newer languages and environments to
choose from.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
xyzzy
2012-08-09 11:56:18 UTC
Permalink
Post by Deanna Earley
It's still a function, you're just ignoring the return value.
http://msdn.microsoft.com/en-us/library/aa338155(v=vs.60).aspx
OK. I presumed functions always had brackets after the keyword.
Post by Deanna Earley
Also, why are you learning a 15 year old language and obsoleted 5 (very
soon to be 6?) times IDE?
While there is still a large pool of VB6 code out there, I wouldn't want
to get into the maintenance market at this stage.
Excellent question. I guess it's because I'm used to VB6 & don't like VB.Net & can't be asked to learn another dialect of Basic. VB6 lets me throw applications together quickly & I do it just for fun.
Post by Deanna Earley
There are many more capable and newer languages and environments to
choose from.
Out of interest, if I could be asked, what would you recommend?
Deanna Earley
2012-08-09 12:43:47 UTC
Permalink
Post by xyzzy
Post by Deanna Earley
There are many more capable and newer languages and environments to
choose from.
Out of interest, if I could be asked, what would you recommend?
It's difficult to say, as I'm not a newbie (no offence :), I use
whatever is suitable for what I'm doing :)
I have 12 years professional VB6 experience and I can't remember how
many before that. Most of my time is spent on the 10 years of legacy VB6
code with most (not all) new code being in C# 2.0.
My colleague primarily uses C++ as most of it communicates with
hardware, Direct3D, etc.

If I was starting from scratch, I'd probably try C# 4.0/WPF "as it's
new" and I can get an IDE for free (#develop and VC# express)

YMMV though. If you have the experience with VB6 (I assumed you didn't
from the "newbie to VB6") then you can stick with it.
--
Deanna Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
xyzzy
2012-08-09 13:52:29 UTC
Permalink
Post by Deanna Earley
YMMV though. If you have the experience with VB6 (I assumed you didn't
from the "newbie to VB6") then you can stick with it.
Well I have some limited experience, but now, as I have some free time on my hands, I thought I'd get down & learn it properly. I'll probably look around at other dialects of Basic after that. C++ & C# I am not a fan of. Thanks for your feedback :)
Mayayana
2012-08-09 14:19:10 UTC
Permalink
| > YMMV though. If you have the experience with VB6 (I assumed you didn't
| > from the "newbie to VB6") then you can stick with it.
|
| Well I have some limited experience, but now, as I have some free time on
my hands, I thought I'd get down & learn it properly. I'll probably look
around at other dialects of Basic after that. C++ & C# I am not a fan of.
Thanks for your feedback :)


These days, any discussion of programming languages
has to take Microsoft's plans into account. Except for
being limited to 32-bit, VB is arguably the best supported
tool on all Windows versions. (Even C++, if used in VS,
will almost always require a sizable runtime installation
on many machines -- unless one uses an older version.)

On the other hand, if Microsoft is successful with the
Metro-everywhere strategy, writing software on Windows
may not have much of a future. One can use .Net, C++,
or even script on Metro, but the only option is to write
phone/tablet trinkets, approved by Microsoft and sold
through their store. (With them getting a 30% cut.)

It's not hard to imagine a scenario in the near future
where actual computer software programs may only be
available on Linux or by pseudo-Web subscription. (I say
pseudo-Web because the cloud craze is mainly a money-
making scheme. The actual logistics are secondary. One
could have a massive program installed locally, but if a
webpage login is required to use that program then it
will be known as a cloud subscription.)

Adobe is already selling Photoshop in a 3-month subscription
version. MS is trying to make MS Office into a Web
business. Etc.)
ralph
2012-08-09 15:08:45 UTC
Permalink
On Thu, 9 Aug 2012 10:19:10 -0400, "Mayayana"
Post by Mayayana
| > YMMV though. If you have the experience with VB6 (I assumed you didn't
| > from the "newbie to VB6") then you can stick with it.
|
| Well I have some limited experience, but now, as I have some free time on
my hands, I thought I'd get down & learn it properly. I'll probably look
around at other dialects of Basic after that. C++ & C# I am not a fan of.
Thanks for your feedback :)
These days, any discussion of programming languages
has to take Microsoft's plans into account. Except for
being limited to 32-bit, VB is arguably the best supported
tool on all Windows versions. (Even C++, if used in VS,
will almost always require a sizable runtime installation
on many machines -- unless one uses an older version.)
Suggesting that MSC or MSVC++, is less supported across Windows
versions is absolutely false. C and VC++ runtimes, have been supplied
with every Windows PC platform.

Based on "dependencies" one might easily get the impression that a
program developed with a MS C/VC++ (or MFC) platform might be
sizeable, but in fact, very little needs to be bundled with an install
package since most is already there.

The reason this is so, is simply because Windows and its utilities are
themselves highly dependent on C/C++ runtimes. As is VB.

If "extras" or "version" ever should become a concern, consider that
C/C++ allows one to statically link libraries.

-ralph
Mayayana
2012-08-09 15:48:12 UTC
Permalink
| Suggesting that MSC or MSVC++, is less supported across Windows
| versions is absolutely false. C and VC++ runtimes, have been supplied
| with every Windows PC platform.
|

It's not a big issue, but there is less support. The VB6
runtime is on nearly all currently-running PCs. Half of
business PCs are still XP, which predates the later versions
of VC. I'm on XP. If I try to install software written with
VC10 then in most cases I'll have to also install the VC10
runtime, which requires XP SP3, and will probably add
8-10 MB to my system. With VB6, by contrast, in most
cases my software doesn't even need to be installed, and
it can run on Win95+. Only VC6 has equivalent support. Each
later version of VC, as you know, has its own runtime.
ralph
2012-08-09 18:34:56 UTC
Permalink
On Thu, 9 Aug 2012 11:48:12 -0400, "Mayayana"
Post by Mayayana
| Suggesting that MSC or MSVC++, is less supported across Windows
| versions is absolutely false. C and VC++ runtimes, have been supplied
| with every Windows PC platform.
|
It's not a big issue, but there is less support. The VB6
runtime is on nearly all currently-running PCs. Half of
business PCs are still XP, which predates the later versions
of VC. I'm on XP. If I try to install software written with
VC10 then in most cases I'll have to also install the VC10
runtime, which requires XP SP3, and will probably add
8-10 MB to my system. With VB6, by contrast, in most
cases my software doesn't even need to be installed, and
it can run on Win95+. Only VC6 has equivalent support. Each
later version of VC, as you know, has its own runtime.
HA.

Doubt if I would use the term "less support" to characterize a
situation where there have been no changes in twelve years, thus less
need to be concerned with versioning. But I suppose one could, and
obviously has. <g>

But then all of this is of concern only to someone who intends to
distribute his creations.

-ralph
Farnsworth
2012-08-10 17:06:06 UTC
Permalink
Post by Mayayana
| Suggesting that MSC or MSVC++, is less supported across Windows
| versions is absolutely false. C and VC++ runtimes, have been supplied
| with every Windows PC platform.
|
It's not a big issue, but there is less support. The VB6
runtime is on nearly all currently-running PCs. Half of
business PCs are still XP, which predates the later versions
of VC. I'm on XP. If I try to install software written with
VC10 then in most cases I'll have to also install the VC10
runtime, which requires XP SP3, and will probably add
8-10 MB to my system. With VB6, by contrast, in most
cases my software doesn't even need to be installed, and
it can run on Win95+. Only VC6 has equivalent support. Each
later version of VC, as you know, has its own runtime.
I think what you mean by "less support" is less support for C++ by Microsoft
in Windows 8, and perhaps less support in the future. I don't think so, but
not really care much about Windows anymore. I plan to use a language that is
at least supports multiple platforms for any new project, so my customers
can leave Windows if they wanted to. As for your attempt with VC10, it's
remarkable that you were able to make something together so fast. I don't
have VC10 installed, but I have VC9(VC 2008), and in that the default seems
to use the runtime in DLL. I made it so it doesn't require the DLL version
of the run time, so simply run the EXE, or drop the DLL into the app folder.
Dependency Walker shows only KERNEL32.dll as the only dependency that a
Standard DLL I made with VC9 requires. For details on how to make VC do it
that way, see this post:

https://groups.google.com/group/microsoft.public.vb.general.discussion/msg/d13dc97bfbf6031a?dmode=source&output=gplain&noredirect
Tom Shelton
2012-08-10 21:44:16 UTC
Permalink
Post by Mayayana
Post by ralph
Suggesting that MSC or MSVC++, is less supported across Windows
versions is absolutely false. C and VC++ runtimes, have been
supplied with every Windows PC platform.
It's not a big issue, but there is less support. The VB6
runtime is on nearly all currently-running PCs. Half of
business PCs are still XP, which predates the later versions
of VC. I'm on XP. If I try to install software written with
VC10 then in most cases I'll have to also install the VC10
runtime, which requires XP SP3, and will probably add
8-10 MB to my system. With VB6, by contrast, in most
cases my software doesn't even need to be installed, and
it can run on Win95+. Only VC6 has equivalent support. Each
later version of VC, as you know, has its own runtime.
LOL... Just because you are an idiot, doesn't make you right. See, C++
supports this little concept called static linking. Look it up
sometime... DUH!
--
Tom Shelton
Mayayana
2012-08-11 00:47:14 UTC
Permalink
| LOL... Just because you are an idiot, doesn't make you right. See, C++
| supports this little concept called static linking. Look it up
| sometime... DUH!

I think you may have misunderstood. All I was saying
was that most software written in VC will require
installation of the respective runtime on machines where
it's not pre-installed. The VC6 runtime is ubiquitous, as
is the VB6 runtime. Newer VC runtimes are not.
Farnsworth
2012-08-11 07:09:21 UTC
Permalink
Post by Mayayana
| LOL... Just because you are an idiot, doesn't make you right. See, C++
| supports this little concept called static linking. Look it up
| sometime... DUH!
I think you may have misunderstood. All I was saying
was that most software written in VC will require
installation of the respective runtime on machines where
it's not pre-installed. The VC6 runtime is ubiquitous, as
is the VB6 runtime. Newer VC runtimes are not.
The runtime and many libraries come in two forms:

1 - Static, usually in a ".lib" file in VC, or ".a" file in GCC(the "a"
stands for Archive). This is a precompiled binary and it becomes as part of
the file that you are compiling. This is like including a UserControl as
part of the EXE as opposed to put it in an OCX file.
2 - Dynamic(".dll" in Windows, ".so" in Unix-like("so"=Shared Object),
".dylib" in OS X).

So why would one want a DLL? It has advantages and disadvantages.

Advantages:

1 - The file becomes smaller, since it doesn't include the runtime or the
shared code, and it requires less RAM.
2 - The DLL can be updated which may include bug fixes.
3 - Binary compatibility when sharing UDT's or classes. This is not the same
as COM Binary Compatibility, but it's similar. Example: You have a UDT that
you want to send between an EXE and two DLL's. You implement it on one of
the DLL's, and others call that DLL to operate on the UDT. This way you have
one version of the UDT at all times. If each were to have a replica of the
declaration, then if you update one of the DLL's or EXE, things would go out
of sync, and get unexpected results. This is true for other languages, such
as Delphi. So if you intend to share objects between files, you must use the
DLL version that implements that object.

Disadvantages:

1 - If every EXE or DLL was statically linked, files gets bigger, and the
redundant code requires more RAM.
2 - The DLL could be replaced by a buggy or older one, affecting your
application behavior. This also explains why Windows 9x was unstable after
you install more products or drivers. MSVCRT.DLL(MS=Microsoft,VC=Visual C++,
RT=RunTime) was one such file that was used by VC5/6. MS used it heavily and
was sharing many of the objects, so they had to use the DLL version. If MS
called the DLL "OSVCRT.DLL" for anything they produced, and "MSVCRT.DLL" for
everybody else, then Windows 9x would have been more stable.

Here is the file size of a standard DLL that I made with VC9(2008), it's
basically an empty DLL with only one function: DllMain with the minimal code
it requires:

1 - Static: File size: 41,472 bytes. Dependency Walker list of DLL's that it
depends on:

KERNEL32.DLL

2 - Dynamic: File size: 6,656 bytes. Dependency Walker list of DLL's that it
depends on:

KERNEL32.DLL
MSVCR90.DLL
Mayayana
2012-08-11 12:25:41 UTC
Permalink
| The runtime and many libraries come in two forms:
|

You're both turning this into a complex issue. (Though I
do appreciate your gracious style in contrast with Tom
"you moron" Shelton. :)

I'm running WinXP. I have the v. 6 and v. 7.1 C++ runtimes.
If I download software written in VC9 it will *probably* require
me to install the runtimes. *Probably* is what I said in the
first place. For all practical purposes there is no one who will
need to install the VB6 runtimes.

The whole idea was to point out the need for context in
talking about programming languages: VB6 is currently supported,
with no practical dependencies, nearly eveywhere. C++ will no
doubt outlive VB on Windows, but that won't do any good if no
one without a Microsoft business partnership can write Windows
software... or if C++ is reduced to an awkward tool for writing
tablet trinkets. In the meantime, VB6 has universal support, except
for the 64-bit limitations. (That's been on my mind lately. Last
week someone wrote to me with trouble instantiating an object
from one of my COM DLLs in VBScript. He couldn't be bothered
to understand the issues and gave up trying to make it work.)

To my mind, anything beyond the next 2-3 of years is going
to depend on factors like the success of Metro, the trends with
tablets, the future of social media, etc. Lately Microsoft are
putting the Windows monopoly at risk in an attempt to create
a Microsoft online services customer base to be "monetized" via
Metro phones and tablets. It remains to be seen whether they're
really so willing to drop the PC market, or whether they firmly
believe they own it and can't lose it, or whether this is all more
like when Bill Gates famously grokked the Internet by putting
links to Disney ads on the Desktop.... much tile ado about nothing.

----------------------------------

| 1 - Static, usually in a ".lib" file in VC, or ".a" file in GCC(the "a"
| stands for Archive). This is a precompiled binary and it becomes as part
of
| the file that you are compiling. This is like including a UserControl as
| part of the EXE as opposed to put it in an OCX file.
| 2 - Dynamic(".dll" in Windows, ".so" in Unix-like("so"=Shared Object),
| ".dylib" in OS X).
|
| So why would one want a DLL? It has advantages and disadvantages.
|
| Advantages:
|
| 1 - The file becomes smaller, since it doesn't include the runtime or the
| shared code, and it requires less RAM.
| 2 - The DLL can be updated which may include bug fixes.
| 3 - Binary compatibility when sharing UDT's or classes. This is not the
same
| as COM Binary Compatibility, but it's similar. Example: You have a UDT
that
| you want to send between an EXE and two DLL's. You implement it on one of
| the DLL's, and others call that DLL to operate on the UDT. This way you
have
| one version of the UDT at all times. If each were to have a replica of the
| declaration, then if you update one of the DLL's or EXE, things would go
out
| of sync, and get unexpected results. This is true for other languages,
such
| as Delphi. So if you intend to share objects between files, you must use
the
| DLL version that implements that object.
|
| Disadvantages:
|
| 1 - If every EXE or DLL was statically linked, files gets bigger, and the
| redundant code requires more RAM.
| 2 - The DLL could be replaced by a buggy or older one, affecting your
| application behavior. This also explains why Windows 9x was unstable after
| you install more products or drivers. MSVCRT.DLL(MS=Microsoft,VC=Visual
C++,
| RT=RunTime) was one such file that was used by VC5/6. MS used it heavily
and
| was sharing many of the objects, so they had to use the DLL version. If MS
| called the DLL "OSVCRT.DLL" for anything they produced, and "MSVCRT.DLL"
for
| everybody else, then Windows 9x would have been more stable.
|
| Here is the file size of a standard DLL that I made with VC9(2008), it's
| basically an empty DLL with only one function: DllMain with the minimal
code
| it requires:
|
| 1 - Static: File size: 41,472 bytes. Dependency Walker list of DLL's that
it
| depends on:
|
| KERNEL32.DLL
|
| 2 - Dynamic: File size: 6,656 bytes. Dependency Walker list of DLL's that
it
| depends on:
|
| KERNEL32.DLL
| MSVCR90.DLL
|
|
Farnsworth
2012-08-13 09:09:54 UTC
Permalink
Post by Mayayana
|
You're both turning this into a complex issue. (Though I
do appreciate your gracious style in contrast with Tom
"you moron" Shelton. :)
I'm running WinXP. I have the v. 6 and v. 7.1 C++ runtimes.
If I download software written in VC9 it will *probably* require
me to install the runtimes. *Probably* is what I said in the
first place. For all practical purposes there is no one who will
need to install the VB6 runtimes.
I have seen some VC developers use the Shared DLL for the runtime, even when
it's not required. Sometimes it's deliberate and sometimes it's
forgetfulness or ignorance. If the author didn't say what the redistribution
requirements are, then it's a clue for me to stay away from such product.
Test the EXE or DLL with Dependency Walker. If you see files that depend on
MSVCRTx.DLL, then the author used the Shared DLL option, perhaps because it
was the default. You can tell the author to use the static linking option.
Here are the instructions:

- Go to Project-->Properties, and select Configuration Properties-->General.
- Set these options as follows:

Use of MFC: Use Standard Windows Libraries, or Use MFC in a Static Library
Use of ATL: Not Using ATL, or Static Link to ATL.

If you chose things like "Not Using ATL", and you were using it, then you
get compilation errors. ATL is what they use in VC to make ActiveX
DLL/OCX/EXE files.

Tom Shelton
2012-08-11 07:27:10 UTC
Permalink
Post by Mayayana
Post by Tom Shelton
LOL... Just because you are an idiot, doesn't make you right. See,
C++ supports this little concept called static linking. Look it up
sometime... DUH!
I think you may have misunderstood. All I was saying
was that most software written in VC will require
installation of the respective runtime on machines where
it's not pre-installed. The VC6 runtime is ubiquitous, as
is the VB6 runtime. Newer VC runtimes are not.
Nope. Static linking. Again, look it up.
--
Tom Shelton
Farnsworth
2012-08-11 05:55:17 UTC
Permalink
Post by Tom Shelton
Post by Mayayana
Post by ralph
Suggesting that MSC or MSVC++, is less supported across Windows
versions is absolutely false. C and VC++ runtimes, have been supplied
with every Windows PC platform.
It's not a big issue, but there is less support. The VB6
runtime is on nearly all currently-running PCs. Half of
business PCs are still XP, which predates the later versions
of VC. I'm on XP. If I try to install software written with
VC10 then in most cases I'll have to also install the VC10
runtime, which requires XP SP3, and will probably add
8-10 MB to my system. With VB6, by contrast, in most
cases my software doesn't even need to be installed, and
it can run on Win95+. Only VC6 has equivalent support. Each
later version of VC, as you know, has its own runtime.
LOL... Just because you are an idiot, doesn't make you right. See, C++
supports this little concept called static linking. Look it up
sometime... DUH!
You expect someone new to a language to know every little detail? Most
beginners put of learning redistribution requirements last, and often years
later.
xyzzy
2012-08-09 18:45:04 UTC
Permalink
Post by Mayayana
These days, any discussion of programming languages
has to take Microsoft's plans into account. Except for
being limited to 32-bit, VB is arguably the best supported
tool on all Windows versions...
Well said. My sentiments exactly. See http://developers.slashdot.org/story/12/06/09/0240204/why-visual-basic-6-still-thrives
Mayayana
2012-08-09 20:44:48 UTC
Permalink
| Well said. My sentiments exactly. See
http://developers.slashdot.org/story/12/06/09/0240204/why-visual-basic-6-still-thrives

I remember that one. A typical Slashdot discussion
of VB, with most barely containing their contempt, while
David Platt is making the bizarre claim that VB.Net was
meant to give power to VBers.
I have a COM book by David Platt, in which he's similarly
contemptuous. That seems to be a "schtick" that he
relishes, as his column is called "Don't Get Me Started".
(Fortunately I bought it his book as a remainder. :)
Leo Bramwell-Speer
2012-08-09 21:42:24 UTC
Permalink
Post by Mayayana
I remember that one. A typical Slashdot discussion
of VB, with most barely containing their contempt, while
David Platt is making the bizarre claim that VB.Net was
meant to give power to VBers.
I have a COM book by David Platt, in which he's similarly
contemptuous. That seems to be a "schtick" that he
relishes, as his column is called "Don't Get Me Started".
(Fortunately I bought it his book as a remainder. :)
Lol! I think there's some valid points though.
--
Leo
http://leobs.net/
Auric__
2012-08-10 05:20:30 UTC
Permalink
Post by xyzzy
Post by Mayayana
These days, any discussion of programming languages
has to take Microsoft's plans into account. Except for
being limited to 32-bit, VB is arguably the best supported
tool on all Windows versions...
Well said. My sentiments exactly. See
http://developers.slashdot.org/story/12/06/09/0240204/why-visual-basic-6-
still-thrives
"They didn't lament the lack of operator overloading or polymorphism in
Visual Basic 6 [...]"

Maybe not, but there are times when they would've made my life easier...
--
This guy is a restraining order waiting to happen.
xyzzy
2012-08-09 11:34:04 UTC
Permalink
On Thursday, August 9, 2012 12:28:04 PM UTC+1, xyzzy wrote:
.
.
Well I always wondered this...
This throws up another question. My standard module code is now:


Option Explicit

Public Function NumericInputErrorCheck(TextInput As TextBox, MinVal As Integer, MaxVal As Integer) As Boolean

If (Not IsNumeric(TextInput)) Or (Val(TextInput) < MinVal) Or (Val(TextInput) > MaxVal) Or _
(Val(TextInput) <> Int(Val(TextInput))) Then
MsgBox "Please enter an integer between " & MinVal & " and " & MaxVal & ".", vbExclamation, "Error!"
TextInput.SetFocus
TextInput.Text = ""
Exit Function
End If

NumericInputErrorCheck = True

End Function


Question: I guess there is no need now for the Option Explicit?
DaveO
2012-08-09 14:43:10 UTC
Permalink
Post by xyzzy
If (Not IsNumeric(TextInput)) Or (Val(TextInput) < MinVal) Or
(Val(TextInput) > MaxVal) Or _
Except in certain cases such as Label = "Hello World" I would avoid relying
on default properrties so the above should really be:
If (Not IsNumeric(TextInput.Text)) Or (Val(TextInput.Text) < MinVal) Or
(Val(TextInput.Text) > MaxVal) Or _

You asked earlier about brackets, if they make to expression clearer and
avoid ambiguous evaluation then yes, the more the merrier. There is no
problem with the brackets in the above line.
Post by xyzzy
Question: I guess there is no need now for the Option Explicit?
Wrong, wrong and a thousand times wrong!

It may well be OK now but if you return and add something else later and
were to type "MinVa1" instead of "MinVal" (Number 1 instead of lower case L)
without Option Explicit you could search for the weird error for weeks, with
Option Explicit it just won't run and will highlight the typo.

I'd strongly suggest going to the Tools/Options menu and ticking "Require
Variable Declaration". This will automatically add "Option Explicit" to all
new forms and modules when they are first created.




DaveO
xyzzy
2012-08-09 18:53:56 UTC
Permalink
Post by DaveO
Except in certain cases such as Label = "Hello World" I would avoid relying
If (Not IsNumeric(TextInput.Text)) Or (Val(TextInput.Text) < MinVal) Or
(Val(TextInput.Text) > MaxVal) Or _
Yes thinking about that I agree with that.
Post by DaveO
You asked earlier about brackets, if they make to expression clearer and
avoid ambiguous evaluation then yes, the more the merrier. There is no
problem with the brackets in the above line
That's a relief :)
Post by DaveO
Post by xyzzy
Question: I guess there is no need now for the Option Explicit?
Wrong, wrong and a thousand times wrong!
It may well be OK now but if you return and add something else later and
were to type "MinVa1" instead of "MinVal" (Number 1 instead of lower case L)
without Option Explicit you could search for the weird error for weeks, with
Option Explicit it just won't run and will highlight the typo.
I'd strongly suggest going to the Tools/Options menu and ticking "Require
Variable Declaration". This will automatically add "Option Explicit" to all
new forms and modules when they are first created.
Yes, very good advice, thankyou DaveO
xyzzy
2012-08-09 11:04:14 UTC
Permalink
Post by Deanna Earley
It should actually be VbMsgBoxResult which is an enum (internally an
integer type)
Interesting. Enumerations look useful.
Post by Deanna Earley
But as you're not asking a question, why both with the answer?
Post by xyzzy
MsgBox "Please enter an integer between " & MinVal & " and " & MaxVal
& ".", vbExclamation, "Error!"
Would work just as well.
Well yes I always wondered this. I quote from my Learn VB6 manual: 'Although Visual Basic still supports the MsgBox statement, Microsoft recommends that you use only the MsgBox() function because of its inspection ability for a return value.' That was why - I wanted to do it 'properly', but, as Microsoft no longer supports VB6, what the hell :)
Eduardo
2012-08-09 19:45:48 UTC
Permalink
Post by xyzzy
BTW note that I have enclosed each comparison operation within brackets so
it's easier to undersand at a glance. Is this considered bad programming
practice?
I consider it a good programming practice, since the AND/OR operators can
operate not just as operators for evaluating conditions, but also as
arithmetic operators. And sometimes the code could work in an unexpected way
if you don't enclose the conditions into brackets.
At least it's what I decided to do after having to debug some strange errors
due to the AND/OR operators acting as an arithmetic operator when they were
intended to evaluate a condition.
Leo Bramwell-Speer
2012-08-09 21:48:25 UTC
Permalink
Post by Eduardo
I consider it a good programming practice, since the AND/OR operators
can operate not just as operators for evaluating conditions, but also
as arithmetic operators. And sometimes the code could work in an
unexpected way if you don't enclose the conditions into brackets.
At least it's what I decided to do after having to debug some strange
errors due to the AND/OR operators acting as an arithmetic operator
when they were intended to evaluate a condition.
Yes that's very true about strange errors caused by that.
--
Leo
http://leobs.net/
Ivar
2012-08-09 14:37:29 UTC
Permalink
Something Like The Code Below May Be A Bit Wiser if you really need to check
the value before user can do anything else :0)

Ivar

Option Explicit

Public Function NumericInputErrorCheck(StrVar, MinVal As Integer, MaxVal As
Integer) As Boolean
Dim TestInt As Integer
TestInt = CInt(Val(StrVar))
Select Case True
Case TestInt <> StrVar, TestInt < MinVal, TestInt > MaxVal, Not
IsNumeric(StrVar)
Case Else
NumericInputErrorCheck = True
End Select
End Function

Private Sub txtInput_KeyPress(KeyAscii As Integer)
Dim BoolVar As Boolean
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
txtInput_Validate BoolVar
If Not BoolVar Then
'NextControl.SetFocus
End If
End If
End Sub

Private Sub txtInput_Validate(Cancel As Boolean)
If Not NumericInputErrorCheck(txtInput.Text, 1, 10) Then
Cancel = True
MsgBox "Please Enter A whole Number Between 1 and 10.", vbExclamation,
"Invalid Input"
txtInput.SelStart = 0
txtInput.SelLength = Len(txtInput.Text)
End If
End Sub
DaveO
2012-08-09 14:48:43 UTC
Permalink
Post by Ivar
Select Case True
This is not going to end well!

I think I'll sit back and wait for the inevitable opprobrium

:-)

DaveO.
xyzzy
2012-08-09 18:49:55 UTC
Permalink
Post by Ivar
Something Like The Code Below May Be A Bit Wiser if you really need to check
the value before user can do anything else :0)
Yup! It's called Error Checking :)
Post by Ivar
Option Explicit
Public Function NumericInputErrorCheck(StrVar, MinVal As Integer, MaxVal As
Integer) As Boolean
Dim TestInt As Integer..etc
No offence, but I really don't see how this code is in any way better. Seems longer or more convoluted to me.
Ivar
2012-08-10 07:53:02 UTC
Permalink
Post by Ivar
Something Like The Code Below May Be A Bit Wiser if you really need to check
the value before user can do anything else :0)
Yup! It's called Error Checking :)
I call it idiot proofing, because all end users are idiots.
What I mean is, before the user can do ANYTHING else, like setting focus on
another control by Tabbing or clicking somewhere.
Maybe look in to 'Error Checking' after the user has (for example) clicked
the save button but before the code in the save button executes (or
whatever)
Depends on what you're doing of course.
Post by Ivar
Option Explicit
Public Function NumericInputErrorCheck(StrVar, MinVal As Integer, MaxVal As
Integer) As Boolean
Dim TestInt As Integer..etc
No offence, but I really don't see how this code is in any way better.
Seems longer or more convoluted to me.
No offence taken in any way
Just my Opinion here but:
You code is ugly and hard to read
You pass a control as an Arg when all you need is a String Variable.
Using Default properties is a bad idea
The function changes properties in a control. taking away the global use of
the function. The control you pass might not have a default property or a
text property or a SetFocus method.
If end user enters '22' then the function reads the default property of the
passed control 9 times, My example, None.
if end user enters '22' then the function calls intrinsic VB6 functions 9
times, My example, Three.
It's a bad idea to put a Msgbox within the function itself. It should be in
the procedure that calls the function.
oops, My baad, StrVar is a Variant, should be declared as String, but I'm
sure you spotted that.
We were all users once. No offence intended of course.


Ivar
Mike Williams
2012-08-10 10:42:47 UTC
Permalink
Post by Ivar
I call it idiot proofing, because all end users are idiots.
Are you the end user of anything ;-)

Mike
Ivar
2012-08-10 11:03:02 UTC
Permalink
Post by Ivar
I call it idiot proofing, because all end users are idiots.
Are you the end user of anything ;-)

Hello mike. :-)
Indeed I am an end user, But I can state as a fact that I am not an idiot!
It's the computer that's an idiot because it keeps doing what I tell it to
do instead of what I want it to do.
If I clicked the No button when I meant to click the Yes button Why O Why O
Why does the computer act as if I clicked the No Button.
I will be writing an app that deals with this very serious issue but not
until next week.
This week I am very busy inventing warp drive, replicators, phasers, photon
torpedoes and a cure for all know diseases.
Last week I wrote the best app in the world, ever! Then forgot to save it.
See - All computers are idiots.

Ivar
Coder X
2012-08-09 16:56:54 UTC
Permalink
Ugh. Google Hungarian notation and clean that up. My eyes hurt.


"xyzzy" <***@gmail.com> wrote in message news:653bdff7-41f4-4ade-aa97-***@googlegroups.com...
Hi guys,

I wrote this standard module, NumericInputErrorCheck, used to validate that
the input from a text box is a numeric integer between the values of MinVal
& MaxVal:



Option Explicit
Dim Message As Integer, N As Integer

Public Function NumericInputErrorCheck(TextInput As TextBox, MinVal As
Integer, MaxVal As Integer) As Boolean

NumericInputErrorCheck = True

For N = 1 To Len(TextInput)
If Asc(Mid(TextInput, N, 1)) < 48 Or Asc(Mid(TextInput, N, 1)) > 57
Then NumericInputErrorCheck = False: Exit For
Next N

If TextInput = "" Or Val(TextInput) < MinVal Or Val(TextInput) > MaxVal
Or Val(TextInput) <> Int(Val(TextInput)) Or NumericInputErrorCheck = False
Then
Message = MsgBox("Please enter an integer between " & MinVal & " and
" & MaxVal & ".", vbExclamation, "Error")
NumericInputErrorCheck = False
TextInput.SetFocus
TextInput.Text = ""
End If

End Function



Which seems to work a treat when I call from a textbox subroutine:

Private Sub txtInput_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then If NumericInputErrorCheck(txtInput, 1, 10)
Then Print "Correct!"
End Sub


BUT I have a few queries...
1) Do you think this is the best was of error checking for an integer value?
2) Why does my system beep when I hit return? Any way of stopping it?
3) In the standard module is it necessary to declare Option Explicit?
4) In the standard module should the variables Message & N be declared
within the function itself?
5) Why does 'If KeyCode = vbKeyReturn Then If NumericInputErrorCheck....'
work but 'If KeyCode = vbKeyReturn and NumericInputErrorCheck....' calls the
function any time a key is pressed? I thought the whole point of AND was
that both arguments had to be valid.

Your feedback would be much appreciated guys :)
xyzzy
2012-08-09 18:59:44 UTC
Permalink
Post by Coder X
Ugh. Google Hungarian notation and clean that up. My eyes hurt.
Lol :)
ralph
2012-08-10 01:44:43 UTC
Permalink
Post by xyzzy
Post by Coder X
Ugh. Google Hungarian notation and clean that up. My eyes hurt.
Lol :)
Technically it isn't Hungarian but an early derivative called
Leszynski. (The "val" suggests perhaps an even earlier
Leszynski/Reddick.)

'True' Hungarian is limited to specific data types, and is far more
restrictive, thus with a migration away from simple data types to
objects and multiple resources has been pretty much abandoned.

This has lead to many developers to erroneously assume that a naming
convention based on prefix's or suffixes (tags, qualifiers, base, ...)
is no longer useful. Such is not the case. The value of adopting a
consistent naming convention (for an enterprise or just one) has
proven its value.

-ralph
Loading...