Questions tagged [option-strict]

The Option Strict Statement restricts implicit data type conversions to only widening conversions which disallows late binding, and also disallows implicit typing which results in an Object type.

Option Strict turns on strong type checking in the Visual Basic .NET programming language.

50 questions
1
vote
1 answer

How to set DataGridViewCell.Value with Option Strict On

How to test for DataGridViewCell.Value with Option Strict On? If DataGridViewCell.Value = "some value" then Gives the error: Option Strict On disallows operands of type Object for operator '='. Use the 'Is' operator to test for object…
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
1
vote
1 answer

VB.NET not seeing some classes

One of my classes seems to be invisible to the rest of my project. I wonder if I somehow have to initialize it before I can use its public stuff. The functions and methods of Class1 immediately appear in IntelliSense, but Class2 is treated like a…
Toerndev
  • 715
  • 1
  • 6
  • 21
1
vote
2 answers

how to use Option Strict On and Late Binding

I am trying to get some code to compile after switching Option Strict On. However I am using some Interop with VB6 and passing in a form object ByRef so Form.Caption fails and I can't convert it to type Form because a VB.NET Form doesn't have a…
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
1
vote
1 answer

How do I use Thread.VolatileWrite with reference types with Option Strict On?

Wrapping the argument in CObj or DirectCast shuts the compiler up, but the value is still not written. Option Strict On Imports System.Threading Module Module1 Dim str As String Sub Main() Thread.VolatileWrite(str, "HELLO") '…
Ansis Māliņš
  • 1,684
  • 15
  • 35
1
vote
2 answers

Running a sub on a form with option Strict ON

I'm trying to clean up my coding practices, and came across this I could not solve. With option strict on, how you you find an instance of a form and run a public sub on said instance? For example in an inventory package, i have a shortcut to…
Josh
  • 89
  • 12
1
vote
1 answer

Why doesn't compiler error on build?

I am using VB.NET, at the top is Option Explicit However why does the compiler not raise an error when I do :- obj.ThisFunction(Convert.ToInt32(strMessage)) and the function is :- Function ThisFunction(id as long) Surely, Int32 is int and int64…
1
vote
0 answers

VB->Option strict and LINQ result

I was recently introduced to LINQ and got a sample how to search for error messages after executing a query against a database. The code looks like this: Dim errors As Object = From e In execution.Messages _ Where e.MessageType = 120…
serializer
  • 1,003
  • 2
  • 13
  • 27
1
vote
2 answers

Option Strict On issues where generic type isn't known until runtime

I have the following code that has worked fine for months, but I forgot to create this class with Option Strict On so now I am going back to clean up my code correctly, however I haven't been able to figure out a way around the following issue. I…
XN16
  • 5,679
  • 15
  • 48
  • 72
1
vote
2 answers

Option Strict On and Constant in Visual Basic?

Please forgive me, I haven't used this site very much! I am working in Visual Studio with Visual Basic. I finished programming my project with Option Strict Off, then when I turned Option Strict on, I was alerted that this code was wrong: Const…
1
vote
1 answer

Using LINQ to switch the parent key with the child keys of a two dimensional dictionary

I was not sure on the precise term but what I tried to do using LINQ was "switching" the keys of a dictionary with the keys of its child. This is the collection I have got as input: Key:HeaderID Value: Key:ItemID Value:Object Key:ItemID…
1
vote
1 answer

Linq query has an implicit cast error for DataGridViewRow when option strict is enabled

I have a DataGridView that is bound to a list of objects called "BaseChange". The BaseChange objects are made up of 4 properties... ChangeType ChangeStatus ChangeDescription LastChangeDate The datagridview has columns for all 4 values as well as a…
StingyJack
  • 19,041
  • 10
  • 63
  • 122
0
votes
2 answers

Linking to options drop down

Can you link to a specific value in an options drop down box from another page? In other words, let's say that I'm on page 1 and I want to anchor link to page 2 that has an options drop down box with 3 different values in it. Let's say by default…
arcadian
  • 3
  • 3
0
votes
0 answers

Option strict On Vs. Checklistbox.items Vs. Late Binding

I have a databinded checklistbox: With Me.chkChaineSelected .DataSource = dtChainesTvRadio .DisplayMember = "Chaînes TV/RADIO" End With To get the items checked, i use a loop: Dim strSelectedLinkeChaine Aa String For…
8oris
  • 320
  • 2
  • 12
0
votes
1 answer

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…
0
votes
2 answers

Arraylist access to x and y when a drawing.point is inside

I want to access an arraylist which contains points. The below example works with option strict off. But how can I do this on the correct way with option strict on? Many thanks in advance! Option Strict Off Imports System.Drawing Module Module2 …
Hias
  • 45
  • 6