Variable Class Names - Rename My Class Human To Man
Dec 18, 2009
What i'm trying to do:
I've got a library which includes a class:
Class Human
End Class
and another class which refers to the human class
Class ASD
Private somevar as new Human
End Class
Ok now i've got a problem, i wish to rename my class Human, to Man. i've got to change Human to Man 2 times, which is OK but the problem is that in the real case, its not just 2 times, its like 500 times or more.
Well its something like a PHP on Javascript.
the following shows the solution of what i'm trying to do, but its in another language PHP/Javascript:
note: in php $ sign declares a variable, echo writes the variable out
CODE:
Is there anyway to do that with VB?
View 6 Replies
ADVERTISEMENT
Jan 9, 2009
Trying to understand the best way to do this and I'm can't get it figured. Here's basically what I have:
Public Class CardParsingClass
Private iAcctIDStart as integer
Private iAcctIDLength as integer
[code]....
I've only included 2 of the class level fields here but there are actually 30, so that's why I was hoping to be able to send the name of the field to set and the value to set it at in the SetValue function. So in some other routine in the program I'd like to be able to issue the following call:
SetValue("iAcctIDStart", "3")
But then when I get into the SetValue routine, I'm not sure how to proceed. I thought about a case statement that would basically be this:
select Case strFieldToSet
case "iAcctIDStart"
iAcctIDStart = cint(strValue)
[code]....
View 5 Replies
Nov 17, 2009
I'm quite new to Visual Basic - using Visual Studio 2008 and can't seem to find a way to do the following:
I have a few tables in a SQL Server database and have used LINQ to SQL to create classes of those tables.
Here's a cut down example of what I'd like:listbox1 filled with table names - APS, SMPS, WCPC, CFLAPS
Then from the SelectedIndexChanged event, listbox2 should populate column headers of the selected table.
I have no issues getting data from the database, and can access all of these headers through the anonymous type objects created from a LINQ query (eg APS.ID, APS.count etc), but populating a listbox with these variable names rather than the data inside them seems rather elusive.
This is probably a cross platform coding question rather than VB specific, so if you have a solution in C# or whatever I'd be happy if you could let me know.
View 2 Replies
Feb 1, 2011
I am working on a project where my class has to execute VB code provided by the user, to make it simple I am trying to recreate my own eval function, I am using the following code I found on the web to do this task.
Imports Microsoft.VisualBasic
Imports System
Imports System.Text
Imports System.CodeDom.Compiler
Imports System.Reflection
[Code] .....
The problem with code is that it can't access any variables or there values, so I have decided to get the variable names, there values types and there types dynamically and recreate them in the class that is being created dynamically. Any way to get the variable names there types and values in the current class or method, so that I can recreate them, and execute the user passed code, the user knows what variables are in the current class or method and there datatypes but he don't know there values as they may have changed, so he can't initialize them. Is there a way to do this, this code will be called in an asp.net page on page_load event, the code passed by the user is stored in the variable vbCode that is passed as a parameter.
View 2 Replies
May 8, 2012
Create a class named Service. Inside the Service class, declare a class variable named Started. The datatype of this variable is Boolean.Public Class Service Dim started as Boolean End Class Create a class named Server. Inside the Server class, declare a dynamic array that can contain elements of the type Service.(Note: For convenience, both the array and the variable Started can be accessible from a client program that creates an instance of Server and Service respectively)
Create a constructor for the Service class. When the constructor is executed, it will set the value of the class variable Started to True. Create two new classes: WebServer and DatabaseEngine. Both of these classes inherit from the class Service. Inside the Service class, declare a Sub procedure (method) named Terminate. This method should display the following text Service stopping in a message box when executed.This method can be overridden in classes that inherit from Service class.
Inside both the WebServer and DatabaseEngine class, override the method Terminate inherited from their base class Service. Both methods should first call the base class Terminate method. The messages Web server stopping and Database engine stopping should also be displayed in a message box when the Terminate method for the WebServer and DatabaseEngine are called respectively. These messages should only be displayed if the Started variable inherited from their base class is not equal to False.
Inside the Server class, declare a method named Shutdown. This method does not return any value. When executed, it will call the Terminate method for each of the Service instances (if any) in the arrServices
array. You should call the Terminate method within a For Each loop that loops through the elements of the arrServices array.
In the Sub Main method, create an instance of the class Server. Set the size of the arrServices array in
your Server instance to contain 2 elements. Create first a WebServer instance and then a DatabaseEngine
instance into this array. Call the Shutdown method from your Server instance.
View 7 Replies
Jun 7, 2012
I want to created a nested class that can only be visible to and instantiated from the parent class.But I also want to be able to use an instance of the nested class through a public variable of the parent class.I tried making the nested class private, or making the nested class' constructor private, but it won't compile.Is it possible to do this in .NET?
[Code]...
View 3 Replies
Sep 29, 2011
I have procedure (Import) that calls a for a new instance of frmImportData. I also have a class name clsBatch that has a data table property called prpParametersTable.For some reason, I get an error (indicated below with ERROR>>>) when trying to assign prpParameterTable to cv_dtImport2. The error states "Object reference not set to an instance of an object.". Why does this error not happen when I assign dtBP to cv_dtImport1? Both cv_dtImport1 and cv_dtImport2 are equal to Nothing and in my Import procedure dtBP = prpParametersTable.
Public Sub Import(ByVal clsB As clsBatch)
Try
Me.cv_clsB = clsB
[code]....
View 5 Replies
Nov 14, 2009
I have three class files, accounts.vb and transactions.vb in addition to my form.vb. I am unable to retrieve a member variable from on class from inside the other. When the combobox index changes, the program loads the correct account (checking or saving) from two different sequential files. I don't think I have the calcBalance procedure in the correct class file. And that is what I am having trouble with. Accessing it to display it. [Code]
View 1 Replies
Jan 31, 2011
I have the following code:
Option Explicit On
Imports System.DirectoryServices
Imports System.IO
[code].....
View 4 Replies
Dec 16, 2009
If Class X is within the scope of Class Y, is X a subclass of Y?If Class A is a sub Class of B, then is Class B considered a super class of A?if Class C inherits Class D is Class D a superclass or parent of Class C?if Class E extends Class F then we can consider Class E a child of F?if Class G inherits Class H and is within the scope of Class I then who is the parent of Class G? Classes that inherits Class J and classes that are within Class J are all sub classes of Class J?
View 1 Replies
Apr 15, 2010
I have put this code in the global form Inherits System.Windows.Forms.Form. And then in the form that will inherit this from the global Inherits MenuStrip. "MenuStrip" is what the global form is called. But keep getting this error: Error1Base class 'MenuStrip' specified for class 'Lesson2' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types.
View 5 Replies
Jul 22, 2011
I have a class (see below)
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Public Class ClientProfile
#Region "Variables"
[CODE]...
It is in the file ClientProfile I have placed in both App_Code and also App_Code/Models
In my code behind I have the following
[CODE]...
The last word, "ClientProfile" has the scary squiggly red line below it. It is not recognizing my class.Even the Intellisense is not picking up te class. Do I have to register the class file in any way?
View 4 Replies
Mar 29, 2009
When you create a new asp.net page in VS 2008 and choose code behind, it also creates the typical aspx.vb or aspx.cs file to go along with it.
At the top of those files, VS names the 'Partial Class' name the file structure and/or name of the aspx file.
The question: Is there a best practice for this? Can I just use a single class name for all the pages in my application or perhaps a single directory instead of having to give each one a unique name?
View 5 Replies
Jan 11, 2012
I have got a class which contains more then 160 fields. i need the name of fields (not value) in an array. get loop through names for field or get list of field names in a array so that i can loop over it and use it in code. i am using visual studio 2010
View 2 Replies
Sep 5, 2010
1. create a blank VS2010 web project called "MySite" targeted at 4.0
2. create a new class object, calling it "class1.vb" (cause it's so unique!!)
3. change default code to read as such...
Namespace MySite
Public Class Functions
Public Shared Function WhatIsTodaysDate() As String
Return Date.Now.ToLongDateString
[code]....
Why is VS asking me to call the namespace twice if I use the "Imports" directive?I'm sure this has got something to do with VS2010 and the 4.0 framework.
View 2 Replies
Mar 17, 2009
I have the following class that i use to pull data from a API.here is my callDim myProducts As clsMagentoProduct() = clsMagentoProduct.List(apiURL, sessionId,New Object() {filterOn})
View 2 Replies
Mar 6, 2009
Okay, say I have a class named "ChannelList", and it raises an event named "FoundChannel"
But what I'M wanting to do is create multiple classes of different names that use that class, but I want to have all of the "FoundChannel" events be handled under one single sub routine?
View 15 Replies
Dec 9, 2011
I have a class with many properties to which I need to assign values.I have another class with a sorted list of data from which the assignments are to be made. Is there a way to get the names properties from a class and refer to those properties?I looked through System.Reflection.Assembly but could not find a way to do it.
Class DataMngr
Sub ManageData()
Dim sl As SortedList(Of String, Double)
sl = GetData()
[code]....
View 4 Replies
Sep 26, 2011
i had a class called Tag with a structure like:
public class Tag
private _members
public properties
public shared database_methods
end class
this class was tailored for mysql database. i'm currently adding access 2007 support so i split tag into tag and tagdata with structures like:
[Code]...
View 2 Replies
Jun 21, 2010
I have valued pairs, attributes names and values in one hand, and I have an object with attributes. I need to set the values of those attributes. I need something like [code]
View 1 Replies
Sep 11, 2009
Dim a as Type=GetType(className) would gimme the type. But I have only the name of the class as string. I want something like GetType("class1") which would return the type.
View 2 Replies
Feb 24, 2009
I want to create a class (I think) that has properties that correspond to column names in a database table, such that they come up in Intellisense when I type the dot after the class name. Is this possible to do?
View 5 Replies
May 15, 2009
I can't make difference between public class and private class and friend and protected friend class.
View 1 Replies
Jan 21, 2010
I can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
View 4 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
Mar 9, 2010
How does a class get the name of the variable that instantiated it?[code]...
View 9 Replies
Aug 15, 2011
I have 2 subs in my class. I need to use the values in the variables in the first sub in my second sub. like this.
Public sub test1()
Dim one as double = 12
Dim two as double = 10
[CODE]...........
But I do not remember how to do it.
View 1 Replies
Mar 12, 2012
I have form1.vb and class1.vb
Code removed
What I am trying to do is very simple now. Pointx and Pointy in Class1 is underlined. How do I get that variable value (which the form1 finds) into class1.
View 14 Replies
Apr 13, 2009
I'm getting an error in .net when trying to declare a Public class on my code behind page.
Partial Class _Default Inherits System.Web.UI.Page
Public someVariable as integer
Public someClass as className
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load [...]
The error I'm getting is BC30508: 'someClass' cannot expose type 'className' in namespace '<Default>' through class '_Default'.The goal here is accessing the class properties in script blocks on the aspx page like this <%=someClass.classProperty%>
I'm not sure if I'm trying the right methods (I've tried several ways of declaring the public class) or if it can even be done..
View 3 Replies
Mar 4, 2012
I want to do this: [URL] but in VB. I believe that is for C# I have 2 classes.
[Code]....
I know I've been asking too many questions lately and I do apologise for that. I am trying to learn the basics
View 12 Replies