Change The Type Of Variable?
Mar 6, 2010
In some part of my code i need to redefine the type of variable that was defined with a different type at the beginning
dim T as new MyClass
...
redefine T as ( MyClass2)
i do not want to do something like
dim T
t= new MyClass
.....
t= new MyClass 2
View 13 Replies
ADVERTISEMENT
Apr 14, 2010
I have this function:
Public Sub DoStuff(ByVal type as System.Type, ByVal value as Object)
End Sub
The 'value' argument is always an array of the same type as 'type'. How can I loop through the values of the array?
I'd like to be able to do something like this:
DoStuff(GetType(Integer), New Integer(){1,2,3})
Public Sub DoStuff(ByVal type as System.Type, ByVal value as Object)
//Strongly types arr as Integer()
[Code].....
View 3 Replies
Oct 10, 2009
I'm aware that questions like this have been asked before and I doubt it's possible, but I just wanted to make 100% sure that it isn't.In VB.net or C# (either language, it doesn't matter), I want to cast a variable to a type represented by another Type variable. Here's an example of the kind of code that would be needed in C#:
Object castMe = new Foo();
Type castTo = typeof(Foo);
Foo beenCast = (castTo.GetRepresentedType())castMe;
[code].....
View 3 Replies
May 18, 2012
Public Class Form1
Dim x, c, number(0 To 19) As Integer
Dim s As Integer
[CODE]...
The variables in the brackets [example] do not actually have brackets in them in the original code. These are where the issues are. For both variables, it says, "The type for variable [variable] will not be inferred because it is bound to a field in an enclosing scope. Either change the name of [variable], or use the fully qualified name (for example, 'Me.[variable]' or 'MyBase.[variable]')." Now, I'm not entirely sure if this is a stupid question or not, as I'm used to VB '98 because that's what we use in my programming class at High School. let me know why this won't work.
-Note: The intention of this program is to continually loop the generation of numbers for this list until I tell it to stop. Button1 ends the program, Button2 generates the list one time only, Button3 is supposed to loop the generation of the list, and Button4 is supposed to end the loop, but not the program.
View 9 Replies
Aug 24, 2009
I am looking for a good resource on variable naming conventions to illustrate variable type and where variables are declared. So I will have public variables, Private variables, private or local variables. I also may want to declare variables with the same name in different class code (i.e. in the code behind different forms). I am assuming good coding would dicatate a prefix for declaration location.
View 4 Replies
Sep 17, 2011
I have the following code that I am using to parse out a test file. I am getting variable conversion error in Sub Main() when I assign file = Read(). The return value of Read() is a TextFieldParser type. How do I assign the proper variable type to "file" so I can write the output to a text file?
Function Read()
Using MyReader As New FileIO.TextFieldParser("C:UsersColinDesktopParse_Me.txt")
Dim currentRow As String
[Code].....
View 3 Replies
Dec 22, 2009
E.g. how do I get VB.Net to statically type a local variable to be the static type of the expression on the right had side of the assignment?
View 1 Replies
Oct 22, 2009
I want to use explicit conversion (CType function in VB.NET) to convert the variable d from double type to integer type and store the result as 132.
Imports System.Console
Module Module1
Sub Main()
[CODE]...
This is my code. But Visual Basic tells me an error: Error1Type 'i' is not defined.C:\Users\mihaispr\Desktop\Conversie explicita\Conversie explicita\Module1.vb1922Conversie explicita
View 4 Replies
Feb 15, 2010
Writing an asp.net mvc app and i have something like this...
Public Class AA
'... has some variables...
End Class
Public Class BB
[code]....
So, now in my program, i just want to copy object of type AA to an empty variable of type BB?it makes sense to do this, as i expect all the fields in AA type object to be copied to the newly created BB type object, and the ExtraVariable in the BB type object i would (will) just assign a value to it later (after the copy) on my own time!!I know copying BB type to AA type would not be appropriate as there would be lost data!But im trying to copy AA to BB, I've used both DirectCast and CType to do this, and i keep getting "unable to cast" error!
Note: I'm using vb.net (but can read c#, no problems)
View 5 Replies
Dec 2, 2009
What's the C# equivalent of
<% dim name %>
so you can use it for web forms in PayPal API integration?
View 3 Replies
Jun 21, 2011
I recently downloaded VB 2010 Express so i am quite new to the language, but i have worked with dark basic, which seems to b very similar.Anyway, my problem is that i cannot seem to correctly set out my array of a custom type/class. i am trying to create two arrays, one of available entities and another of selected entities of which the user selects the entities to be dealt with in irrelevant ways. i have creates a button (called test) which adds some entities to the available list and all the entities come back the same value but they shouldnt be as you'll c in the code. i have run the step into command a found that "available.item(#).Name = " will change all of the entity's names.As of current i am working with lists as the array kept asking for a 'new' statement but i couldnt figure out where to put it.[code]
View 7 Replies
Feb 9, 2011
The code below works for the class that I hard coded "XCCustomers" in my RetrieveIDandName method where I use CType. However, I would like to be able to pass in various classes and property names to get the integer and string LIST returned. For example, in my code below, I would like to also pass in "XCEmployees" to my RetrieveIDandName method. I feel so close... I was hoping someone knew how to use CType where I can pass in the class name as a string variable.
Note, all the other examples I have seen and tried fail because we are using Option Strict On which disallows late binding. That is why I need to use CType.I also studied the "Activator.CreateInstance" code examples to try to get the class reference instance by string name but I was unable to get CType to work with that.When I use obj.GetType.Name or obj.GetType.FullName in place of the "XCCustomers" in CType(obj, XCCustomers)(i)I get the error "Type 'obj.GetType.Name' is not defined" or "Type 'obj.GetType.FullName' is not defined"
'+++++++++++++++++++++++++++++++
Imports DataLaasXC.Business
Imports DataLaasXC.Utilities
[code]....
View 2 Replies
Jun 22, 2009
i have a property (items) that i want to use for either a checkedlistbox or a standard listbox depending on the value of another property.
heres the code i wrote that doesn't work:
[Code]...
View 5 Replies
Sep 17, 2009
I have some code like:
Lookup(Of String)("Testing")
Lookup(Of Integer)("Testing")
And both of those Lookups work great. What I'm trying to is call the appropriate LookUp based on the type of another variable. Something that would look like...
Lookup(Of GetType(MyStringVariable))("Testing")
I've tried to Google this but I'm having a hard time coming up with an appropriate search.
View 4 Replies
Mar 17, 2009
What's the main problem if I don't declare the type of a variable? Like, Dim var1 versus Dim var1 as Integer.
View 6 Replies
Nov 22, 2006
I want to Assign the Value to Multiple Variable of same type in .net and that to in one line of Code.
View 6 Replies
Sep 6, 2010
I have a BaseClass, a DerivedClass1 and a DerivedClass2 from a third party library. DerivedClass1 and DerivedClass2 both inherit from BaseClass.There's a ContainerClass, from the same library, with a member variable ActiveItem, which can be of DerivedClass1 or DerivedClass2, so it is declared as BaseClass.I want to know if ActiveItem is of DerivedClass1, as it can change in runtime without notice.If I do
Dim isDerivedClass1 as boolean = TypeOf(oject.ActiveItem) Is DerivedClass1
then I get a compile time error, telling me that ActiveItem can never be of DerivedClass1 type.I have tried several combinations of GetType and TypeOf but it doesn't seem possible to check this. I have also tried to declare an auxiliary DerivedClass1 variable and comparing their types, but haven't got any luck either.
Edit:The following code doesn't compile in vs2005 SP1.
Public Class Base
Public x As Integer
End Class
Public Class Derived1
[code]....
View 3 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
Jun 12, 2009
So, let's say I have this code (VB.Net)[code]...
What I don't like is:
- relies upon reflection
- loosely typed (no compile time checking)
- I'd rather store the binding information somewhere other than ID, but don't know where else it could go within the aspx definition. Moving the binding declaration to the code behind would be better in some ways, but worse in others.
View 3 Replies
Jun 24, 2010
if I create a variable like
dim DT as new Datetime
automatically the date is set to 01/01/0001
is there a better way to check that no value has been assigned to the variable a part to compare the datatevalue?
View 1 Replies
May 26, 2010
i want to display a value of a variable, type into a textbox.
for example
num=1234
varx=763
i=23
[Code].....
View 14 Replies
May 15, 2010
Is it possible to declare a variable and to choose it's appropriate type during runtime?
it should be something like this (of course, the last line does not work):
'Determine what type of variable is needed later
Dim myVariableType As System.Type = System.Type.GetType("System.String", True, True)
'Create variable with needed type
Dim myVariable As myVariableType ' Should be a string variable in this case
View 5 Replies
Dec 3, 2009
My app has a group of forms that do a specific work in different ways. I want to create a new variable of a form when I want with its name. So, I want a Function in this form :
Public Function GetNew (byref f as form ) as form
That give a form name and return a variable of that type. In other words, it must work as "dim f1 as new formx".
View 4 Replies
Feb 1, 2010
[code].....
View 4 Replies
Jan 6, 2012
I try to understand the VBA scope type, it's impossible to make this such of thing in VBA, but it's possible in other language (java,scala,etc):
[Code]...
Can you give me some information about this type of limited scoping ? It's dynamical or lexical, i don't really understand the difference
View 2 Replies
Apr 2, 2012
Can you use a variable to symbolize the type of style? For example, Dim FS as new font("Times New Roman", FSize,FontStyle.FS)
View 8 Replies
Aug 28, 2009
Dim mYVariable = From C In dtXMLConverter Select C I am using the above mentioned syntax for getting the rows in the variable named "mYVariable" after issuing the from clause when I am moving my mouse cursor on the variable name, it is showing "Dim mYVariable As Object" instead of showing DataRow or something like that. I can't understand how to solve this problem.
where dtXMLConverter = DataTable
View 2 Replies
Jun 19, 2012
I'm trying to convert some VB.net code into C# and having issues trying to convert this one line. VB.NET Dim myreg As Microsoft.Win32.Registry I know it's a static so I can't create an instance but when I tried a VB.NET converter to C# the website gives me this: Microsoft.Win32.Registry myreg = null; And gives me an error message: 'Microsoft.Win32.Registry' is a 'type' but is used like a 'variable' In the last part of the Function in VB.NET, myreg is used:
[Code]...
View 2 Replies
Jul 4, 2010
[Code]...
I prefer to solve this problem at application rather than db level. NOTE: DueDate in database is of type datetime. I'm coding in C# interacting with Sql-Server. I hope my question is clear enough.
View 4 Replies
Jul 5, 2009
in vb I can do that
sub SetFocusControl(byref ctl as object)
ctl.Focus
end sub
in c# the compiler complaint that object doesn't have a Focus method
void SetFocusControl(ref object ctl)
{
ctl.Focus();
}
how can I do the same in c#?
View 3 Replies