VS 2008 Use The Value Of One Variable To Call Another Variable Of The Same Name?

Feb 7, 2011

I am trying to use the value of one variable to call another variable of the same name.I have 2 variable one called VAR1 and VAR2.

The variable VAR1 has a value of "VAR2"
The variable VAR2 has a value of "HELP"

I want to be able to get the value VAR2 from the variable VAR1 I have defined the value of VAR2 early in the code and now I want to call that value by using the value of VAR1.The reason I am doing it this way as I have a list of 50 variables that are pulled from one system. Each of these variables have the same name as the columns of a spreadsheet. The total number of Variable stay the same but the total column headers may vary each time. I need to loop through each of the column headers match them with the variable names and add the data to the spreadsheet.

VAR1 = "VAR2"
VAR2 = "HELP"
i =1

[code]....

This is the tricky bit...if the value of the cell(1,i) = "VAR2" How do I get it to display the value of the variable of the same name In this case how will I get it to display "HELP" when I only have from the VAR1 value "VAR2" I know my code will bring back the value as a string but I want it to bring back that string as a variable and display the value of that variable?

View 9 Replies


ADVERTISEMENT

VS 2008 Error: Range Variable 'sender' Hides A Variable In An Enclosing Block Or A Range Variable Previously Defined In The Query Expression

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

VS 2008 Call .exe From VBA Using A Variable

Apr 7, 2010

I have created a project using VB.Net(VS2008) and created the exe file. I have another project in VBA (Excel 2003). The project basically IC-Testing based. So according to the device type the Excel workbook name varies. For example I have AAAA.xls, BBBB.xls, CCCC.xls. When I open AAAA.xls, I want to call the .exe (which is developed in VB.Net) with the variable "AAAA". i.e when the exe program runs, it knows which Excel is opened or from which Excel the .exe is called. now I am using Shell retval=Shell("d:Monitor.exe",1). Using this the exe is called and running fine. But the Monitor.exe doesn't know which Excel called it, whether it is AAAA.xls, BBBB.xls or CCCC.xls.

View 1 Replies

[2008] Call Method Through Variable?

Mar 12, 2009

I using VB.NET (VS 2008). I want to know if I can call a sub whereby the name of sub is in a varialbe.

For example :

Private Sub Hello()
Msgbox "Hello"
End Sub

[code]....

I know it does not work that way but how can I call a function or sub using a variable and not directly.

View 10 Replies

Call A Variable With A Variable?

Aug 27, 2010

I'm attempting to set a variable from a variable i've searched high and low and looked in many books but still to no avail. I guess i'm using the wrong keyword.I have many public variables like this:

View 4 Replies

Variable Error "Variable 'reader' Hides A Variable In An Enclosing Block"

Aug 23, 2011

I receive the error -

[Code]...

View 10 Replies

Call A Class From A Variable?

Jul 17, 2009

How can I call a class from a variable ?

Something like :

Dim strClassName As string = "clsAction"
Dim newclass = strClassName

I know that this code doesn't work, but how can I do it, if possible.

View 4 Replies

Call A Subroutine By Variable Name (In .Net)?

Jun 21, 2010

what I need to do is to call/run/execute a subroutine using a varaible name from a subroutine.

Public Sub Main(ByVal subName as String)
Call subName ' subName may be contain the value AAA or BBB
End Sub

[code]....

View 5 Replies

Call Member Through Variable?

Nov 6, 2010

I have a class with something like [code]...

By doing this, i want the label to display value of cube.m10

I've tried other things like quotation marks or brackets but doesn't seem to work.

Is it possible to do without being too complicated?

View 3 Replies

Use A Variable To Call A Text Box?

Jul 27, 2011

Im new to VB and have written an application which copies data around a network. Im trying to simplify the code that does the copying so i can get it to run as a module.[code]...

View 5 Replies

Using A Variable To Call A Function?

Aug 27, 2010

I have searched, but am not exactly sure what to call this process, so it's difficult to know what to search for. I have a set of functions that are almost Identical, so I want to call them, for example, function1(), function2(), function3(), etc. I want to be able to define and call them with a bit of code that says something like.

[Code]...

View 3 Replies

Call A Variable Without Addressing It Directly?

Jul 10, 2011

So I am having an issue where I want to call a variable without addressing it directly and I get an error for it:

Conversion from string "player1BuzzLock" to type 'Boolean' is not valid.

This is technically correct but why would it fail?

Dim player1BuzzLock As Boolean = False
Dim PlayerNum as Integer = 1
'...
Dim playerBuzzLock As Boolean = CType("player" & PlayerNum.ToString & "BuzzLock", Boolean)

View 13 Replies

Call Event (method) From Variable?

Mar 9, 2010

If I have a string that contains the name of a control is there a way to call that control's click event?

Dim a as string = "MyButton1"

Now I want to call MyButton1.Click Method or MyButton_Click Event using the contents of a.

View 7 Replies

Call Or Set Variable Value When Its Name Is Stored As String

Jun 6, 2011

My application has a variable VAR_1 that is boolean, this name is also stored in database.

Now I need to set VAR_1 value in my app by reading database and asign x value,

How do I call VAL_1 from a string?, this is:

Dim VAL_1 as boolean

Dim str as string = myTable.Rows(0).item("x") <--- Here's the name "VAL_1"

But I just can't find how to call VAL_1 by converting "VAL_1" to variable

View 10 Replies

Construct A String And Use It To Call A Variable?

Aug 3, 2011

This is probably a dumb question but I have to call one of 30 or so global variables by constructing the variable name to be called from another information. However when i do that it treats it as a string. Any ideas on how to make this work?eg something like this:

