Public Sub changePoints(ByVal Name As String, StartPoint As Boolean, Point As Integer)
Locations(Point).Name = Name
If StartPoint = True Then
For i = 0 To 19
Locations(i).StartPoint = False
Next
End If
Locations(Point).StartPoint = StartPoint
DrawGraph()
End Sub
Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
GraphicalPlot.changePoints(PointNameBox.Text, MakeStart.Checked, LoadedPointValue)
End Sub
У меня есть 2 формы. Первая форма при щелчке с выбранной точкой отображает вторую форму с деталями точки в редактируемом текстовом поле. Когда вы нажимаете кнопку «Сохранить» во второй форме для сохранения сведений, вторая надпись над ней запускается и вызывает подпрограмму в первой форме, которая содержит глобальную переменную.Global Array не сохраняет внесенный в него изменения
Информация передается подпрограмме в первом виде правильно. Когда я проверяю значение глобального массива сразу после его изменения (сразу после строки Locations (Point) .Name = Name), он говорит, что значение было изменено правильно.
Однако после завершения подпрограммы глобальный массив возвращается к значению, которое оно имело до того, как была вызвана подпрограмма, и нет следа информации, которую я вводил во вторую форму.
Если это помогает, глобальный массив структуры:
Structure EnteredPoint
Dim Xcoord As Integer 'Stores X co-ordinate of point
Dim Ycoord As Integer 'Store Y co-ordinate of point
Dim Name As String 'Stores name of point, used to check if point is unused
Dim StartPoint As Boolean 'Checks if the point is the start point
Dim Selected As Boolean 'Checks if the point is currently being hovered over the mouse
Dim nextPoint As Integer 'Used to implement a linked list, making deleting and recreating points easier
End Structure
Имя меняется обратно к тому, что это не должно быть возможным; единственный раз, когда моя программа меняет имя за пределами инициализации (которое устанавливает его в «неиспользованный» или количество созданных точек).
Я искал его, показал его своему учителю и другу, и мы не смогли найти ничего, несмотря на то, что играли с ним часами. Любая помощь будет высоко оценена, так как это для моей курсовой работы Comp4!
Edit: добавлена vbnet3d
Sub DrawGraph()
'Used to draw the current state.
G = Me.CreateGraphics
G.Clear(Color.White) 'Sets entire background to white
Dim placeholder As Integer = 0 'Used to store the current point being checked.
If UsedLocations > 0 Then 'This part will only run if any points have been made
Do Until Locations(placeholder).nextPoint = 0 'Loops until all points have been drawn
If Locations(placeholder).StartPoint = True Then 'will only draw this if it is the starting point
G.FillEllipse(Brushes.LightBlue, Locations(placeholder).Xcoord - 3, Locations(placeholder).Ycoord - 3, 16, 16)
End If
If Locations(placeholder).Selected = True Then 'Will only draw this if it is the currently selected point
G.FillEllipse(Brushes.LightGreen, Locations(placeholder).Xcoord - 3, Locations(placeholder).Ycoord - 3, 16, 16)
End If
'Draws the actual Point
G.FillEllipse(Brushes.Black, Locations(placeholder).Xcoord, Locations(placeholder).Ycoord, 10, 10)
If UsedLocations <= 20 Then
placeholder = Locations(placeholder).nextPoint 'Gets the next point to be checked.
End If
Loop
If UsedLocations = 20 Then
If Locations(placeholder).Selected = True Then 'Will only draw this if it is the currently selected point
G.FillEllipse(Brushes.LightGreen, Locations(placeholder).Xcoord - 3, Locations(placeholder).Ycoord - 3, 16, 16)
End If
'Draws the actual Point
G.FillEllipse(Brushes.Black, Locations(placeholder).Xcoord, Locations(placeholder).Ycoord, 10, 10)
End If
End If
End Sub
Где массив МЕСТОПОЛОЖЕНИЕ объявлен? – vbnet3d
Вероятно, имеет отношение к ссылкам по умолчанию. Каковы имена форм? – Plutonix
Массив местоположений объявлен в самом верхнем, глобальном, первом строчке под открытым классом Графический график – Hellfire