By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Option Strict On and Ubound

P: n/a
Hi all

Generally, it seems Option Strict ON is recommended
practice? How, then, does one reconcile
--
Option Strict On

Public MyArray(6) Single

'Some Code here

For i = 0 to Ubound(MyArray)
--
I get the error "Option Strict on disallows implicit
conversions from 'Integer' to 'Short'" on the last line
for Ubound. CType or a conversion function doesn't seem to
be the right thing, either.

Cindy Meister

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cindy,
How did you define i?

You can solve this two ways:

' VB.NET 2003 syntax
For i As Short = 0 to CShort(Ubound(MyArray))
Next

For i As Integer = 0 to UBound(MyArray))
Next

I normally use MyArray.Length - 1 instead of the UBound function.

Hope this helps
Jay

"Cindy Meister -WordMVP-" <Ci**********@XSPMswissonline.com> wrote in
message news:VA.000087e0.0117252e@speedy...
Hi all

Generally, it seems Option Strict ON is recommended
practice? How, then, does one reconcile
--
Option Strict On

Public MyArray(6) Single

'Some Code here

For i = 0 to Ubound(MyArray)
--
I get the error "Option Strict on disallows implicit
conversions from 'Integer' to 'Short'" on the last line
for Ubound. CType or a conversion function doesn't seem to
be the right thing, either.

Cindy Meister

Nov 20 '05 #2

P: n/a
Cindy Meister -WordMVP- <Ci**********@XSPMswissonline.com> scripsit:
Generally, it seems Option Strict ON is recommended
practice? How, then, does one reconcile
--
Option Strict On

Public MyArray(6) Single

'Some Code here

For i = 0 to Ubound(MyArray)


Are you sure that 'i' is declared as 'Integer'?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Hi Jay / Herfried

Thanks to you both. It never occurred to me <duh> that the data
types within the For...to had to match. Now that you've pointed it
out to me, it's clear that option Strict would require this. But my
VB(A)-steeped instincts did't recognize it!
I normally use MyArray.Length - 1 instead of the UBound function.

And thanks for this, Jay :-) I'm trying to convert "me" (the object
typing on the keyboard), but I suspect I picked up the wrong book
for acquiring the NET syntax (Step-by-step). I'd have thought such
"baby-step" exercises would be an excellent place to introduce .NET
syntax alternatives, but the author certainly hasn't done so!

--Cindy

Nov 20 '05 #4

P: n/a
Cindy,
typing on the keyboard), but I suspect I picked up the wrong book
for acquiring the NET syntax (Step-by-step). I'd have thought such I'm sure its a style thing. I have enough OOP language background (C++,
Java) that using Framework directly makes sense.

I'm not sure of any specific books that "introduce .NET syntax
alternatives".

Charles Petzold's book "Programming Microsoft Windows with Microsoft Visual
Basic .NET" has 3 appendixes in the back which covers Files & Streams, Math
Classes, and String Theory. All three appendixes are good intros into the
".NET Syntax alternatives". I wish the three appendixes were available
separately! The rest of the book does a good job of covering Windows Forms,
from a perspective that does not rely on VS.NET.

Matthew MacDonald's book "Microsoft Visual Basic Programmer's Cookbook"
mostly does a good job of providing the ".NET syntax". Plus its a good
cookbook on how to do things, at least get started doing things in .NET.

Hope this helps
Jay

"Cindy Meister -WordMVP-" <Ci**********@XSPMswissonline.com> wrote in
message news:VA.000087ed.00ae60de@speedy... Hi Jay / Herfried

Thanks to you both. It never occurred to me <duh> that the data
types within the For...to had to match. Now that you've pointed it
out to me, it's clear that option Strict would require this. But my
VB(A)-steeped instincts did't recognize it!
I normally use MyArray.Length - 1 instead of the UBound function.

And thanks for this, Jay :-) I'm trying to convert "me" (the object
typing on the keyboard), but I suspect I picked up the wrong book
for acquiring the NET syntax (Step-by-step). I'd have thought such
"baby-step" exercises would be an excellent place to introduce .NET
syntax alternatives, but the author certainly hasn't done so!

--Cindy

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.