469,344 Members | 6,124 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

VB.NET App: store a value in vb.net at run time

karthickbabu
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 like this, but not working any problem in this code
Expand|Select|Wrap|Line Numbers
  1.          For i As Integer = 0 To 1
  2.               For j As Integer = 0 To 1
  3.                    FirstMatrixArray(i, j) = Val(txtInput.Text)
  4.                        txtInput.Text = ""
  5.                        txtInput.Focus()
  6.                    End If
  7.                Next
  8.          Next 
  9.  
Let me know your idea about this

Hope your reply
Dec 3 '07 #1
4 2560
CyberSoftHari
487 Expert 256MB
The code you done will update the 2d array every time you trigger the enter.
1. Give i and j declaration as private in that class.
2. Increment i and j value after enter press (in key press event).
3. write assignment statement for FirstMatrixArray(i, j) in key press event after FirstMatrixArray index changed.
Dec 3 '07 #2
I tried all possible ways. But i couldnt get anything. Let me give any example it will help to me.

The code you done will update the 2d array every time you trigger the enter.
1. Give i and j declaration as private in that class.
2. Increment i and j value after enter press (in key press event).
3. write assignment statement for FirstMatrixArray(i, j) in key press event after FirstMatrixArray index changed.
Dec 6 '07 #3
Shashi Sadasivan
1,435 Expert 1GB
use variables i and j in the class (class variables)

and use the button click event (users hits enter / clicks the button to submit the value)

set i and j to 0 on the load of the form.

Expand|Select|Wrap|Line Numbers
  1. int i = 0, j = 0;
  2. int maxi = 2, maxj = 2;
  3. int[,] matrixArr = new int[maxi,maxj];
  4.  
  5. private void btnSubmitValue_Click(object sender,  EventArgs e)
  6. {
  7.    this.matrixArr[i,j] = this.txtInput.Text;
  8.    j++;
  9.    if(j >= this.maxj)
  10.    {
  11.        j = 0;
  12.        i++;
  13.    }
  14.    if(i >= this.maxi)
  15.    {
  16.        //array has been filled if it reaches this line
  17.        this.txtInput.Enabled = false;
  18.        this.btnSubmit.Enabled = false;
  19.    }
  20. }
I have used an online converter to convert it to vb .net, but havent tested it

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer =  0,j As Integer =  0 
  2. Dim maxi As Integer =  2,maxj As Integer =  2 
  3. Dim matrixArr(,) As Integer =  New Integer(maxi,maxj) {} 
  4.  
  5. Private  Sub btnSubmitValue_Click(ByVal sender As Object, ByVal e As EventArgs)
  6.    Me.matrixArr(i,j) = Me.txtInput.Text
  7.    j = j + 1
  8.    If j >= Me.maxj Then
  9.        j = 0
  10.        i = i + 1
  11.    End If
  12.    If i >= Me.maxi Then
  13.        'array has been filled if it reaches this line
  14.        Me.txtInput.Enabled = False
  15.        Me.btnSubmit.Enabled = False
  16.    End If
  17. End Sub
Dec 6 '07 #4
Hi
Thanks I got some ideas from your code. I will try this code. Surely it will be help to me. I reply after i test this code with my code

Once again thanks



use variables i and j in the class (class variables)

and use the button click event (users hits enter / clicks the button to submit the value)

set i and j to 0 on the load of the form.

Expand|Select|Wrap|Line Numbers
  1. int i = 0, j = 0;
  2. int maxi = 2, maxj = 2;
  3. int[,] matrixArr = new int[maxi,maxj];
  4.  
  5. private void btnSubmitValue_Click(object sender,  EventArgs e)
  6. {
  7.    this.matrixArr[i,j] = this.txtInput.Text;
  8.    j++;
  9.    if(j >= this.maxj)
  10.    {
  11.        j = 0;
  12.        i++;
  13.    }
  14.    if(i >= this.maxi)
  15.    {
  16.        //array has been filled if it reaches this line
  17.        this.txtInput.Enabled = false;
  18.        this.btnSubmit.Enabled = false;
  19.    }
  20. }
I have used an online converter to convert it to vb .net, but havent tested it

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer =  0,j As Integer =  0 
  2. Dim maxi As Integer =  2,maxj As Integer =  2 
  3. Dim matrixArr(,) As Integer =  New Integer(maxi,maxj) {} 
  4.  
  5. Private  Sub btnSubmitValue_Click(ByVal sender As Object, ByVal e As EventArgs)
  6.    Me.matrixArr(i,j) = Me.txtInput.Text
  7.    j = j + 1
  8.    If j >= Me.maxj Then
  9.        j = 0
  10.        i = i + 1
  11.    End If
  12.    If i >= Me.maxi Then
  13.        'array has been filled if it reaches this line
  14.        Me.txtInput.Enabled = False
  15.        Me.btnSubmit.Enabled = False
  16.    End If
  17. End Sub
Dec 6 '07 #5

Post your reply

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

Similar topics

3 posts views Thread by Tim Gallivan | last post: by
2 posts views Thread by Dotnet Gruven | last post: by
10 posts views Thread by Brett Romero | last post: by
6 posts views Thread by NickP | last post: by
3 posts views Thread by =?Utf-8?B?Sm9u?= | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.