Define "what My Variable Will Be"?
Jan 27, 2011
So I have this:
Dim aBoolean As Boolean = True
Will it make any difference to just do this?
Dim aBoolean = True
In other languages, I believe it was a good practice to also define the type of variable it would be, for performance or something. I am not entirely sure with VB.NET.
View 4 Replies
ADVERTISEMENT
Feb 8, 2011
i wonder if it's possible to define a variable/property of more than one type. Let's say i want a property TextWebControl that is a WebControl and also implements Web.UI.ITextControl(f.e. like a TextBox or Label). But i don't want to enforce that it is a TextBox or Label, but only one that inherits from WebControl and also implements ITextControl so that it also would work with controls added in future releases of .Net-Framework.
.Net-Framework 4.0
Edit: I have retagged the question and added VB.Net because it's my default language. Normally it's no problem for me to understand C# also, but i must admit that it's difficult to translate generic stuff to VB.Net without experiences and it's also better documentated in C# than in VB. So i would appreciate(and aceept) a working example of a VB.net generic type of ITextControl/WebControl.From Marc's answer i understand that i need a generic class. But how do i instantiate it in SomeClass? This won't compile:
Class SomeClass
Public Property info As InfoControl(Of WebControl, ITextControl)
End Class
Public Class InfoControl(Of T As {WebControl, ITextControl})
End Class
View 3 Replies
May 14, 2009
I have no idea as to how I can define a variable as "GLOBAL" in VB Express 2008. I used VB V 3.0 and if I remember correctly the statement "Global varName as Integer" allowed me to use the variable across different forms. I've tried the statement "Public varName as Integer = 0" on Form1 but Form2 tells me the variable is not declared.
The statement (in Form1) "Form2.Label1.Text = CStr(varName)" displays the value on Form2 in Label1 but I cannot then use the value again in Form2, e.g. "Label2.Text = Label1.Text". How I can transfer a variable value from one form to another and manipulate that variable in the second form?
View 4 Replies
May 18, 2010
[Code]...
I have remplace the keyarr definition by my SQL query: With the code above, I can print both keyarr in a console. What should I change in the _sqlReader.Read() function in order to get keyarr definition like the first code. I would like that keyarr could be
interpreted by the rest of my code.
View 7 Replies
Sep 18, 2011
Im trying to grasp session varibles, i understand what they are etc but i would like to know how to define a type for each session variable.Iv written it like this
Session("Title") = txtTitleContent.Text
How can i tell it what type of value is going to be in it, because at the moment im only playing about with strings, but what if i have an integer and want to pass it back to the back end to save it will throw an error saying "conversion from string to integer is not valid" should i use Cint to deal with this?
View 1 Replies
May 6, 2010
I want to define a variable that is a collection of interfaces - it could be any interface that is defined for use in my app.
e.g. Dim x as New List(Of InterfaceBase)
Is there a base type for all interfaces that I can use for InterfaceBase?
View 1 Replies
May 3, 2012
Is it possible to define a datagrid and chart name as variable? I'm planning to put the result into the predefined datagridview inside FOR and NEXT loop. I've been trying but getting different sorts of errors..
For i = 1 to 10
[Code]...
View 2 Replies
Mar 9, 2009
public partial class _Default : System.Web.UI.Page
{
private bool isEditMode = false;
protected void Button1_Click(object sender, EventArgs e)
[code]....
What is the VB code equivalent for the above C# code. Mainly how to define Property (IsInEditMode) and Global variable (isEditMode) in ASP.NET?
View 5 Replies
Jun 2, 2011
The company I work for has an application where various users can log in and add their own "clients". Currently, via sql mail a confirmation email goes out to the client who has been added but the "From" value is generic i.e.Admin@CompanyA.com. What we need is a way for an email message to be sent to the new client but have the "From" email be that of the user adding the new client. When a user registers to use our system they supply basic info including their email, so when they log in and then add a client we would like to have an email sent to that client but have the "From" address be that of the logged in user instead of the generic one from our company. The email would have to be sent from our company's server but we want the sendee to be able to directly "reply" to the sender's email.
View 2 Replies
Apr 20, 2011
Why define a variable "As Long"? And how does it differ from "As Variant"?
View 1 Replies
Mar 25, 2010
I am getting the error:"Range variable 'sender' hides a variable in an enclosing block or a range variable previously defined in the query expression."for this
Imports System.Data.SqlClient
Imports System.Linq
Public Class Form1
[code]....
I can select any other item from the table without the error. "sender" has the same properties as "receiver" in the SQL table.
View 2 Replies
Jun 3, 2009
This Image shows type-safe method of defining the Actionlinks ,how to define it in VB.NET
View 1 Replies
Jun 3, 2009
This image shows how to define the RouteTable in C#, using the Route Class. How to define it in VB.NET?
View 1 Replies
Sep 2, 2011
I want to define several constants of pens like SystemPens. How do I do that?
View 6 Replies
May 27, 2009
I am using System.Reflection to load a type that I cannot otherwise load during design time. I need to pull all controls within a collection of this type, however, i the OfType command doesn't seem to like the reflection Syntax. here is "close to" what I got.
Dim ControlType As Type = System.Reflection.Assembly.GetAssembly( _
GetType(MyAssembly.MyControl)) _
.GetType("MyAssembly.MyUnexposedControl")
Dim Matches as List(Of Control) = MyBaseControl.Controls.OfType(Of ControlType)
So that code is bogus, it doesn't work, but you get the idea of what I am trying to do. So is there a way to use reflection and get all of the controls that are of that type?
View 4 Replies
May 4, 2011
Is there any way to define a Generic in VB.NET which will accept only Singles or Doubles? I tried the following things, based on what I've found online, but none compile:
Dim target As Nullable(Of {Single, Double})
Dim target As Nullable(Of T As {Single, Double})
Dim target As Nullable(Of T {Single, Double})
Dim target As Nullable(Of Single, Double)
Dim target As Nullable(Of T As Single, Double)
I want to specify that target can either be a Single? or a Double? only.
View 1 Replies
Feb 16, 2011
I have a class called "heater". One of the properties is "designstatus", a string. I want to limit the property to one of three choices; "current", "obsolete", "notdesigned".
View 2 Replies
Aug 1, 2011
I want to know when I need to define a property in programming in general?,in every language
View 4 Replies
Mar 1, 2010
I have a list(of object) lets say ob1,ob2,ob3 that are classes I want to write a linq-querry that exstract from this list only one particolur object that is different time to time how can I write the linq querry?
dim List as new list(of Object)
list.add(ob1)
list.add(ob2)
list.add(ob3)
dim Result=(from P as ob3.gettype in list select p).tolist
but it does not work?
View 4 Replies
Feb 28, 2010
How to define array in vb2005? (Actually, I am making a game, whcih have to find out a pair of same pictures. I want to randomize 8 pictures, but it will randomize some pictures which is the same. Therefore, I need to use array.
View 3 Replies
Jun 23, 2011
bit is use for boolean where it is use to define result either 1 or 0 / true or false.
how to set it, if i want to define result either in or out/ yes or no/ big or small..
can i change it??what is the code to set it..
View 13 Replies
Oct 15, 2009
I need to do something like this Class A End Class Class B Inherit A End Class A=B If i try i get an exception! that i can not cast B in A. How can I overcome this problem? I need to define 2 classes B identical to A but as a distinct class What I need is to be able to cast one class to the other like A=B or B=A I tried with directcast but i got the exception what can I do
View 1 Replies
Mar 16, 2011
I know to define integer type sqlparameter but I do not know the decimal type sqlparameter for the precession.
I am giving a sample example.
//Code
Dim sqlparameters(2) as sqlparameter
sqlparameters(0)=new sqlparameter ("@RMID", SqlDbtype.integer,7)
but in case of decimal I am giving like this
sqlparameters(1)=new sqlparameter ("@RMID", SqlDbtype.decimal,7,2)
which is wrong
View 1 Replies
May 26, 2010
I need to define Virtual IP programmatically (Perl or VB or CMD or java).I need it for temporary use, I can't use any actual IP address and I don't care if it will be accessible only from local machine.
View 1 Replies
Sep 21, 2009
I'm using the Hashtable class for the first time, and have a question about it:Is it possible to define a type for all it's elements? So that when you for example only put strings in it, you can retrieve them without having to cast them from objects.
View 7 Replies
Dec 16, 2009
What is that 0x thingy notation ALso what is &H notation Sometimes I see 0& when calling API what does that mean?What's the difference between 0& and 0
View 3 Replies
Aug 23, 2011
I receive the error -
[Code]...
View 10 Replies
Nov 12, 2010
I am making an interface that has a number of events defined in it. When I implement the interface in a class the events will show up. I want to force a class that implements my interface to also have to make the event handlers too. I don't care where the class raises the event, but I want them to have to define what happens once the event is raised. Is this possible and if so, how do I do it?
View 1 Replies
Jan 18, 2011
In java I use the Desktop application as under;Create JFrame Add JdesktopPane and in the Jframe constructor intilize the all the child forms and then in the events i use child form.visible method.But in the VB where is best technoque to use child forms to initilize?i also need a piece of code for the application to learn how effectively i use the VB to develop MDI application.
View 1 Replies
Apr 19, 2009
I have the following situation, can anybody help me in that?Following is a "pseudo" code of what I want to do in VB using VB.NET 2005:
[Code]...
View 2 Replies