viegasss Posted March 16, 2012 at 11:21 AM Report #444180 Posted March 16, 2012 at 11:21 AM Public Class Form1 Dim n1() As Integer Dim n2() As Integer Dim max As Integer Dim nome() As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load max = 0 ReDim nome(max) ReDim n1(max) ReDim n2(max) nome(0) = "Ana" n1(0) = 11 n2(0) = 12 ListBox1.Items.Add(nome(0)) ListBox1.SelectedIndex = 0 Label7.Text = nome(0) Label8.Text = n1(0) Label9.Text = n2(0) Label10.Text = ((n1(0) + n2(0)) / 2) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click max = max + 1 ReDim Preserve nome(max) ReDim Preserve n1(max) ReDim Preserve n2(max) nome(max) = InputBox("Nome:", "Nome") n1(max) = InputBox("Introduza a nota", "Primeira Nota") n2(max) = InputBox("Introduza a nota", "Segunda Nota") ListBox1.Items.Add(nome(max)) ListBox1.SelectedIndex = max Label7.Text = nome(max) Label8.Text = n1(max) Label9.Text = n2(max) Label10.Text = ((n1(max) + n2(max)) / 2) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim indx As Integer If ListBox1.SelectedIndex - 1 Then MsgBox("Selecione um elemento na lista", MsgBoxStyle.Information, "Tente de Novo") Else indx = ListBox1.SelectedIndex nome(indx) = InputBox("Introduza o nome", "Nome") n1(indx) = InputBox("Introduza a nota", "Primeira Nota") n2(indx) = InputBox("Introduza a nota", "Segunda nota") ListBox1.Items(indx) = nome(indx) Label7.Text = nome(max) Label8.Text = n1(max) Label9.Text = n2(max) Label10.Text = ((n1(max) + n2(max)) / 2) End If End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim i As Integer [b] i = ListBox1.SelectedIndex Label7.Text = nome(i)[/b] ---> dá-me um erro que diz "Índice fora dos limites da matriz." Label8.Text = n1(i) Label9.Text = n2(i) Label10.Text = ((n1(i) + (n2(i))) / 2) End Sub End Class ajudem sff boa tarde!
edmolko Posted March 16, 2012 at 02:18 PM Report #444203 Posted March 16, 2012 at 02:18 PM Tens que verificar se ListBox1.SelectedIndex > -1
viegasss Posted March 16, 2012 at 02:47 PM Author Report #444211 Posted March 16, 2012 at 02:47 PM no label7.text ainda dá erro diz que "Índice fora dos limites da matriz."
edmolko Posted March 16, 2012 at 02:51 PM Report #444213 Posted March 16, 2012 at 02:51 PM Em debug, coloca um breakpoint nessa linha e verifica qual o length do array nome e qual o valor do ListBox1.SelectedIndex.
viegasss Posted March 16, 2012 at 03:09 PM Author Report #444218 Posted March 16, 2012 at 03:09 PM Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim i As Integer Label7.Text = nome(i) Label8.Text = n1(i) Label9.Text = n2(i) Label10.Text = ((n1(i) + (n2(i))) / 2) i = ListBox1.SelectedIndex > -1 --> Assim dá! só que na listbox só aparece uma vez depois se selecionar outro já nao dá End Sub End Class
edmolko Posted March 16, 2012 at 03:12 PM Report #444221 Posted March 16, 2012 at 03:12 PM Não podes mudar de sítio a inicialização da variável i, caso contrário i vai ter sempre o valor 0 (por defeito). Tens é que tentar perceber porque é que o valor do SelectedIndex está fora da dimensão do array nomes
viegasss Posted March 16, 2012 at 03:14 PM Author Report #444222 Posted March 16, 2012 at 03:14 PM existe algum método para Atualizar a listbox ?
edmolko Posted March 16, 2012 at 03:19 PM Report #444227 Posted March 16, 2012 at 03:19 PM se colocares este código: Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim i As Integer i = ListBox1.SelectedIndex Debug.Print("Valor de i = " & i) Debug.Print("Tamanho do array = " & nome.Length) Label7.Text = nome(i) ---> dá-me um erro que diz "Índice fora dos limites da matriz." Label8.Text = n1(i) Label9.Text = n2(i) Label10.Text = ((n1(i) + (n2(i))) / 2) End Sub O que é que ele escreve na immediate window?
viegasss Posted March 16, 2012 at 03:39 PM Author Report #444234 Posted March 16, 2012 at 03:39 PM http://imageshack.us/photo/my-images/210/semttulogo.jpg/ Está aqui uma print amigo! vê
edmolko Posted March 16, 2012 at 03:48 PM Report #444235 Posted March 16, 2012 at 03:48 PM Tal como te disse tens que verificar se é o index é maior que -1: Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim i As Integer i = ListBox1.SelectedIndex if i >-1 then Label7.Text = nome(i) Label8.Text = n1(i) Label9.Text = n2(i) Label10.Text = ((n1(i) + (n2(i))) / 2) end if End Sub
viegasss Posted March 16, 2012 at 04:03 PM Author Report #444239 Posted March 16, 2012 at 04:03 PM http://imageshack.us/photo/my-images/692/semttulocaj.jpg/ Tipo no programa so dá para alterar o luis os outros não consigo alterar! Consegues ver qual é o problema está aqui um trabalho 🙂
viegasss Posted March 16, 2012 at 04:06 PM Author Report #444242 Posted March 16, 2012 at 04:06 PM https://rapidshare.com/files/3710618258/array_xD.rar Tens aqui o link do meu trabalho, vê sff
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now