A common programming technique I use in VB is making a collection of
structures. But if Option Strict is on (which I would prefer), the .Add
that adds the structure to the collection is flagged with a compiler
error (invalid type conversion). Is there a way to use a collection of
structures WITH the Option Strict On? 4 1350
Can you change your structures to classes? I use collections of classes all
the time with no problems.
Mike Ober.
<za***@construc tion-imaging.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
strange ,,,
changing structures to classes seems a bit odd to me as the TS might have a
good reasson to choose for a structure
when you do not need instancing , and ther are no actuall methods ( so the
struct only holds values ) i prefer to use structures also structures are
faster as classes in this case ( stack vs heap ) and more lightweight so
they seem perfect for this task.
I use structures in a hashtable , and i program always with option explicit
and option strict on
strange thingy i do not encounter this problem with a collection
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows. Forms.Form
Private Structure test
Friend a As String
Friend b As String
End Structure
Private sCol As Collection
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
sCol = New Collection
For i As Integer = 1 To 100
Dim strTest As New test
With strTest
..a = i.ToString
..b = "just a test"
End With
sCol.Add(sCol, i.ToString)
Next i
MsgBox("finishe d")
End Sub
End Class
regards
Michel Posseth [MCP]
<za***@construc tion-imaging.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. . A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
On Sat, 19 Nov 2005 10:07:07 +0100, "m.posseth"
<mi*****@nohaus ystems.nl> wrote: strange ,,,
changing structures to classes seems a bit odd to me as the TS might have a good reasson to choose for a structure
when you do not need instancing , and ther are no actuall methods ( so the struct only holds values ) i prefer to use structures also structures are faster as classes in this case ( stack vs heap ) and more lightweight so they seem perfect for this task.
I use structures in a hashtable , and i program always with option explicit and option strict on
strange thingy i do not encounter this problem with a collection
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows. Forms.Form
Private Structure test
Friend a As String
Friend b As String
End Structure
Private sCol As Collection
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click
sCol = New Collection
For i As Integer = 1 To 100
Dim strTest As New test
With strTest
.a = i.ToString
.b = "just a test"
End With
sCol.Add(sCo l, i.ToString)
Key difference in my usage and yours. The above statement in my usage
would have been:
sCol.Add(strTes t)
And yes that would work just fine. It when I try to do this:
For Each strText in sCol
do something
Next
THIS is where I get the error. Next i
MsgBox("finish ed")
End Sub
End Class
regards
Michel Posseth [MCP] <za***@constru ction-imaging.com> wrote in message news:11******* *************** @f14g2000cwb.go oglegroups.com. ..A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
Hello well this works just fine with me
sCol = New Collection
For i As Integer = 1 To 100
Dim strTest As New test
With strTest
..a = i.ToString
..b = "just a test"
End With
sCol.Add(strTes t)
Next i
For Each Strval As test In sCol
Debug.WriteLine (Strval.a)
Debug.WriteLine (Strval.b)
Next
when i typed this sCol.Add(sCol , i.ToString)
my head was probably not so clear :-) as it ofcourse should have beensCol.Add(strT est, i.ToString)
but anyway i have tested above code and it foes work on my computer ( with
option strict on )
regards
Michel Posseth [MCP]
"Joe Cool" <jo*****@home.n et> wrote in message
news:1v******** *************** *********@4ax.c om... On Sat, 19 Nov 2005 10:07:07 +0100, "m.posseth" <mi*****@nohaus ystems.nl> wrote:
strange ,,,
changing structures to classes seems a bit odd to me as the TS might have a good reasson to choose for a structure
when you do not need instancing , and ther are no actuall methods ( so the struct only holds values ) i prefer to use structures also structures are faster as classes in this case ( stack vs heap ) and more lightweight so they seem perfect for this task.
I use structures in a hashtable , and i program always with option explicit and option strict on
strange thingy i do not encounter this problem with a collection
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows. Forms.Form
Private Structure test
Friend a As String
Friend b As String
End Structure
Private sCol As Collection
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventA rgs) Handles Button1.Click
sCol = New Collection
For i As Integer = 1 To 100
Dim strTest As New test
With strTest
.a = i.ToString
.b = "just a test"
End With
sCol.Add(sCol , i.ToString)
Key difference in my usage and yours. The above statement in my usage would have been:
sCol.Add(strTes t)
And yes that would work just fine. It when I try to do this:
For Each strText in sCol do something Next
THIS is where I get the error.
Next i
MsgBox("finis hed")
End Sub
End Class
regards
Michel Posseth [MCP] <za***@constr uction-imaging.com> wrote in message news:11****** *************** *@f14g2000cwb.g ooglegroups.com ...A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged with a compiler error (invalid type conversion). Is there a way to use a collection of structures WITH the Option Strict On?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Microsoft News |
last post by:
I have a project that was created all with Option Strict OFF. Works great,
not a problem with it. But if I turn Option Strict ON then I get a LOT of
errors.
My question, should I even care about Option Strict?
What advantages do I get with Option Strict On?
Does better type statement make my code run faster?
If anyone knows THE ANSWERS! please fill me in. I have ideas and belief but
I would once and for all like to know what the...
|
by: Rich |
last post by:
Hello,
If I leave Option Strict Off I can use the following
syntax to read data from a Lotus Notes application (a
NotesViewEntry object represents a row of data from a
Lotus Notes View - like a record in a sql Server view)
....
Dim entry As Domino.NotesViewEntry
Dim obj As Object
str1 = entry.ColumnValues(0)
|
by: Howard Kaikow |
last post by:
I am trying to retrive some WMI properties using Option Strict On.
This requires the use of InvokeMember.
I know that there are alternative ways to get the values, but I want to
learn how to use WMI with InvokeMember and Option Strict On.
I'm getting an "Unknown Name" error in the following statement in the code
below.
objProp = typeObjProps.InvokeMember("Item", _
|
by: David |
last post by:
Hi all,
I have the following problem: my program works fine, but when I add option
strict at the top of the form, the following sub fails with an error that option
strict does not allow late binding. What should I do?
Public Sub MyMnuHandler(ByVal sender As Object, ByVal e As System.EventArgs)
If sender.checked = True Then sender.checked = False Else sender.checked = True
|
by: YYZ |
last post by:
After reading many messages in this group, it seems that the preferred
setting for this is ON. Okay, I did that in my project (first with
..Net -- long time VB6 developer) and now a bunch of problems have
cropped up. Most are easy to solve with using an explicit type cast
cType(whatever, whatever type), but some aren't.
Situation 1: I've got code that tries to get the itemkey of the
selected item in a combobox....
| |
by: Rich |
last post by:
This code worked before I added option strict. But I should do it correctly.
option ...
option Strict On
Public Structure Itm
Dim mailSvr As String
...
Public Sub New(ByVal a1 As String...)
mailSvr = a1
|
by: guy |
last post by:
when i first started using .net (beta 1) i came across option strict and
thought hey this could be really good, and since then have always turned it
on, most people here seem to agree that this is a good thing.
i have now been asked to debug a vb2005 web app for 3 weeks and there is no
mention of option strict in it, (there are also no classes defined, just a
couple of structures) everything is define as 'as object', data coming back...
|
by: Rory Becker |
last post by:
A wise man once said: "Never put off until runtime what you can fix at compile
time."
Actually I think he said it about 10 minutes before I started this post.
I am a firm believer, like the man in question, in "Option Strict On" by
default.
Actually I don't believe I have code where this is not the case.
|
by: cday119 |
last post by:
Hi everyone,
I have a Collection that is set up like this:
Lines(
Line1(
Reduction1(
FontName
)
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |