Code en boucle

marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011 - 30 juin 2009 à 04:13
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011 - 1 juil. 2009 à 15:08
Bonjour,
Est il possible de faire tourner ce code 10 fois d'affiler
tout en changeant le nombre de course d'inscrit
EX premiere execution scourse 1 Pcourse 2
EX deuxieme execution scourse 2 Pcourse 3




S = InStr(1502, gg, "Course 6 :")
P = InStr(1620, gg, "Course 7 :")
If P False Then P InStr(i + 1, gg, "Réunion 2")
Form1.Text11.Text = Mid(gg, S, P - (S + 5))


If InStr(1, Form1.Text11.Text, (" 1,1 ")) Then MsgBox "bravo"
If (Exists(" 14 partants ") Or Exists(" 15 partants ") Or Exists(" 16 partants ") Or Exists(" 17 partants ") Or Exists(" 18 partants ") Or Exists(" 19 partants ") Or Exists(" 20 partants ")) _
And _
(Exists(" 1,6 ") Or Exists(" 1,5 ") Or Exists(" 1,4 ") Or Exists(" 1,3 ") Or Exists(" 1,2 ") Or Exists(" 1,1 ")) Then
MsgBox "bravo"
Beep
End If

par avance merci.

29 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
30 juin 2009 à 09:06
ton code est là pour faire apparaitre des Msgbox...
tu veux faire tourner la chose en boucle, qu'elle toutes ces MsgBox (et ces affreux Beep) ?


quelle est cette fonction Exists ?
Exists(" 1,1 ")


Pour ta boucle, une simple boucle For suffit:

For i = 1 to 10
...
Next i
0
bigfish_le vrai Messages postés 1835 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 20 novembre 2013 15
30 juin 2009 à 09:08
Salut,

Dim i As Long

For i=1 to 10 Step 2
S = InStr(1502, gg, "Course " & i & " :")

P = InStr(1620, gg, "Course " & i+1 & " :")
If P False Then P InStr(i + 1, gg, "Réunion 2")

Form1.Text11.Text = Mid(gg, S, P - (S + 5))

If InStr(1, Form1.Text11.Text, (" 1,1 ")) Then MsgBox "bravo"

If (Exists(" 14 partants ") Or Exists(" 15 partants ") Or Exists("
16 partants ") Or Exists(" 17 partants ") Or Exists(" 18 partants ") Or
Exists(" 19 partants ") Or Exists(" 20 partants ")) _

   And _

   (Exists(" 1,6 ") Or Exists(" 1,5 ") Or Exists(" 1,4 ") Or Exists(" 1,3 ") Or Exists(" 1,2 ") Or Exists(" 1,1 ")) Then

  MsgBox "bravo"

  Beep

  End If

Next i

A+
0
bigfish_le vrai Messages postés 1835 Date d'inscription vendredi 13 mai 2005 Statut Membre Dernière intervention 20 novembre 2013 15
30 juin 2009 à 09:09
Oups... Poste croisé
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
30 juin 2009 à 10:35
salut,

comme tu peux le voir je ne suis pas le seul lecteur marty14....
expose clairement le sujet et met le code intégrale concernant le problème

renfield -> exists n'est qu'un allégé de instr, juste pour simplifier la lecture et comprendre le OR et AND :
http://www.vbfrance.com/forum/sujet-CODE-MARCHE-PAS_1331745.aspx


<hr size="2" width="100%" />
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 08:34
Bonjour tout le monde et Merciiiii énormément pour votre aide.

Je vous explique mon projet avec mon code clairement :



1 - acceder a la page


WebBrowser1.Navigate ("http://www.pmu.fr/pmu/servlet/pmu.web.servlet.www.infos.ListeToutesCotes?dd=29062009")


2 - scanner toutes les courses existante sur cette page et les afficher dans un textBox


For i = 1 To 10 Step 2
S = InStr(1, gg, "Réunion 1")
S = InStr(S, gg, "Course " & i & " :")

If S Then
Beep
P = InStr(S + 1, gg, "Course " & i + 1 & " :")
If P False Then P InStr(i + 1, gg, "Réunion 2")
Text11.Text = Mid(gg, S, P - (S + 5))

End If

If InStr(1, Text11.Text, (" 1,1 ")) Then MsgBox "bravo"
If (Exists(" 14 partants ") Or Exists(" 15 partants ") Or Exists(" 16 partants ") Or Exists(" 17 partants ") Or Exists(" 18 partants ") Or Exists(" 19 partants ") Or Exists(" 20 partants ")) _
And _
(Exists(" 1,6 ") Or Exists(" 1,5 ") Or Exists(" 1,4 ") Or Exists(" 1,3 ") Or Exists(" 1,2 ") Or Exists(" 1,1 ")) Then
MsgBox "bravo"
Beep
End If
Next i


Pour le moment les actions BEEP ET MSGBOX sont volontaire en attendant de veritable action, j'ai testé le code que vous m'avez fournis mais il ne fonctionne pas, il m'affiche tous le contenus de la page web dans mon textbox.

S = InStr(1502, gg, "Course " & i & " :")
P = InStr(1620, gg, "Course " & i+1 & " :")


alors que normalement c'est course par course, S InStr(1502, gg, "Course 1") et P InStr(1620, gg, "Course 2") fonctionne trés bien mais j'ai besoin d'exectuter mon code 10 fois tout en changeant le numero des course automatiquement.


Pour peaufiner j'aimerais utiliser un progressbar en fonction du nombre d'execution de ce code .


Voila et merci encors
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 juil. 2009 à 08:56
parse la page HTML, pas le texte
les balises sont propres, avec des DIV ID numérotées

çà sera bien plus simple que de jouer comme tu tentes de le faire

exemple d'équivoque possible : il y a deux fois "réunion 4" sur ta page
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 juil. 2009 à 09:08
clair qu'il vaux bien mieux manipuler l'HTML (une RegExp et zou!)

possible surement de jouer directmenent avec le DOM pour analyser la page.

Proxy au boulot, j'ai pas accès au HTML, je peux pas etre plus précis, donc ^^
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 10:15
J'utilise le meme code mais avec une source html cette fois ci! c'est ca ?
A l'okasion pouvez vous me donner un petit exemple accompagné d'un progressbar svp ?
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 juil. 2009 à 10:20
colle ici le code HTML, je te fais une regexp et zou
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 10:56
Tout le code HTML a cet endroit ! bon allons y :
Qu'est ce qu'une REGEXP ???

<style type="text/css" media="screen, projection, print"><![CDATA[
*{
font-family:Arial,Helvetica,sans-serif;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
color:#1C5000;
font-size:12px;
}

table.tableBordure, table.tableBordure tr,table.tableBordure th,table.tableBordure td{
border-color:#E0E0E0;
border-width: 1.2px;
border-style:solid;
}
table.tableBordure td{
width: 25px;
text-align: center;
}
table.tableBordure td.fav{
border-color:#FF0000;
border-width: 2px;
border-style:solid;
}

#navigation #left {
display:block;
width:100%;
background-color:#55BA1F;
color:white;
float: left;

}
#navigation #left div{
display:block;
width:250px;
float: left;
padding-left:5px;
margin-right:70px;
}
#navigation #left div a{
float:left;
font-weight: bold;
color:white;
}
#navigation #left div input{
float: right;
}
#navigation #left span{
text-decoration: underline;
cursor: pointer;
}

