bonjour,
j'ai un DGVCote qui charge les données journalières de ma BD, j'ai un deuxième DGVAnaTech qui analyse le premier DGV. Dans une de mes functions j'ai besoin de lire une cellule du DGVAnaTech précédent, donc du jour précédent, mais ma routine n'a pas le temps d'inscrire la ligne avec de faire l'analyse du jour suivant. donc j'ai un messagej'ai essayé de mettre un messagebox à la fin de chaque journées analysé et ma procédure fonctionne bien car la ligne a le temps de s'afficher avant la seconde passe.Citation:
L'exception System.ArgumentOutOfRangeException n'a pas été gérée par le code utilisateur
Message=L'index était hors limites. Il ne doit pas être négatif et doit être inférieur à la taille de la collection.
Mon probléeme ce trouve au niveau de la ligne OBVHier = CDbl(DGVAnaTech.Item(6, ind - 1).Value)Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 For i = 0 To (DGVCote.Rows.Count - 2) 'Appel de la classe analiTech AT = New AnaliTech At.Symb = symb At.DateAnali = DGVCote.Item(0, i).Value At.MM50 = MMS(i, 50).ToString("0.000") At.MM200 = MMS(i, 200).ToString("0.000") At.VoluMoyen3 = MMSVolume(i, 3) At.VoluMoyen100 = MMSVolume(i, 100) At.RSI = RSI(i, 14).ToString("0.000") At.OBV = OBV(i) DelDGVAnaTech(At.DateAnali & "," & "AT.MME12" & "," & "AT.MME16" & "," & At.MM50 & "," & At.MM200 & "," & At.RSI & "," & At.OBV & "," & At.VoluMoyen3 & "," & At.VoluMoyen100 & "," & "at.MACD" & "," & "at.MACDSign") My.Application.DoEvents() effaceClasse() 'MessageBox.Show("yy") Next
merci de vos suggestionsCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 Function OBV(ByVal ind As Integer) As Integer My.Application.DoEvents() Dim Rep As Double = 0 Dim OBVHier As Double = 0 If ind = 0 Then 'le volume est le premier de la serie on passe Else 'L'OBV précédent OBVHier = CDbl(DGVAnaTech.Item(6, ind - 1).Value) Dim Vol As Double = CDbl(DGVCote(6, ind).Value) Dim Prix As Double = CDbl(DGVCote(5, ind).Value) Dim PrixHier As Double = CDbl(DGVCote(5, ind - 1).Value) If PrixHier > Prix Then 'Si l'écart est négatif je soustrais le volume du jour de l'OBV Rep = OBVHier - Vol ElseIf PrixHier < Prix Then 'Si l'écart est positif j'additionne le volume à l'OBV Rep = OBVHier + Vol ElseIf PrixHier = Prix Then Rep = OBVHier End If End If Return Rep End Function
Je vais passer par un Dataset pour effectuer mes opérations, le hic c'est que je ne connais pas le Dataset.
Premièrement j'aimerais faire une function dans ma classe AcceeDonnee pour executer mes opérations avec la BD. Ma classe comprend:
Avec l'exemple de M. Desserre j'arrive à créer un DataSet et j'aimerais faire un function pour construire un Dataset dans la classe AcceesDonnee.Code:
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 Imports System.Data.OleDb Public Class AcceesDonnee Dim _cn As OleDbConnection Sub OuvrirConnection() 'Chaîne de connection Dim strConnection As String = My.Settings.BourseConnectionString If _cn Is Nothing Then _cn = New OleDbConnection(strConnection) Try _cn.Open() Catch ex As Exception Throw (New ApplicationException("L'ouverture à échoué avec une ex. de type " & ex.GetType.FullName, ex)) End Try End Sub Sub FermerConnection() If _cn IsNot Nothing Then _cn.Close() End Sub Function FournirDataReader(ByVal SQL As String) As OleDbDataReader Dim dr As OleDbDataReader Try Me.OuvrirConnection() Dim Cmd As New OleDbCommand With Cmd .Connection = Me._cn .CommandType = CommandType.Text .CommandText = SQL End With 'Obtention des enregistrements dr = Cmd.ExecuteReader() Return dr Catch ex As Exception Me.FermerConnection() Throw New ApplicationException("La Commande à échoué", ex) End Try End Function Function DoublonEsTuLa(ByVal SQL As String) As OleDbDataReader Dim dr As OleDbDataReader Try Me.OuvrirConnection() Dim Cmd As New OleDbCommand With Cmd .Connection = Me._cn .CommandType = CommandType.Text .CommandText = SQL End With 'Obtention des enregistrements dr = Cmd.ExecuteReader() Return dr Catch ex As Exception Me.FermerConnection() Throw New ApplicationException("La Commande à échoué", ex) Finally 'Me.FermerConnection() End Try End Function Function FournirValeur(ByVal SQL As String) As Integer Try Me.OuvrirConnection() Dim cmd As New OleDbCommand() With cmd .Connection = Me._cn .CommandType = CommandType.Text .CommandText = SQL End With Return CType(cmd.ExecuteScalar, Integer) Catch ex As Exception Throw New ApplicationException("La commande a échoué", ex) Finally Me.FermerConnection() End Try End Function Function ExecuterCommande(ByVal Sql As String) As Integer Try Me.OuvrirConnection() Dim cmd As New OleDbCommand() With cmd .Connection = Me._cn .CommandType = CommandType.Text .CommandText = Sql Return cmd.ExecuteNonQuery End With Catch ex As Exception Throw New ApplicationException("La Mise à jour à échoué") Finally Me.FermerConnection() End Try End Function End Class
est-ce possible?