Visual Basic .NET : erreur inattendue !!

Résolu
allthew3 Messages postés 551 Date d'inscription samedi 8 janvier 2005 Statut Membre Dernière intervention 12 avril 2008 - 29 août 2005 à 16:41
allthew3 Messages postés 551 Date d'inscription samedi 8 janvier 2005 Statut Membre Dernière intervention 12 avril 2008 - 30 août 2005 à 10:10
Bonjour à tous,

je voudrais faire un prog qui recherche dans tous les fichiers TXT du répertoire c:\WINDOWS\wormskiller\temp les mots delete, del, erase, remove, format et qui, s'il les trouvent, envoit une fenetre Windows, sinon, il envoit une autre fenetre windows (voir la source ci-dessous) : aidez-moi SVP !!!!

ma source :

imports Microsoft.VisualBasic
imports System
imports System.Collections
imports System.IO
imports System.ComponentModel
imports System.Drawing
imports System.Windows.Forms


' initialisation des fenetres windows
public class rien : inherits System.Windows.Forms.Form
public sub new()
Me.Text = "Rien"
' bien sur je finirais la fenetre ...
end sub
end class


public class detecte : inherits System.Windows.Forms.Form
public sub new()
Me.Text = "Detecte !"
' la aussi je finirais la fenetre ...
end sub
end class


' module de recherche
public module MyModule

' recherche
function recherche() as integer
' ouvrir les fichiers TXT du dossier suivant
Dim sr as new StreamReader("C:\WINDOWS\wormskiller\temp\*.txt")
' ouvrir
sr.Read()
Dim FichierScan as new Hashtable(sr.ReadToEnd)
' si les fichiers contiennent les mots ... renvoyer ...
if FichierScan.ContainsValue("delete") then return 1
if FichierScan.ContainsValue("del") then return 2
if FichierScan.ContainsValue("remove") then return 3
if FichierScan.ContainsValue("erase") then return 4
if FichierScan.ContainsValue("format") then return 5
' fermer
sr.Close()
end function


' retour
sub Main
' si la fonction recherche = 0 alors lancé la fenetre Windows "Rien"
if recherche = 0 then
Application.Run(new rien())
else
' sinon lancé la fenetre "détecté !"
Application.Run(new detecte())
end if
end sub


end module

3 réponses

cs_69chris Messages postés 318 Date d'inscription jeudi 30 janvier 2003 Statut Membre Dernière intervention 30 décembre 2005 1
29 août 2005 à 17:20
Salut,

A la place de

Dim sr as new StreamReader("C:\WINDOWS\wormskiller\temp\*.txt")

tu pourrais faire un truc du genre

For Each strFichier As String In Directory.GetFiles("C:\WINDOWS\wormskiller\temp", "*.txt")

Dim sr as new StreamReader(strFichier)

......

sr.Close()

Next





Chris


N'oubliez pas de cloturer votre post.
3
cs_69chris Messages postés 318 Date d'inscription jeudi 30 janvier 2003 Statut Membre Dernière intervention 30 décembre 2005 1
29 août 2005 à 17:58
Et j'y pense, ajoutes un bloc try/catch dans tes méthodes, ça évite des problèmes et ça permet de localiser les erreurs...

Du genre, "new StreamWriter(<Chemin vers un fichier>)" car ta
synthaxe (si ça marchais) ça donnerais un flux vers un ensemble de
fichiers, un 'ti coup d'oeil à la doc fait pas de mal.


Chris


N'oubliez pas de cloturer votre post.
0
allthew3 Messages postés 551 Date d'inscription samedi 8 janvier 2005 Statut Membre Dernière intervention 12 avril 2008 2
30 août 2005 à 10:10
C bon : problème réglé ! merci

et je suis un débutant, alors ....

à+
0
Rejoignez-nous