h2{
font-weight: 900;
font-size:14px;
}



]]></style><style type="text/css" media="print"><![CDATA[
#navigation{display:none;}
.boutonImpression{visibility:hidden;}
#pageBreak {page-break-after: always}
]]></style><script type="text/javascript" src="http://js.cybermonitor.com/pmufr.js"></script>
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 10:58
Le code n'apparait pas! je te l'envois en Message privé, j'espere que tu le verras!
Merci a toi
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 juil. 2009 à 10:59
volontiers, j'ai pas accès au site du PMU ^^
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 juil. 2009 à 11:10
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 juil. 2009 à 11:16
merci l'ami pour cette piqure de rappel
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 12:19
Merci pcpt pour ce lien trés utils.
Voila renfield tout est la ! j'ai hate de voir ton REGEXP et de comprendre son fonctionnement.



http://tools.codes-sources.com/copy-paste-code.aspx?ID=235
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 juil. 2009 à 12:42
testé avec succès avec le code HTML enregistré en local:






Option Explicit

Private Type Participant
NumID As String
Favori As Boolean
Cote As Single
Partant As Boolean
End Type

Private Type Course
Nom As String
NbParticipants As Long
Participants() As Participant
HeureCourse As Date
HeureReleve As Date
End Type

Private Type Reunion
Nom As String
Temperature As Integer
DirectionVent As String
VitesseVent As Integer
Ciel As String
NbCourses As Long
Courses() As Course
End Type

Private mNbReunions As Long
Private mxtReunions() As Reunion

Private Sub Form_Load()
Dim sBuffer As String
Open "C:\a.html" For Input As 1
sBuffer = Input(LOF(1), 1)
Close #1

LoadPage sBuffer

'# On peu ici jouer avec le tableau mxtReunions, qui contien les infos de notre page
End Sub

