2 Replies - 2894 Views - Last Post: 04 February 2010 - 07:01 AM Rate Topic: -----

#1 mono15591  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

assigning value to array...

Posted 03 February 2010 - 10:34 PM

I decided to learn Visual basic because I want to see actual results and I don't see any in C++

I'm using the little help links that come with the program to learn the syntax and when I was following it I get "Declaration expected" I'm going to assume that there is something wrong with the way that I'm assigning the array it's values but I don't know what to do.
Public Class Form1

    Dim player(2) As String
    player(0) = "Bob"
    player(1) = "Bill"
    player(2) = "Ted"


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = player(0) & " is player 1."
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = player(1) & " is player 2."
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = player(2) & " is player 3."
    End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: assigning value to array...

#2 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: assigning value to array...

Posted 04 February 2010 - 06:24 AM

Wrong forum... you need VB.NET...
Was This Post Helpful? 0
  • +
  • -

#3 mr.coder  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 41
  • Joined: 31-January 10

Re: assigning value to array...

Posted 04 February 2010 - 07:01 AM

You could assign values in Arrays as :

- On Declaration of Array

    Dim player() As String = {"Bob", "Bill", "Ted"}



OR

- On Load Event of Form
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        player(0) = "Bob"
        player(1) = "Bill"
        player(2) = "Ted"
    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1