Search code examples
vb.netoption-strict

Option Strict ON made some errors


I had to enable Option Script, in order to use properly OpenXML package. Once I've done, I had several errors, regarding implicit conversions from a type to another.

Label6.Text = FormatNumber(CInt(Form3.Label12.Text), "0.00") 'O.S. On disallows implicit conversions from String to Integer'

hrrspk.Add(Form3.ListBox2.Items(i)) 'O.S. On disallows implicit conversions from Double to Integer'

tsdom.Add(((hrrspk(ts) - CInt(Label6.Text)) * (CInt(Label3.Text) - CInt(Label4.Text)) / (CInt(Label6.Text))) + CInt(Label4.Text)) 'O.S. On disallows implicit conversions from Double to Integer'

hrrnativexcel = CreateObject("EXCEL.APPLICATION") 'O.S. On disallows implicit conversions from Object to Application'

hrrnativexcel.Cells(1, 1).value = "Time [s]" 'O.S. On disallows late binding'

For Each o As String In Form3.ListBox1.Items.Cast(Of Object).Zip(Form3.ListBox2.Items.Cast(Of Object), Function(x1, x2) x1 & "," & x2) 'O.S. On prohibits operands of type Object for operator &.'

How could I change this line in order to resolve this errors? Thanks all are gonna answer me.


Solution

  • Change:

    Label6.Text = FormatNumber(CInt(Form3.Label12.Text), "0.00") - O.S
    

    To:

    Label6.Text = CDbl(Form3.Label12.Text).ToString("0.00")
    

    For the Double to Integer error.

    Change:

    hrrspk.Add(Form3.ListBox2.Items(i))
    

    To:

    hrrspk.Add(CInt(Form3.ListBox2.Items(i)))
    

    Change:

    If Me.TextBox1.Text.Split(".")(1).Length < 3 Then
    

    To:

    If Me.TextBox1.Text.Split(".".ToCharArray())(1).Length < 3 Then
    

    For the Object and & one, change:

    Function(x1, x2) x1 & "," & x2
    

    To:

    Function(x1, x2) CStr(x1) & "," & CStr(x2) ' or use x1.ToString() and x2.ToString()