Private Sub LoadPage(ByRef vsHTMLContent As String)
Dim oMatch As Object
With CreateObject("VbScript.RegExp")
.Pattern = ">Réunion \d+ : (.+?) *<[\s\S]+?alt=""(.+?)"" /> (\d+).+?, (\d+).+?, (.+?)\r([\s\S]+?)
"
.Global = True
.MultiLine = True
For Each oMatch In .Execute(vsHTMLContent)
ReDim Preserve mxtReunions(mNbReunions)
With mxtReunions(mNbReunions)
.Nom = oMatch.submatches(0)
.Ciel = oMatch.submatches(1)
.Temperature = oMatch.submatches(2)
.VitesseVent = oMatch.submatches(3)
.DirectionVent = oMatch.submatches(4)
End With
LoadCourses oMatch.submatches(5), mxtReunions(mNbReunions)
mNbReunions = mNbReunions + 1
Next oMatch
End With
End Sub

Private Sub LoadCourses(ByRef vsHTMLContent As String, ByRef vtReunion As Reunion)
Dim oMatch As Object
With CreateObject("VbScript.RegExp")
.Pattern = "Course \d+ : (.+?)\r[\s\S]*?(\d+H\d+),[\s\S]*?(<table[\s\S]+?</table>)[\s\S]+?(\d+:\d+)"
.Global = True
.MultiLine = True

For Each oMatch In .Execute(vsHTMLContent)
ReDim Preserve vtReunion.Courses(vtReunion.NbCourses)
With vtReunion.Courses(vtReunion.NbCourses)
.Nom = oMatch.submatches(0)
If IsDate(oMatch.submatches(1)) Then
.HeureCourse = CDate(oMatch.submatches(1))
Else
.HeureCourse = CDate(Replace(oMatch.submatches(1), "H", ":"))
End If
If IsDate(oMatch.submatches(3)) Then
.HeureReleve = CDate(oMatch.submatches(3))
End If
End With
LoadPartipations oMatch.submatches(2), vtReunion.Courses(vtReunion.NbCourses)
vtReunion.NbCourses = vtReunion.NbCourses + 1
Next oMatch
End With
End Sub

Private Sub LoadPartipations(ByRef vsHTMLContent As String, ByRef vtCourse As Course)
Dim oMatches As Object
Dim i As Long
With CreateObject("VbScript.RegExp")
.Pattern = "<td class=""(.*?)"".*?>[\s\S]*?([\w,]+)"
.Global = True
.MultiLine = True

Set oMatches = .Execute(vsHTMLContent)
For i = 0 To oMatches.Count \ 2 - 1
ReDim Preserve vtCourse.Participants(vtCourse.NbParticipants)
vtCourse.Participants(vtCourse.NbParticipants).NumID = oMatches(i).submatches(1)
vtCourse.NbParticipants = vtCourse.NbParticipants + 1
Next i
For i = i To oMatches.Count - 1
With vtCourse.Participants(i - vtCourse.NbParticipants)
.Favori oMatches(i).submatches(0) "fav"
.Partant = oMatches(i).submatches(1) <> "NP"
If IsNumeric(oMatches(i).submatches(1)) Then
.Cote = oMatches(i).submatches(1)
Else
.Cote = Val(oMatches(i).submatches(1))
End If
End With
Next i
End With
End Sub
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 13:27
Tres bien merci beaucoup.
Mais peus tu m"expliquer comment cela fonctionne, je ne sais absolument pas ce qu'est un regexp.
Dois mettre ce code dans un module ?
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 13:33
si jamais tu l'as en tout compiler peux tu me l'envoyer sur mon mail" marty14 arobase figuralbanks.com "
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 13:53
pardon si jamais tu as les sources peux tu me l'envoyer sur mon mail" marty14 arobase figuralbanks.com " .
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
1 juil. 2009 à 14:06
Je vient de créer un nouveau projet et mis tous le code sur la form avec une copie de la page html sur C :

Le programme demare mais ne se passe , j'ai une form vide a l'ecran!


1- Ensuite comment faire pour que ce programme aille chercher la page directement sur une url et non sur un C: ?


2- ou dois je inserer mon code de recherche :


For i = 1 To 10 Step 2
S = InStr(1, gg, "Réunion 2")
S = InStr(S, gg, "Course " & i & " :")


If S Then
Beep
P = InStr(S + 1, gg, "Course " & i + 1 & " :")
If P False Then P InStr(i + 1, gg, "Réunion 3")
Text11.Text = Mid(gg, S, P - (S))


End If


If InStr(1, Text11.Text, (" 1,1 ")) Then MsgBox "bravo"
If (Exists(" 14 partants ") Or Exists(" 15 partants ") Or Exists(" 16 partants ") Or Exists(" 17 partants ") Or Exists(" 18 partants ") Or Exists(" 19 partants ") Or Exists(" 20 partants ")) _
And _
(Exists(" 1,6 ") Or Exists(" 1,5 ") Or Exists(" 1,4 ") Or Exists(" 1,3 ") Or Exists(" 1,2 ") Or Exists(" 1,1 ")) Then
MsgBox "bravo"
Beep
End If
Next i


Je m'excuse de toute ses questions mais j'ai un peu de mal a comprendre.
0
Rejoignez-nous