Jump to content

Help needed for college assignment (with arrays)

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
juniordee

juniordee

    Newbie

  • Members
  • Pip
  • 9 posts
Hi, I am currently working on an assignment for college, and need help with something.

First off, here is my code.

Public Class Arrays_Loops

    Dim defaultArray(,) As Integer = {{4, 12, 33}, {18, 12, 10}, {14, 29, 5}, {19, 25, 2}}

    Dim newArray(,) As Integer


    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        fillTextboxDefault()

    End Sub


    Private Sub fillTextboxDefault()

        txt00.Text = defaultArray(0, 0)

        txt01.Text = defaultArray(0, 1)

        txt02.Text = defaultArray(0, 2)

        txt10.Text = defaultArray(1, 0)

        txt11.Text = defaultArray(1, 1)

        txt12.Text = defaultArray(1, 2)

        txt20.Text = defaultArray(2, 0)

        txt21.Text = defaultArray(2, 1)

        txt22.Text = defaultArray(2, 2)

        txt30.Text = defaultArray(3, 0)

        txt31.Text = defaultArray(3, 1)

        txt32.Text = defaultArray(3, 2)

    End Sub


    Private Sub fillArray()

        newArray(0, 0) = txt00.Text

        newArray(0, 1) = txt01.Text

        newArray(0, 2) = txt02.Text

        newArray(1, 0) = txt10.Text

        newArray(1, 1) = txt11.Text

        newArray(1, 2) = txt12.Text

        newArray(2, 0) = txt20.Text

        newArray(2, 1) = txt21.Text

        newArray(2, 2) = txt22.Text

        newArray(3, 0) = txt30.Text

        newArray(3, 1) = txt31.Text

        newArray(3, 2) = txt32.Text

    End Sub

End Class


What this code is supposed to do is replace the values in newArray with what the user inputs in the textboxes.

Now the question is, how can I call my fillArray() sub only when it is needed? Do I even need a private sub for this? I don't know how I can get the program to automaticly replace the values of newArray in real time, when the user changes the values in the textbox.

I hope you understand what I'm trying to explain, and that someone can help me with this.

Thanks.

#2
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
hello there i made few tricks i will post the code & attach the solution

Public Class Form1

    Dim defaultArray(,) As Integer = {{4, 12, 33}, {18, 12, 10}, {14, 29, 5}, {19, 25, 2}}

    Dim newArray(,) As Integer = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}


    Private Sub fillTextboxDefault()

        txt00.Text = defaultArray(0, 0)

        txt01.Text = defaultArray(0, 1)

        txt02.Text = defaultArray(0, 2)

        txt10.Text = defaultArray(1, 0)

        txt11.Text = defaultArray(1, 1)

        txt12.Text = defaultArray(1, 2)

        txt20.Text = defaultArray(2, 0)

        txt21.Text = defaultArray(2, 1)

        txt22.Text = defaultArray(2, 2)

        txt30.Text = defaultArray(3, 0)

        txt31.Text = defaultArray(3, 1)

        txt32.Text = defaultArray(3, 2)

    End Sub


    Public Sub fillArray()


        newArray(0, 0) = txt00.Text

        newArray(0, 1) = txt01.Text

        newArray(0, 2) = txt02.Text

        newArray(1, 0) = txt10.Text

        newArray(1, 1) = txt11.Text

        newArray(1, 2) = txt12.Text

        newArray(2, 0) = txt20.Text

        newArray(2, 1) = txt21.Text

        newArray(2, 2) = txt22.Text

        newArray(3, 0) = txt30.Text

        newArray(3, 1) = txt31.Text

        newArray(3, 2) = txt32.Text

    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        fillTextboxDefault()

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        fillArray()

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        txt00.Text = newArray(0, 0)

        txt01.Text = newArray(0, 1)

        txt02.Text = newArray(0, 2)

        txt10.Text = newArray(1, 0)

        txt11.Text = newArray(1, 1)

        txt12.Text = newArray(1, 2)

        txt20.Text = newArray(2, 0)

        txt21.Text = newArray(2, 1)

        txt22.Text = newArray(2, 2)

        txt30.Text = newArray(3, 0)

        txt31.Text = newArray(3, 1)

        txt32.Text = newArray(3, 2)

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        txt00.Text = ""

        txt01.Text = ""

        txt02.Text = ""

        txt10.Text = ""

        txt11.Text = ""

        txt12.Text = ""

        txt20.Text = ""

        txt21.Text = ""

        txt22.Text = ""

        txt30.Text = ""

        txt31.Text = ""

        txt32.Text = ""

    End Sub

End Class


download link:

http://www.coderisla.../file.php?id=74
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel

#3
juniordee

juniordee

    Newbie

  • Members
  • Pip
  • 9 posts
Ok I see what you did, and I understand how it works, but I found a better solution myself just 5 minutes ago in the shower :)

I should have explained what the end product was going to do, instead of just explaining this part of the code (lesson learned).

The final product is going to have a "Calculate" button that would multiply the rows and subtract the the columns. So the solution I found this morning (taking my shower) was to put my fillArray() sub with my calculate button (duh). :)

So thanks for the help, I really appreciate it and will do my best to help others the same way you do.

Thanks

#4
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
no problem, as you mentioned it is best to well explain your problem :) good luck
Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel