0

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.

  • Have a look at https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse?view=netframework-4.8 and https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse?view=netframework-4.8 and see if you can work it out from there. – Andrew Mortimer Nov 09 '20 at 17:31

1 Answers1

0

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()
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
  • 1
    He's just comment "O S" meaning "option strict". It isn't actually part of the code I don't think. – Andrew Mortimer Nov 09 '20 at 17:31
  • @AndrewMortimer Haha! You just might be right... =) – Idle_Mind Nov 09 '20 at 17:32
  • Yes, it's how @AndrewMortimer writes. Sorry for writing wrong, now I edited the post. – telemaco10399 Nov 09 '20 at 18:11
  • I'm correcting the line I'm able to. Could you help me to correct the error about conversion from String to Char and from Double to Integer? – telemaco10399 Nov 09 '20 at 18:35
  • This is the line with the string to char error: 'If Me.TextBox1.Text.Split(".")(1).Length < 3 Then' – telemaco10399 Nov 09 '20 at 19:27
  • That line didn't even make it into your original post, but I'll put a solution in for that one. – Idle_Mind Nov 09 '20 at 19:42
  • Thanks for the line I missed. I'm correcting my code step by step. Btw, at the moment I still haven't found any final solution for late binding issue. What I did is to reach the compiler settings (where I enabled Option Strict) and I set Late Binding alerts from error to warning, in order to have the notification of the problem and at the same time debugging my application. I tried to run the part where the Excel Interop is programmed and seems to run, even with Option Strict turned on. Maybe I'll change my code when I'll find a final solution... – telemaco10399 Nov 09 '20 at 20:32
  • You probably have `hrrnativexcel` declared as `Object`? If that is the main excel reference, change it to `Excel.Application` instead of `Object`. For variables referring to Sheets, use `Excel.WorkSheet`, for Workbooks use `Excel.Workbook`. – Idle_Mind Nov 09 '20 at 20:43
  • That's the strange thing, because I've found online the same you're saying me, but hrrnativexcel has always been declared as Excel.Application. Nevertheless I'm having back this error, so I changed Late Binding option in order to solve temporarily. – telemaco10399 Nov 10 '20 at 08:16
  • @telemaco10399 It's possible you'll have some things that require late binding. If so, the best way to do it is to separate it out into a separate routine that you can put in a file that doesn't have `Option Strict On`. – Craig Nov 10 '20 at 21:10