473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

VB.NET App: Get Value from TextBox and stored in Array Variable

karthickbabu
Hi

Is Possible to store a value to declared Variable from Text Box at run time. I want to store a value from Text Box in 2 dimension array. First Value can be sotred in variable(0,0). If i press enter text box will be cleared and get another number and it stored in variable(0,1) and so on

I try the code as below but not working. I write this in Text Box KeyDown Event. If not in which event we write the code

Expand|Select|Wrap|Line Numbers
  1. Try
  2.             If e.KeyCode = Keys.Enter Then
  3.                 For i As Integer = 0 To 1
  4.                     For j As Integer = 0 To 1
  5.                         FirstMatrixArray(i, j) = val(txtInput.Text)
  6.                         txtInput.Text = ""
  7.                         txtInput.Focus()
  8.                     Next
  9.                 Next
  10.             End If
  11.     Catch ex As Exception
  12.          MessageBox.Show(ex.Message())
  13. End Try
  14.  
hope ur reply
Nov 21 '07 #1
4 8584
Frinavale
9,735 Expert Mod 8TB
Hi

Is Possible to store a value to declared Variable from Text Box at run time. I want to store a value from Text Box in 2 dimension array. First Value can be sotred in variable(0,0). If i press enter text box will be cleared and get another number and it stored in variable(0,1) and so on

I try the code as below but not working. I write this in Text Box KeyDown Event. If not in which event we write the code

Expand|Select|Wrap|Line Numbers
  1. Try
  2.             If e.KeyCode = Keys.Enter Then
  3.                 For i As Integer = 0 To 1
  4.                     For j As Integer = 0 To 1
  5.                         FirstMatrixArray(i, j) = val(txtInput.Text)
  6.                         txtInput.Text = ""
  7.                         txtInput.Focus()
  8.                     Next
  9.                 Next
  10.             End If
  11.     Catch ex As Exception
  12.          MessageBox.Show(ex.Message())
  13. End Try
  14.  
hope ur reply

I have a feeling that the string is getting lost when you clear the txtInput.Text. Remember that everything in VB.NET is a pointer...if you clear the value at the memory location where that pointer is pointing to....anything else referencing that memory location will be lost too.

So I suggest creating a new string based on the txtInput.Text to store in your FirstMatrixArray.

Eg:
Expand|Select|Wrap|Line Numbers
  1. FirstMatrixArray(i, j) = New String(txtInput.Text)
Hope this helps!
-Frinny
Nov 21 '07 #2
I have a feeling that the string is getting lost when you clear the txtInput.Text. Remember that everything in VB.NET is a pointer...if you clear the value at the memory location where that pointer is pointing to....anything else referencing that memory location will be lost too.

So I suggest creating a new string based on the txtInput.Text to store in your FirstMatrixArray.

Eg:
Expand|Select|Wrap|Line Numbers
  1. FirstMatrixArray(i, j) = New String(txtInput.Text)
Hope this helps!
-Frinny



No Frinny still it lose tha data in that Array Variable. I got only one value what i type last in that TextBox. But if i give msg box to display. It display with Exception
Nov 23 '07 #3
Frinavale
9,735 Expert Mod 8TB
No Frinny still it lose tha data in that Array Variable. I got only one value what i type last in that TextBox. But if i give msg box to display. It display with Exception
Hmm I took a look at your question again.
Are you sure you want to use the Text Box KeyDown Event?
Should you be using the KeyUp Event?
Nov 23 '07 #4
I try in key up event no improvements, If i use

new string(textbox1.text)

it shows exception "converison from string to integer type is not valid ".
Expand|Select|Wrap|Line Numbers
  1.                For i As Integer = 0 To FirstMatrixArray.GetUpperBound(0)
  2.                     For j As Integer = 0 To FirstMatrixArray.GetUpperBound(0)
  3.                         'value = CInt(txtFirstInput.Text)
  4.                         FirstMatrixArray(i, j) = CInt((txtFirstInput.Text).ToString)
  5.                         MsgBox(FirstMatrixArray(i, j))
  6.                         txtFirstInput.Text = ""
  7.                         txtFirstInput.Focus()
  8.                     Next
  9.                 Next
  10.  
Just i test using msg box it displays in msgbox whatever i give in text box but with excetion, i used conversion type also but no changes in my result.

i post the same question in some other forum. Some body replies you should not be programming, values cannot be stored at run time. They suggest like these only

val(0,0)= 2
val(0,1) = 3
.
.
.and so on


Hmm I took a look at your question again.
Are you sure you want to use the Text Box KeyDown Event?
Should you be using the KeyUp Event?
Dec 4 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ant | last post by:
Ok, so I have a regular input textbox on my webpage and I'm trying to work out how to make it so when the user presses a button the the textbox holds the value of a variable. I just can't work out...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
2
by: mcl chan | last post by:
Hello all, I'm using below code for c# app to call another app { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc Enable.RaisingEvents=false; proc...
5
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
4
by: James Pemberton | last post by:
I have recently created a ASP site utilizing Master Pages and all works fine until I want to proces my javascripts. Just to let you know, most of cliewnt side scripting is new to me. But...
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
4
karthickbabu
by: karthickbabu | last post by:
Is Possible to store a value to declared Variable from Text Box at run time. I want to store a value from Text Box in 2 dimension array. First Value can be sotred in variable(0,0). If i press enter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.