Public gsNewYork As String
public sub Getinfo
dim lslocation as string

[code].....

View 1 Replies

Function Variable To Be Separate For Each Call?

Nov 14, 2010

Private Function TestFunction (byval VariableA as SomeClass)
Static VariableB as integer
VariableB = variableA.position

[code].....

View 3 Replies

How To Call Variable In Public Class

Aug 22, 2011

I have this public class
Public Class commonSettings
Dim etcString As String = "some string"
End Class
How can I call etc String and use it entirely on my code?

View 3 Replies

VS 2005 Call A Subroutine Via A Variable

May 6, 2009

I'm looking to call a subroutine via a variable. For example:[code]Is that possible?

View 3 Replies

Forms :: Call A Function Whos Name Is In A Variable?

Apr 11, 2011

i would like to call a funtion whos name is in a vairable.

Dim Car_service As String
Private Sub ComboBox_Spray_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox_Spray.SelectedIndexChanged
Car_service = ("Spray_" & Me.ComboBox_Spray.Text)
end sub

Call spray_Standard 'this is what i need to change standard is what comes from the combobox 'but i would like to call the funtion depending on what the combobox.text was eg,' if combobox.text was Parkingsensors i would like to call the function call spray_parkingSensors

Private Sub Spray_Standard()
Price_Subtotal = 0
Price_Subtotal = (Damagecount * 65)
Car_Price_Subtotal.Value = Price_Subtotal
End Sub

View 7 Replies

Should A Local Variable Call Dispose Method And Set To Nothing?

Oct 14, 2009

I have 2 question, hope somebody give me an explanation: 1. Should a local variable call dispose method and set to nothing? 2. If some method have an arguments which it is a ByVal argument, it means a method create a new object? But If it is a ByRef argument, it means a method don't create a new object?

View 4 Replies

Visual Basic .net - Call Procedure From A Variable Name?

Jan 19, 2010

Is there a way to call a procedure in Visual Basic (.net) with a variable name? For example, the variable strColour can be one of 10 pre-defined values, green blue black white red pink orange yellow indigo purple. How to handle each one is in it's own Sub Routine, colgreen, colblue, colblack and so on.

I can use a bunch of if..then..else and select case, but what I'd like to have is something like VBA Excel's Run "col" & strColour

View 5 Replies

Call An Object Based On A Variable In Visual Studio?

Apr 24, 2012

So I'm trying to write a MasterMind game, but I have a problem I have 40 pictureboxes set up in 10 different rows, and I want to have one code handle all 10 rows, rather than copying and pasting the code and changing the names of the pictureboxes. I've been trying to use a variable to achieve this, but if it's possible, then I don't know the correct way to do it.This is what I have right now:

[Code]...

View 1 Replies

Forms :: Call Mdi Form Toolstripmenuitem Name Using The String Variable?

Jul 8, 2009

i need to call mdi form toolstripmenuitem name using the string variable. for ex, mdi form is Form1. toolstripmenuitem is customer master if i do like that "Form1.customer master.Enabled=True" its working

but my issue is i stored customer master in a string variable like mystring="customer master" i need to enabled using the string variable like Form1.mystring.enabled=True

View 11 Replies

Office Automation :: ByREF Variable Not Updating After Call?

May 31, 2011

I have a subroutine that passes several variables to the called subroutine.I want one of the variables to be updated by the called subroutine and then check for the change in the calling subroutine. My code works fine except that the variable I am checking

calling Sub routine
Code:
Public Sub ProjectName_Exit(Cancel As Integer)

[code].....

View 4 Replies

Program Function - Says, "The Type For Variable [variable] Will Not Be Inferred Because It Is Bound To A Field

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

VS 2010 Compiler Creates New Variable Automatically When Use If Statement Without Strictly Declared Variable?

Jan 10, 2011

Say that i have the following code that parse about 20k records from the DB.

Code #1

vb.net While reader.Read()
list.Add(If(Integer.TryParse(reader(0).ToString, 0), Integer.Parse(reader(0).ToString), 0))
End While

And then another code which does the very same thing but it seems to be a little cleaner.

Code #2

vb.net While reader.Read()
Dim storeowner As Integer = 0
Integer.TryParse(reader(0).ToString, storeowner)
list.Add(storeowner)
End While

This is what i am confused about; does the compiler creates a new variable automatically when i use the if statement without strictly declared variable? What approach is better in sense of performance?

View 2 Replies

Variable Naming Conventions To Illustrate Variable Type And Where Variables Are Declared

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

Import Text File : Object Variable Or With Block Variable Not Set

Mar 28, 2011

i have this error in the line of with xl.active......Object variable or With block variable not set.

Dim xl As Object
xl = CreateObject("Excel.Application")
With xl.ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:Documents and SettingsUserDesktop429MEDICA2.TXT", _ Destination:=xl.Range("$A$1"))

[code]....

View 4 Replies

Object Variable Or With Block Variable Not Set - From Property Get With Bindingsource.current?

May 31, 2012

Now I have the need to get a current value from a bindingsource in a property of a user control.In a previous thread I had tracked down the "Object variable or With block variable not set" to the return in the Get block of a property. At the time I was only using the Set so I just commented out the offending code until I needed it.

[Code]...

The error does not occur during a system compile, only upon saving the container object of the user control. As I said the Set works correctly, only the Get causes the error.I would like to know what I am missing/misunderstanding and am open to other suggestions of handling retrieving the current value of a bindingsource in a user control.

View 2 Replies

Pass A Variable To Another Form Or Else Make The Variable Visible To Both Forms?

Sep 5, 2010

Using Visual Basic 2008 Express. I need to pass a variable to another form. Or else make the variable visible to both forms.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved