Option Strict disallows late binding, need to update code

C

CodeMonkey

Hi All
the following code generates an error with option strict on - Option
strict disallows late binding. Can someone please help with what needs
to be changed:

Dim sweep, totalsweep As Integer
Dim slices As Array = Split("26, 40, 34",",")
Dim colors() As Color = { _
Color.Blue, Color.LimeGreen, _
Color.Purple}
Dim brush As System.Drawing.SolidBrush
Dim g As System.Drawing.Graphics
g = Me.CreateGraphics

For i As Integer = 0 To UBound(slices)

brush = New System.Drawing.SolidBrush(colors(i))
sweep = 360 * (CLng(slices(i)) / 100) '<----PROBLEM HERE
If totalsweep + sweep > 360 Then _
sweep = 360 - totalsweep
g.FillPie(brush, New Rectangle(0, 0, 80, 80), _
totalsweep, sweep)
totalsweep += sweep
Next

Thanks
CodeMonkey.
 
H

Herfried K. Wagner [MVP]

CodeMonkey said:
the following code generates an error with option strict on - Option
strict disallows late binding. Can someone please help with what needs
to be changed:

Dim sweep, totalsweep As Integer
Dim slices As Array = Split("26, 40, 34",",")
Dim colors() As Color = { _
Color.Blue, Color.LimeGreen, _
Color.Purple}
Dim brush As System.Drawing.SolidBrush
Dim g As System.Drawing.Graphics
g = Me.CreateGraphics

For i As Integer = 0 To UBound(slices)

brush = New System.Drawing.SolidBrush(colors(i))
sweep = 360 * (CLng(slices(i)) / 100) '<----PROBLEM HERE

Replace the line above with this:

\\\
sweep = CInt(360 * (CLng(slices.GetValue(i)) / 100))
///
 
G

Guest

You may also want to change
Dim slices As Array = Split("26, 40, 34",",")
to
Dim slices() As String = Split("26, 40, 34", ",")
because it appears that your intention is that slices is an array of strings.
 
S

Samuel R. Neff

Change this line:

Dim slices As Array = Split("26, 40, 34", ",")

To

Dim slices As String() = Split("26, 40, 34", ",")

HTH,

Sam


Hi All
the following code generates an error with option strict on - Option
strict disallows late binding. Can someone please help with what needs
to be changed:

Dim sweep, totalsweep As Integer
Dim slices As Array = Split("26, 40, 34",",")
Dim colors() As Color = { _
Color.Blue, Color.LimeGreen, _
Color.Purple}
Dim brush As System.Drawing.SolidBrush
Dim g As System.Drawing.Graphics
g = Me.CreateGraphics

For i As Integer = 0 To UBound(slices)

brush = New System.Drawing.SolidBrush(colors(i))
sweep = 360 * (CLng(slices(i)) / 100) '<----PROBLEM HERE
If totalsweep + sweep > 360 Then _
sweep = 360 - totalsweep
g.FillPie(brush, New Rectangle(0, 0, 80, 80), _
totalsweep, sweep)
totalsweep += sweep
Next

Thanks
CodeMonkey.

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
H

Herfried K. Wagner [MVP]

AMercer said:
You may also want to change
Dim slices As Array = Split("26, 40, 34",",")
to
Dim slices() As String = Split("26, 40, 34", ",")
because it appears that your intention is that slices is an array of
strings.

Full ACK. Thanks for adding that... :).
 
M

Marcie Jones

Or even:
Dim slices As Array = Split("26, 40, 34", ",")
Dim slices As String() = Split("26, 40, 34", ",")

to
Dim slices As String() = {"26", "40", "34"}

Marcie
 
S

Samuel R. Neff

Or

Dim slices As Integer() = {26, 40, 34}

Then no need for conversion later.

Sam


Or even:


to
Dim slices As String() = {"26", "40", "34"}

Marcie
B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
C

CodeMonkey

All,
thanks for your extremely prompt and accurate help.

Regards
CodeMonkey.
 

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