Message d'erreur

kovalev24 Messages postés 6 Date d'inscription mardi 17 mars 2009 Statut Membre Dernière intervention 17 mars 2009 - 23 janv. 2009 à 18:51
kovalev24 Messages postés 6 Date d'inscription mardi 17 mars 2009 Statut Membre Dernière intervention 17 mars 2009 - 23 janv. 2009 à 20:07
bonjour,
j'ai un message d'erreur qui s'affiche des fois dans une application vb.net qui genere des fichiers excel et envoi un mail par smtp, je vous vais mettre le message si qlq a une idee svp.

System.ArgumentOutOfRangeException: L'index et la longueur doivent faire référence à un emplacement situé dans la chaîne. Nom du paramètre : length à System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) à System.String.Substring(Int32 startIndex, Int32 length) à PoMailPh.frmPrinc.fct_send_mail(String m_from, String m_to, String m_subject, Int32 m_type, String m_msg, String f_name) à PoMailPh.frmPrinc.fct_fill_excel(String[] lines, String sqltype) à PoMailPh.frmPrinc.procVerifFichier()

merci bcp pour votre aide.

4 réponses

Supra3000 Messages postés 159 Date d'inscription lundi 18 février 2008 Statut Membre Dernière intervention 8 janvier 2010 2
23 janv. 2009 à 19:40
Peux-tu nous donner le code de ta fonction "procVerifFichier" dans "frmPrinc"..

L'erreur se produit à cet endroit, il serait également bien que tu roules cette fonction avec des breakpoints pour identifier la ligne critique

Bonne continuation
0
kovalev24 Messages postés 6 Date d'inscription mardi 17 mars 2009 Statut Membre Dernière intervention 17 mars 2009
23 janv. 2009 à 19:49
voila ma focntion:



Private






Sub
procVerifFichier()


Dim
i

As



Integer

Dim
sFiles()

As



String

Dim
FreeF

As



Integer

Dim
str()

As



String

Dim
tmp()

As



String

Do

Try

'System.Threading.Thread.Sleep(5000)

If



Not
File.Exists(f_in &

"\pomail.lock"
)

Then

'pour avoir les noms des fichiers et des sous-répertoires

sFiles = Directory.GetFiles(f_in)


For
i = 0

To
sFiles.GetUpperBound(0)


If
InStr(sFiles(i),

".txt"
) > 0

Then

FreeF = FreeFile()

'Possibilité de mettre 1************

FileOpen(FreeF, sFiles(i), OpenMode.Input)

'Ouverture du fichier créé**********

str = Split(InputString(FreeF, FileLen(sFiles(i))), Chr(10))

'Séparation des lignes du fichier***

FileClose(FreeF)
File.Delete(archive & sFiles(i).Substring(27, sFiles(i).Length - 27))
File.Move(sFiles(i), archive & sFiles(i).Substring(27, sFiles(i).Length - 27))


With
txtwatch
.SelectionStart = Len(txtwatch.Text)
.SelectionProtected =

False

.SelectionStart = Len(txtwatch.Text) + 1
.SelectionColor = System.Drawing.Color.Red
SelectedText =

"Fichier créé : "
& Replace(sFiles(i), f_in,

""
) &

" "
&

Date
.Now & vbCrLf
.SelectionProtected =

True

.Focus()
.SelectionStart = txtwatch.Text.Length
.ScrollToCaret()


End



With

tmp = Split(Replace(Replace(str(0), Chr(34),

""
),

"'"
,

" "
),

";"
)


If
tmp(2).ToUpper =

"V"



Then

fct_fill_sql(str, sFiles(i).Substring(27, 2).ToUpper)
fct_fill_excel(str, sFiles(i).Substring(27, 2).ToUpper)


End



If

End



If

If
File.Exists(f_in &

"\pomail.lock"
)

Then



Exit



For

Next

End



If

Catch
ex

As
Exception
fct_send_mail(envoyeur, warning,

"ERREUR PO VIA MAIL "
& Replace(sFiles(i), f_in,

""
), 0, ex.ToString,

"none"
)


fct_exec_sql(

"UPDATE pur_order SET err=1 WHERE pur_order.po_number='0'"
)


End



Try

Exit



Do

Loop

End



Sub

Merci pour ton aide
0
Supra3000 Messages postés 159 Date d'inscription lundi 18 février 2008 Statut Membre Dernière intervention 8 janvier 2010 2
23 janv. 2009 à 20:02
En remontant on peux voir que ta fonction : "fct_fill_excel" qui appelle la fonction "fct_send_mail"..

"à System.String.Substring(Int32 startIndex, Int32 length) à PoMailPh.frmPrinc.fct_send_mail"

Donc ta fonction Substring a une erreur de logique, je crois que cette fonction essai de récupérer une valeur trop grande par rapport au string envoyer, d'ou l'erreur :Nom du paramètre :
"length à System.String.InternalSubStringWithChecks"

Exemple: tu essaie de faire un "sFiles(i).Substring(27, 2).ToUpper"
sur une String trop courte.

Il faudra que tu testes pour résoudre le problème

Bonne continuation 
0
kovalev24 Messages postés 6 Date d'inscription mardi 17 mars 2009 Statut Membre Dernière intervention 17 mars 2009
23 janv. 2009 à 20:07
merci beaucoup,


je vais essayer de le resoudre et bonne continuationn a toi aussi.
0
Rejoignez-nous