'dynamically' Refer To A Variable?

Aug 18, 2010

I have a bunch of string variables, string1, string2, string3 etc.At the end of my program I want to write these strings to a file, but I don't want to have to laboriously type out string1, string2, string3 etc.

It would be much easier to use a loop to dynamically refer to (string & loopcounter), ie reference the variable by dynamically concatenating its name from a string and a number. Python can do this with eval(). How does VB do it? I can think of loads of examples where it'd be useful. Otherwise I have to type out all the different conditions and that's not efficient.

View 1 Replies


ADVERTISEMENT

Refer To Control Name Dynamically (VS 2005)?

Jun 14, 2009

I'm an Access/VBA programmer new to vb.net. In Access I can do this using the controls collection of form, but I can't figure out how or even if I can do it with vb.net.

I want to change this:

'tcpWeek(x) is a tab control page
My.Forms.frmBookMain.tcpWeek1.Text = "Mytext1"
My.Forms.frmBookMain.tcpWeek2.Text = "Mytext2"

[Code].....

View 4 Replies

Refer To Dynamically Created Controls?

Jun 29, 2012

I have 4 textbox on my formviz. txtQuantity0, txtRate0, txtDiscount0, txtAmount0When User Press Enter Key on txtAmount0 a new row of textbox is created as follows
txtQuantity1, txtRate1, txtDiscount1, txtAmount1

View 8 Replies

Asp.net - Refer To Footer Value In GridView Created Dynamically ASP VB

Jun 4, 2009

I have a Gridview that I create a dynamic footer wired up to the RowDataBound event.

However there is a 50/50 chance that 3 of the columns will have no data.

I want to be able to dynamically hide the columns with no data if possible.

I have tried doing this in the RowDatabound event by checking if the value is = 0 but that does not work because I think the event is called to early?

Is there anyway to refer to the values in the Footer row after ALL the data has been bound?

Ideally in VB

`Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then

[Code].....

View 2 Replies

Refer To A Numeric Variable?

Oct 8, 2010

In VB 2010, I am trying to use this query, but I always get an error message because the numerical variable CHAVE is not correctly called. STATUS and HISTORICO are string type fields, that will be filled by the string variables SITUACAO and DESCRICAO.DIA is a date type field and will be filled by the date type variable PROXIMA.CHAVE is a numerical field and should be filled by the numeric variable CHAVE.

sql = " INSERT INTO " & conta & " (status,dia,chave,historico)" & _
" VALUES ('" & situacao & "', #" & Format(proxima, "M/d/yy") & "#, & chave &, '" & descricao & "') "

View 6 Replies

VS 2008 Use A Variable To Refer To A Control By Name?

Jan 9, 2010

If I have a TextBox control with the Name Property = Textbox1, is there a way to use a variable for part of the name - like this:

Dim i as String = "1"
"TextBox" & i & ".Text" = "Hello"

View 3 Replies

Declare A Variable Dynamically?

May 9, 2012

I have searched online for a few hours to try to figure out how to do this, but nothing I found really makes sense, so could someone please tell me, in a simple way, how to do this?

Let's say I have a text box that the user fills out, named textbox1. And I have a combo box, named combobox1, which contains the choices A, B, C. And then I have a button named submit_button.

Each time that the user clicks submit_button, I would like to dynamically create a new variable. This variable should be named the same as textbox1.text, and should contain the value of combobox1.

For example, if the user types "blue" into textbox1, and chooses value "C" from combobox1, and then clicks submit_button... then the following variable should be dynamically created, like..Dim blue as String = "C"

And then, after that, if the user types "red" into textbox1, and chooses value "B" from combobox1, and then clicks submit_button... then another variable should be dynamically created, like...

Dim red as String = "B"

And each time the user submits new information into the textbox and combobox, a new variable should be created.Is it possible to have the program automatically create variables like this? If so, how?

My actual project is much more complicated than this, of course, so the above is just an example. But if I could figure out how to solve the problem in this example, I could figure out how to solve the entire project.

View 6 Replies

Declaring Variable Dynamically In .net?

Dec 21, 2011

I have started using the builder class to create my connection strings for the sole purpose of making more generic connectivity code. However, I am stumped on this issue. The MS eConnect product apparently expects to receive integrated security=SSPI in its connection string if you want to use integrated security, (vs Integrated Secturity=True). I thought I would just pass "Trusted_Connection"="SSPI" to the builder class.

as it turns out, the item for Integrated Security is boolean and despite what the documentation says, will not give me SSPI in my connection string. Has anybody else found this issue and is there a simple fix for it? as for now, I'll simply strip out the item and replace it in my string.

View 3 Replies

Dynamically Increment Variable Name In ASP.NET?

Jun 7, 2012

I am using the AJAXToolkit Accordion control and dynamically adding panes to it based on a query of the database. For example:

Jane logs in and pulls up the page with the accordion on it. In the database she has five rows in the todo_list table. So, I need to dynamically generate five panes that contain the info. from the table...but if Joe logs in he may have only three rows, and Josh may have fifteen - so I can never know how many an individual will have beforehand.

So, I need some way to dynamically name the variables (or is there another way to do this). For example, here is some pseudo-code of what I'm trying to accomplish:

Dim i as integer
For each row in todo_list
Dim ap + i as New AccordionPane
Add some info from the row to the pane
Next

View 1 Replies

Dynamically Assign Type Of Variable?

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

Dynamically Change Variable Types?

May 10, 2010

I'm trying to make an application to do mathematical equations, but I also want to implement error checking. So that if someone doesn't put anything in one of the fields the output textbox will say "Error".

But the problem is that I already declared the variables I used as a numeric value, in my case decimal.

So, when I make an if statement that says if inputbox1="" then outputbox1="Error" it doesn't work.

I think that in order to get this to work I would have to have it setup so that the variable that is exported to the text property of outputbox1 could switch between being declared as a decimal or string value based on what the user put into the textboxes. But I'm not sure how to go about this. Declaring the variables inside the if/elseif statements won't work because the variables need to be declared before they are calculated within my if/elseif statements.

View 1 Replies

How To Declare DataType Of Variable Dynamically

Jul 6, 2010

How can I define the datatype of an variable dynamically. I read out data from a file. In the file it is specified, if the raw-data is interpreted as single, integer or .... So my idea is: To check, what datatype is in use and then declare an array with this datatype to store the data there.

View 2 Replies

Php - Dynamically Choose And Set Class Variable?

Nov 4, 2010

I want to set a variable in a class. But I want to dynamically choose which variable to set.

[Code]...

View 1 Replies

VS 2010 : Dynamically Dimension A Variable?

May 5, 2010

is it possible to dynamically dimension a variable?in my case, i have a chart that has a varying number of series on it depending on the data extracted and in order to use those series, i have to dimension them manually before adding points to them, IE:

Dim series1 as New Series()
Dim series2 as New Series()
etc
etc

my series data is contained in a datatable, so i'll know the count required, but it will change at runtime, so obviously doing something like this won't work, but explains what i'm trying to do:

dim recordcount as integer = datatable.rows.count
for i = 1 to recordcount
dim "series"+recordcount.tostring as new series()
next

View 13 Replies

Dynamically Referencing Class Property With A Variable?

Feb 4, 2009

So Im iterating through the properties of a class. For each property Im iterating through a datatable until I find a column name with the same name as the property.

No worries so far, here's the isse: Once I've found a match I want to set the class's property to the value in the datatable but I'm having difficulty referencing the property as it has to be done through a variable.

Code:
Dim per As New Person
Dim t As Type = per.GetType
For Each p As PropertyInfo In t.GetProperties

[Code].....

View 2 Replies

Dynamically Created Event - Button To Simply Set A String Variable Equal To The Clicked Buttons Text

Mar 14, 2009

I have a form that I am adding a set of buttons to. I am adding an event to those buttons. I need this event to function slightly to determine what button was pressed.

I need the button to simply set a string variable equal to the clicked buttons text so I can determine what button was pressed.

How can this be accomplished?

''Adding the buttons''
For Each dr In dtMenus
Dim strMenuName As String
strMenuName = dr.Item("strMenuName").ToString

[CODE]...

View 5 Replies

VS 2008 Dynamically Declaring A Constant - Public Const Blah As String = Variable & "something"

Aug 5, 2009

How would I go about dynamically declaring a constant? (It's value is dynamic, not the variable name)

View 5 Replies

Dynamically Creating Methods For Dynamically Created Buttons?

Mar 15, 2011

I have this code.

Code:
Public Class Form1
Dim NPB As Button
Dim x As Integer

[code]....

As you can see, when I open a program from my menu, a new button will be created with text similar to this, "C:Program ". The button it self will not do anything. How can I create the method at the same time the button it is for is created? Also how can I change the text do that it gives me, for example, CCleaner.exe instead of the whole target path?

View 14 Replies

Forms :: Refer To Another Sub?

Nov 28, 2009

I have a program that used information form treenodes and put them in the textbox after timer ticks the problem is that i should use AddHandler for ticking, but i dont know how to refer to the title() and name() because they are not on the same sub private

[Code]....

View 1 Replies

How To Refer To A MessageBox

Aug 25, 2009

I am amateur programmer.so far, I can use Visual Basic .Net only. That is all I know!!How can I refer to a MessageBox?or how can I Programatically handle a MessageBox after it is displayed?I need to close a MessageBox after certain time if no response from the user.

View 3 Replies

Refer To An Object By Its Name?

Jun 18, 2012

Is there a possible way to refer an object through it's name in Vb.Net?The case is, I have menu items created in my designer with names such as MenuA, MenuB and MenuC.On the database, I created a table consisting the list of all available menus in string format : MenuA, MenuB all the way to MenuZ.

Also I created a dynamic table consisting the user permission, what menu is accessible by a certain user.So when I started the app, it will get the name of menu assigned to the logged user, and start to turn the Visible property to TRUE.If it was a Control, I would just loop through it by Parent.Controls.Find(FoundMenu, True).My problem is most of it is not a control, it is an Item added to the Control, or even another SubItem added to the Item.So how can I found an object in my UI only by it's name?

SearchQuery = "SELECT menu_name FROM tbl_menulist menu, tbl_user user WHERE menu.id_menu = user.id_menu"
QueryReader = ExecuteQueryReader(SearchQuery)
QueryReader.Read()

[code]....

View 1 Replies

VS 2005 What Value Is Or What It Could Mean / Refer To

Jan 14, 2010

Can anyone tell me looking at this picture what Value is or what it could mean/reffer to? (S-1-5-xx-xxx)I had to block out some of it since I am not sure what it means.

View 2 Replies

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

Can Refer To Samples Of Such Apps?

Aug 15, 2011

I would like to develop a VB.Net based smart device app. A simple one. Do any of u know where i can refer to samples of such apps?

View 2 Replies

How To Refer Text Box As Username

Nov 18, 2011

I am creating a project using VB, and I am new to VB, I am still a beginner, I need help in retrieving email address from database when I enter the username, I have added the code below, please review it and let me know, basically when I enter the username it has pull the email address and display in the label..[code]I am stuck at the sql statement as I have no idea how to refer the text box as the username i.e "& uname" it is the name of the text box, is it the right way, also then as I informed I need to paste the email address in the label and the name is label2, I am trying it as " label2.text=da" but I get a error message, I am using Visual basic professional 2010.

View 11 Replies

Cannot Refer To Itself Through Its Default Instance

Sep 2, 2009

am making a super advanced text processor and i am at the point where i am trying to make print preview dialog [code] Word_Env.Form1' cannot refer to itself through its default instance; use 'Me' instead.i have tried "Me" but that don't work.

View 2 Replies

How To Programmatically Refer To A Control

Aug 23, 2011

This was explained in a recent thread - but I can't find it again :-( Why won't the following work? I am trying to set the bounds on 9 buttons - Button11 to Button19. All these buttons are already added in design time. qli() is a rectangle array.

[Code]...

View 9 Replies

How To Refer To Columns In An Array

May 7, 2012

I am very new to programming so I apologize if I am asking really basic questions here, but how would I go about referring to a specific column in an array? I am trying to use the prices in one column of my array and multiply that by a quantity, but I am not sure how to extract the price out of the array.

[Code]...

View 4 Replies

How To Refer To Container Of A Usercontrol

Mar 9, 2011

I have a user control called UCO and it is being put in many diffrent forms.How can i refer to these forms from the code of the UCO?For instance, how can i get the color of the form and make the UCO have the same color?

View 1 Replies

Make A Control Refer To Itself?

Jan 13, 2009

Im working on a project and just wanted to know to make a control refer to itself?I know that by using the word "Me", the system refers to the form but how about the control. I know that i can simply name the control (e.g. txtSurname.Clear) but if i was to use the code on multiple controls it would save alot of time if the control could simply refer to itself!

View 7 Replies







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