Nested For Loop to populate matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slvr02scooby
    New Member
    • Feb 2008
    • 9

    Nested For Loop to populate matrix

    So this is an introductory course, but i'm having the hardest time understanding how to do this problem. By clicking on one button it's supposed to have the following output:

    0 1 2 3 4
    5 6 7 8 9
    10 11 12 13 14
    15 16 17 18 19
    20 21 22 23 24
    25 26 27 28 29
    30 31 32 33 34
    35 36 37 38 39
    40 41 42 43 44
    45 46 47 48 49

    Five numbers a line for 10 lines.I know we're required to use two For Statements and supposed to use carriage return-line's but I know it's easier to use vbnewline which is ok. Of course I had an example that was similar but apparently i only saved the project and not the code...=/

    Any help would be greatly appreciated!
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • werks
      New Member
      • Dec 2007
      • 218

      #3
      I can only come up with this.. Just modify it..

      [CODE=vb 6]
      Private Sub cmdGenerate_Cli ck()
      Dim i As Integer
      Dim j As Integer
      j = 0
      For i = 0 To 49
      j = j + 1
      If j = 5 Then
      j = 1
      Print vbCrLf
      Print i
      Else
      Print i
      End If
      Next
      End Sub

      Private Sub Form_Load()
      Form1.WindowSta te = 2
      End Sub

      [/CODE]


      -Kenneth
      -"Better Than Yesterday"

      Comment

      • slvr02scooby
        New Member
        • Feb 2008
        • 9

        #4
        Sorry if my wording was misleading, i'm by no means looking for someone to tell me the answer, I've been attempting and had a much better understanding when I had my example but i don't anymore!

        What I have so far is stating

        Dim"name" as integer

        I know I need to create a For statement, so I need to use 2 variables such as "x" and "y", is it as simple as x= 0 to 49 and y= something like if x doesn't equal...then +1?

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          Can you kindly post your code for reference of our experts please.

          Comment

          • jamesd0142
            Contributor
            • Sep 2007
            • 471

            #6
            you need:

            textbox - textbox1
            button - button1

            [code=vbnet]
            Public Class Form1
            Dim i As Integer
            Dim a As Integer = 0
            Dim hold(49) As Integer

            Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
            Dim a As Integer = 0
            For i = 0 To 49
            hold(i) = i
            Next
            For i = 0 To 49
            a += 1
            TextBox1.Text = TextBox1.Text & hold(i) & " "
            If a = 5 Then
            TextBox1.Text = TextBox1.Text & vbCrLf
            a = 0
            End If
            Next
            TextBox1.Text = Mid(TextBox1.Te xt, 1, Len(TextBox1.Te xt) - 2)
            End Sub
            End Class
            [/code]
            Attached Files

            Comment

            • werks
              New Member
              • Dec 2007
              • 218

              #7
              Originally posted by jamesd0142
              you need:

              textbox - textbox1
              button - button1

              [code=vbnet]
              Public Class Form1
              Dim i As Integer
              Dim a As Integer = 0
              Dim hold(49) As Integer

              Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
              Dim a As Integer = 0
              For i = 0 To 49
              hold(i) = i
              Next
              For i = 0 To 49
              a += 1
              TextBox1.Text = TextBox1.Text & hold(i) & " "
              If a = 5 Then
              TextBox1.Text = TextBox1.Text & vbCrLf
              a = 0
              End If
              Next
              TextBox1.Text = Mid(TextBox1.Te xt, 1, Len(TextBox1.Te xt) - 2)
              End Sub
              End Class
              [/code]

              Are you using VB.Net?


              --
              Kenneth
              "Better Than Yesterday"

              Comment

              • jamesd0142
                Contributor
                • Sep 2007
                • 471

                #8
                Originally posted by werks
                Are you using VB.Net?


                --
                Kenneth
                "Better Than Yesterday"
                im using vb 2005, but i find its the same as vb.net right?

                Comment

                • werks
                  New Member
                  • Dec 2007
                  • 218

                  #9
                  Originally posted by jamesd0142
                  im using vb 2005, but i find its the same as vb.net right?
                  No idea im still in VB 6..


                  --
                  Kenneth
                  "Better Than Yesterday"

                  Comment

                  • kadghar
                    Recognized Expert Top Contributor
                    • Apr 2007
                    • 1302

                    #10
                    Originally posted by jamesd0142
                    im using vb 2005, but i find its the same as vb.net right?
                    not always, and not for every version, most of the changes in .net and in express editions is that the mid, left and right functions are being replaced by the .substring property, also the Len function is replaced with the .lenght property.

                    But, the main idea is well shown in the code, so i think the syntax problems shouldn't be so.

                    Comment

                    • slvr02scooby
                      New Member
                      • Feb 2008
                      • 9

                      #11
                      Now if I don't use a text box then I would just need to put it in a msgbox instead fo rthe window to pop up correct?

                      I'm using VB2005

                      Comment

                      • kadghar
                        Recognized Expert Top Contributor
                        • Apr 2007
                        • 1302

                        #12
                        Originally posted by slvr02scooby
                        Now if I don't use a text box then I would just need to put it in a msgbox instead fo rthe window to pop up correct?

                        I'm using VB2005
                        yeap, that's right, but remember you cannot select the text in a msgbox, nor copy it.

                        Comment

                        • slvr02scooby
                          New Member
                          • Feb 2008
                          • 9

                          #13
                          Correct. i'm not looking for any interaction, just for the window to show the table.

                          Now i've run in to my next problem, after working on it last night i go to pull it up and while the project exsists, the Form and Design are nowhere to be found and I know I saved them both each time before trying to run it.

                          I know this is simple for some but man this program is frustrating lol

                          Comment

                          • kadghar
                            Recognized Expert Top Contributor
                            • Apr 2007
                            • 1302

                            #14
                            Originally posted by slvr02scooby
                            Correct. i'm not looking for any interaction, just for the window to show the table.

                            Now i've run in to my next problem, after working on it last night i go to pull it up and while the project exsists, the Form and Design are nowhere to be found and I know I saved them both each time before trying to run it.

                            I know this is simple for some but man this program is frustrating lol
                            To be honest with you, i've never used vb2005 other than the express edition, but i think the Form should be saved in the same dir as the project, may be it creates a subdir called src or source... but it should be somewhere around there. Its extension is .frm

                            Comment

                            • slvr02scooby
                              New Member
                              • Feb 2008
                              • 9

                              #15
                              Yeah I am using the express edition, it does make sub directories for them but it just says Your project currently has no data sources associated with it.

                              Comment

                              Working...