Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,151 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,356 people online right now. Registration is fast and FREE... Join Now!




Magic Square

 
Reply to this topicStart new topic

Magic Square

dumbstruckk
14 Jul, 2008 - 03:02 PM
Post #1

New D.I.C Head
*

Joined: 13 Jul, 2008
Posts: 2

Hi, we are asked to make a magic square (3x3) using 3 listboxes and initialize with "?". My codes are
CODE

Public Class Form1
    Dim numlist1(2) As Double
    Dim numlist2(2) As Double
    Dim numlist3(2) As Double

   Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

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

    End Sub

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

    Sub InitListBox()
        For c As Integer = 1 To 3
            numlist1(c) = ListBox1.Text(c) = "?"
            numlist2(c) = ListBox2.Text(c) = "?"
            numlist3(c) = ListBox3.Text(c) = "?"
        Next

    End Sub
End Class


It says that they are not in the bound of the array. What am I doing wrong? I am so confused with all these visual basic codes o__o heheh thanks.
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Magic Square
14 Jul, 2008 - 03:11 PM
Post #2

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 863



Thanked: 54 times
Dream Kudos: 2250
My Contributions
vb

Dim numlist1(2) As Double
Dim numlist2(2) As Double
Dim numlist3(2) As Double


Defines an array containing 3 elements. Of which the first starts at 0 (Zero) upto 2 (Two).
In basic array start at 0 upto Number of elements minus 1
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Magic Square
14 Jul, 2008 - 03:14 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET smile.gif
User is offlineProfile CardPM
+Quote Post

WayneSpangler
RE: Magic Square
14 Jul, 2008 - 04:39 PM
Post #4

D.I.C Head
**

Joined: 22 Mar, 2008
Posts: 103



Thanked: 9 times
My Contributions
CODE
For c As Integer = 0 To 3
            numlist1(c) = 123
            numlist1(c) = ListBox1.Text(c) = "?"
            numlist2(c) = ListBox2.Text(c) = "?"
            numlist3(c) = ListBox3.Text(c) = "?"
        Next

First change the 3 in your for loop to 2 (the largest number in the array).
Next you can't use two(2) = signs in a statement
Next numlist is a double so you can't put a string in a number unless the string
is a number then you have to parse it to a double .
CODE
numlist3(c) = Double.Parse(ListBox1.Text)

If you are putting the contents of the listbox into the arrays then use:
CODE
        For c As Integer = 1 To 3
            numlist1(c) = ListBox1.Items(c).ToString
            numlist2(c) = ListBox2.Items(c).ToString
            numlist3(c) = ListBox2.Items(c).ToString
        Next


This post has been edited by WayneSpangler: 14 Jul, 2008 - 04:43 PM
User is offlineProfile CardPM
+Quote Post

dumbstruckk
RE: Magic Square
15 Jul, 2008 - 11:29 AM
Post #5

New D.I.C Head
*

Joined: 13 Jul, 2008
Posts: 2

thank you so much for the help. I think I am starting to understand it better now. tongue.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:33AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month