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


ADVERTISEMENT

Dimension Of Variable Inside For Loop

Mar 30, 2010

Using VB.NET .NetFramwork 3.5. This fails and strikes me as odd. Is this correct behavior:
Public Sub TestForEach()
For index As Integer = 1 To 10
Dim z As Integer
Assert.AreEqual(0, z)
z = index
Next
End Sub
I would expect z to always equal 0 as I thought the dim-ing of an integer would set the value to 0. If you run this. It fails at the second loop. For some reason z retains it's value of 1. I know I can manually initialize z to = 0, but I wanted to know if this is a bug or expected behavior.

View 9 Replies

Split The 2 Dimension Into 2 Variable From A String?

Jul 16, 2009

How do you split the 2 dimension into 2 variable from a string?

what i have:
RECT (-9895480 4134720, -3298480 9523800)

what i want to appear in the message box:

-9895480 4134720 - x axis
-3298480 9523800 - y axis

how do i split the string into 2 variables with "," as the splitting refernce point? I'm using vb08.

View 5 Replies

VS 2010 Loading Extremely Large(dimension) Images?

Feb 8, 2012

I'm trying to load this image file on a PictureBox but I get an "OutOfMemoryException was unhandled" error.

How do I allocate more memory for this? Or maybe use another container? My project's main feature is loading maps, unfortunately my boss wants to load the whole map and won't accept sliced version of the map.

View 8 Replies

[2005] Convert One Dimension Array To Two Dimension Array?

Feb 5, 2009

I have an one dimension string array ar1

ar1(0) ="One;is;a;dog;"
ar2(1)="Two;is;a;cat;"
...

I want to convert ar1 into ar2 which is a two dimension array

ar2(0)(0)="One";ar2(0)(1)="is";ar2(0)(2)="a";ar2(0)(3)="dog"
etc

View 4 Replies

'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

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

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

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

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 2010 Merging An Integer Variable With A String Variable?

Jun 2, 2011

Say I have something like this

Dim Level1 as Integer = 83
Dim Goal as String
Goal = InputBox(" What level is your goal?")

[code].....

View 7 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

Add Together Only 1 Dimension Of Array?

May 1, 2011

How do I use only one dimension of an array? What I have going on is: I have an array suit(1, 4) and rank(1, 13) to represent a deck of cards. What I want to do is take the value of the rank of the selected item in my listbox to be able to add it to the rank of other selected items in the listbox (essentially adding the players hand together). [code]...

View 5 Replies

3 Dimension Dynamic Array?

Jan 12, 2010

I am having trouble conceptualizing how to create and load my 3d Array. The Project does the following:

View 6 Replies

For Loop For 2 Dimension Array?

Nov 3, 2011

I had insert value from datagridview to array

but how to make the array become for loop function?
Dim rowNo As Integer = 0
counter = dgv.RowCount()

[code].....

View 5 Replies

Get One Dimension From A Bi-dimensional Array In .Net?

Feb 26, 2010

I have an application in VBA that gives to my VB.Net dll one bi-dimensional variant. It is a an array, in which every component is a another array containing two positions.

I want to get this two-position array. When I am using VBA I can access directly the data from each position by doing:dataArray(index, 0) or dataArray(index, 1)And when I want to get the two-position array I can use:

Dim posArray as variant
posArray = dataArray(index)

[Code]...

View 1 Replies

Get The Dimension In Pixel Of A Form?

May 26, 2012

I would like to know if it is possible to get the dimension in pixel of a form without the title bar and the border.

View 2 Replies

Add Additional Dimension To Output Array?

Oct 6, 2010

I need to add an additional dimesion to outputArrayOfBits() in the code below which I hope conveys my intention. I need to convert a one dimensional array of 1 to n boolean (bit) values into arrays that group them by 8's so the output can be consumed by someone needing these values to be in hex format (0000 1111) = 0F How do I change the declaration of 'outputArrayOfBits and the nested control loop to achieve that?

Dim inputArrayOfBits As New BitArray(32, True) ' I can't change this.
'Create array of bytes containing what will be sent out has hex numbers 0 - F
'outputArrayOfBits(0) = (1,1,1,1,1,1,1,1) 'Hex value FF

[code]....

View 11 Replies

How To Load A 2 Dimension Array With Strings

Apr 21, 2011

I need to manipulate data for 1000 boxes, each one of these boxes has 8 variables.How to declare an appropriate array? and how to load the array with the 8 variables for each box?

View 20 Replies

Multi-Dimension Array With Looping?

Feb 20, 2011

I am trying to create a multi dimension array that will search each row of the array and total up the number of 0's 1's, 2's, and 3's. I believe that I need to create some sort of looping structure that will search through each row of the array.I have created a listbox that will allow the user to pick which row of the array the program will search.This is what I have created so far, but I am only just learning and I am having trouble wrapping my head around how arrays work. So I'm not sure if I am on the right path or not.

Dim racescores(,) As Integer = {{0, 1, 0, 3, 2},
{1, 0, 2, 0, 0},
{0, 3, 0, 1, 0},

[code].....

View 3 Replies

Returning New Array Dimension From Within Function

Jun 22, 2011

I'm trying to return changes to array data, including redimensioned arrays, from within a function call in code similar to:
fault = MyFunction(Array1, Array2)
Public Function MyFunction(ByVal inObj1 as UserStruture(), ByVal inObj2 and Integer(,)) as String
Dim myResult as String = "Failed"
Dim tmpStruct() as UserStructure = inObj1

[Code] .....

This works fine in updating the input array 'Array1', only when the redimensioning of tmpStruct is NOT performed. After redimensioning tmpStruct, the redimensioned array is passed back successfully into 'inObj1' within the function 'MyFunction', but is not passed out of the function call; i.e.
fault = MyFunction(Array1, Array2) -

The dimension of array 'Array1' out of the function call remains as it was before the function call. However, the data change; i.e.
tmpStruct(0).Nam = "New Name"
is passed successfully out of the function call.

Why the Redim operation is not passed back out of such function calls. I would like to return changes to arrays 'Array1' and 'Array2', plus a result string from the function call if I can. Furthermore, I would also like to change the dimension of the array within the function call, if required, and return the complete redimensioned array back out of the function call.

View 4 Replies

Search A Multi-Dimension String?

Nov 6, 2011

I have searched for a simple way to search a string array. MS gives a clean simple solution for a one dimesion string.

Dim StrArray() As String = {"ABCDEFG", "HIJKLMNOP"}
Dim FindThisString As String = "JKL"
For Each Str As String In StrArray

[code]......

View 14 Replies

Storing 2-Dimension Arrays In My.Settings?

Dec 7, 2011

I'm still doing upgrades on my program that i'm creating and i've run into a bump again. I'm currently using a multi-dimension array to store a name, email, password, email provider, and user name. These 5 values are stored, corresponding with the latter, meaning the array is build as: name 1....n user name 1....n user email 1....n user email provider 1....n password 1....n So my question is, how can i store this in My.Settings? To be clearer, i'll use code: My.Settings.Name = name My.Settings.UserName = userName etc..... My current set up for a first run is like so... My.Settings.Password = adminInfo(2, 0) My.Settings.UserName = admingInfo(1, 0) etc.

View 11 Replies

VS 2008 Redim Last Dimension Of Array

May 13, 2010

I have the following array in my project that I'm trying to redim without losing the values.The problem with redim preserve is I can only redim the last dimension of the array. I want to redim the 2nd dimension without losing data. How do I get this to work?[code]

View 11 Replies







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