I'm sure there is an answer to this somewhere but I'm clearly using the wrong terminology in my searches, so I apologise in advance for this inevitably being a duplicate.Take the function CType. Clearly I can cast (or at least try) a given object to a given reference type. The function will not work if trying to cast to a structure, i.e.CType(myObject, Integer)
will generate a compiler error. This I'm sure most often crops up when working with generics:
[Code]...
What is the opposite? I want only reference types so that CType doesn't fail. I can't overload the T As Structure with a plain T because it considers them identical signatures, so surely there's a keyword I'm missing somewhere?
I can remember reading some time ago that there is some way to set the opposite value of a variable depending on the value that it is set to but, I can't remember the syntax of it and I'm not sure what the correct terminology is to describe what I'm looking for. Suppose that I have a boolean variable that can be either true or fule. I need to some way set the variable to the opposite value that is set.
Off of the top of my head it was written something like this (excuse the wrong syntax below, it's what I'm trying to figure out :-) ). Dim myBool as Boolean = False myBool = True : False I know this can be done with if else statements but I'm sure I've seen a more compact way to write it.
I'm wanting to to make a color scheme selection feature for my program, which involves changing the foreground and background colors of many components at once. I have the components divided into groups in which all elements should have the same background and foreground.
vb With BtnLoad And BtnSave And TbxListname And CmbProgDifficulty And TbxRptStandard And TbxQNA And BtnAddProbQ .ForeColor = Color.White .BackColor = Color.IndianRed End With
The problem is that this get's an error message saying that you cannot use "And" (or & or +) in the statement.If I just use one object at a time,
vb With BtnLoad .ForeColor = Color.White .BackColor = Color.IndianRed End With
it works fine. I have so many objects though, I don't really want to copy and paste this with statement 50 times. is there a way to make a with statement take multiple objects?
Why can't I just override the = operator and have it assume that <> is the opposite? Like, if I ask if A <> B, I mean if not (A = B). Straightforward, I would assume.Also, I can't think of ANY circumstance where <> wouldn't be the exact opposite of =.
Well I am trying to autoscroll my ListBox or display everything the opposite way just like a shoutbox. how to do it. I have tried many ways but they either gave me errors or didn't work.
comparing C# code and VB.NET and the results between the seemingly identical code were entirely different.(Why C# is always winning over VB.NET?)The explanation given is that C# will initialize the class fields, then call the base constructor, but VB.NET does the exact opposite. Is there a technical reason for the languages to be different? At first glance, it seems that either approach is equally valid, but I can't fathom why they wouldn't have selected the SAME approach.
EDIT: As 'Jeffrey L Whitledge' has pointed out, VB6 did not have inheritance, so I don't think we can say 'to keep VB.NET and VB6 more closely related'.
Module Module1 Public Structure structure1 Public TRANS() As structure2 End Structure Public Structure structure2 Public X() As Integer End Structure End Module
I'm new to VB 2008 after having spent a long time with VB6, so I apologize if this is a stupid question. But I'd really like to have this straightened out.
Let's say I have a pretty large structure that has lots of properties.
Code:
Now say that I want an internal database with about 10 instances of this structure total, describing, say, 10 different products that a store sells. When these values are loaded from a database, they remain totally static. (However, they can be different each time a program loads)
Now say that I have a class. Each instance of this class is a type of that BaseProduct structure. Meaning, each instance of the class pertains to one of the 10 types of products that the store sells. However, this class has additional properties that pertain specifically to each instance, which are not static.
Code:
Now, the problem here is... If I have 200 different transactions, each one contains an instance of BaseProduct. BaseProduct is HUGE, and is largely redundant (only 10 types possible), so I think it's a little silly to include a whole copy of it with EVERY transaction. However, the Transaction class really needs information regarding the base product it pertains to. Is there a way to, instead of declaring a New BaseProduct in the Transaction class, to simply make one of the properties of the Transaction class a pointer to a BaseProduct variable?
In VB6, I would accomplish this by making a BaseProduct(10) array, and then giving each Transaction an ID number referring to an entry in that array. But in VB 2008, using class structure, this is impossible. I can't define the BaseProduct(10) array outside of a class in a namespace, and if I define it in the actual application's form, then the class loses modularity since it relies on the application that's using it.
I am trying to communicate with an external device and i am trying to send a byte array to the external device via sockets but i am always getting a response the message size is too small so i am not sure what i have done wrong. Between the data type there should be no alignment present and all numbers are represented in little endian format. The char array is not null terminated as mentioned in the protocol specifications.
I have to send data based on a struct that embeds 2 other struct. So here's my vb.net code for the struct used to convert to byte array and the sending part.
Public Structure MESSAGETYPE_OIP_Login Dim Header() As COMMANDHEADER Dim UserName() As PSTRING
I'm having a problem that's driving me crazy; I can't understand how to convert the XML structure into a class structure (that I want to use to hydrate a XML document).
The XML document looks like this:
xml <?xml version="1.0" encoding="utf-8"?> <artists xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns="http://www.spotify.com/ns/music/1">
Public Structure LogicalEdge Dim sTypeEdge As String Dim dTotalLengthOfLines As Double Dim lstLinesInEdge As List(Of Line) End Structure
In my code, I create a new list of this LogicalEdge:
Dim myListOfEdges As List(Of LogicalEdge) = New List(Of LogicalEdge)
After, I create a new LogicalEdgecontainer:
LogicalEdge = New LogicalEdge
I set one of it's properties:
LogicalEdge.sTypeEdge = "endcap"
Now, I add it to the list
myListOfEdges.Add(LogicalEdge)
After looping a few times, i want to set one of the other propterties for the same item in my LogicalEdge, but when i do this:
LogicalEdge.dTotalLengthOfLines = 80.77
To look at the values in the collection, I loop through myListOfEdges collection; and I see that dTotalLengthOfLines doesn't pick up the value i have assigned to it. i thought I might need to identify which item in myListOfEdges to add it to... so i tried this:
Recently I found that I'm not able to instantiate a structure for an array:
Dim mObjectLists() As New objectLayout
Ok, fair but It's an easy way to store a bunch of data in an array instead define a class. And after that I tried to define this:
Dim mObjectLists() As Collection
And add structures to the collection. But it says you should instantiate the reference object first. I searched about creating own Collection based on the base collection class but I think It's wasting time to write a code with class inheritance instead the first sample.
In a recent project I was working I created a structure in my class to solve a problem I was having, as a colleague was looking over my shoulder he looked derisively at the structure and said "move it into a class". I didn't have any argument for not moving it into a class other than I only need it in this class but this kind of falls down because couldn't I make it a nested class?
I need to convert structure from VB6 to VB.Net. This struct is used to pass to a c++ dll. The problem is that the following struct size in VB is 113, but for some reason in VB.Net is 116.
I have an unmanaged C++ dll that I am using in my program. I have successfully used several functions using DllImport. I have run into a problem with one function that takes a structure as input. I originally tried building a structure to pass to the function, but this was unsucessful. So i created a class to define the needed structure. When I pass this, I get no error message, but also no data is passed back to this variable. I have a C++ example of how to use this function, but I don't know how this translates to VB 2005. Here is how they call it in C++ .
Code: Public Structure StrFolder Public isActive As Boolean Public NameFolder As String[code]....
I would like to retrieve and print each variable name within a given structure (not its value). For example:
StrFolder(0).Name should print "isActive" StrFolder(1).Name should print "NameFolder" StrFolder(2).Name should print "URLIDNumber" StrFolder(3).Name should print "DateOfFolder" etc..
I would also like to know each type of an item within a structure. For example:
StrFolder(0).Type should print "Boolean" StrFolder(1).Type should print "String" StrFolder(2).Type should print "Integer" StrFolder(3).Type should print "String" etc..
What is the best way to get a structure from memory, I know the format:
[Code]...
The structure is 53 bytes until the chat text, the message length is determined by one of the structure variables LineLength, so what is the best way to get that and put into into a structure?
I have a structure with types ranging from thread's to control.what im looking for is a easy way to iterate through those item like For eachbut i couldn't get for each to workis there a way to do it
I'm sure I need to do a for each <something> in my something..but I cant figure out what..I kinda want to make a trace program for my structure so I can loop through and split out the name and the value in it..
I have an array structure called Survey and I'm attempting to loop through all the data and get it printed out. I'm trying to follow the example in my text but I must have something different.Here is my basic structure:
Structure Survey Dim ID_Code As Integer Dim Members As Integer
[code]....
I'm not understanding how to fix? The objects and properties to the right of "Family Size: " are getting errors saying "Value of type Integer cannot be converted to System.Drawing.Font.
I have a list of a few thousand names. I actually have last name, first name, phone number, etc and more info. I'm going to make a class to contain the data. so I'll have like a people object with for example a last name field. I'm going to store these in like an array list. Lets say i have 100 items in array list. Maybe last name smith is on index 3 21 and 63. I'd like a data structure where i can easily search for smith and get indexes 3 21 and 63. Brute force is simply loop through complete array checking last name and grabbing index each time i find smith. Ideally id like to have more efficiency. In c++ I'd use a multi map but i don't see that that exists in vb.net. A dictionary wont work because its 1:1.Name of data structure, short description of how to use it and web help reference page would be nice.
I'm writing a test application in order to figure out how to serialize a structure to XML. I can not get the following code to work for me and it's not obvious to me.
The following defines the structures I am attempting to serialize. I think I have the xml decoration correct - but the errors I'm receiving (see below) don't really give me much information.
Imports System.IO Imports System.Xml.Serialization Public Module modTestSerialization
explain what I need to do at the bottom here? I can not figure out what is meant by setting the element of the structure to the value.. Option Strict On
I'm just learning about Structures and so I have created one, but now i want to find out if it contains a line that I placed into itHere's my structure:
Public Structure aLine Dim IsEdge As Boolean Dim myLine As Line