Code marche pas

Résolu
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011 - 28 juin 2009 à 16:01
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011 - 29 juin 2009 à 19:36
Hello,
je dois trouver dans cette page avec la fonction INSTR : http://www.pmu.fr/pmu/servlet/pmu.web.servlet.www.infos.ListeToutesCotes?dd=28062009

Une course egal a 14 partants ou superieur maxi (19)
une cote de 1,6 ou inferieur

J'ai fait un truc comme ca mais bon ca ne marche pas !

posTxt2 = InStr(pos1 + 1, Text1.Text, "14 partants") Xor InStr(pos1 + 1, Text1.Text, "15 partants") Xor InStr(pos1 + 1, Text1.Text, "16 partants") Or InStr(pos1 + 1, Text1.Text, "17 partants") Or InStr(pos1 + 1, Text1.Text, "18 partants") Or InStr(pos1 + 1, Text1.Text, "19 partants")
posTxt3 InStr(pos1 + 1, Text1.Text, "1,6") Xor posTxt1 InStr(pos1 + 1, Text1.Text, "2,3") Xor posTxt1 = InStr(pos1 + 1, Text1.Text, "1,4") Or posTxt1 = InStr(pos1 + 1, Text1.Text, "1,4") Or posTxt1 = InStr(pos1 + 1, Text1.Text, "1,3") Or posTxt1 = InStr(pos1 + 1, Text1.Text, "1,2") Or posTxt1 = InStr(pos1 + 1, Text1.Text, "1,1")


If (posTxt2 And posTxt3 > pos1) And (posTxt2 And posTxt3 < pos2) Then MsgBox "bidul bien trouvé dans la partie voulue, à la position " & CStr(posTxt1)

Merci de votre aide

8 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
29 juin 2009 à 13:45
Dans mon textbox1 j'ai ceci :

posTxt2 = InStr(pos1 + 1, Text11 .Text, ....
posTxt2 = InStr(pos1 + 1, Text1.Text, ...




If InStr(1, Text11.Text, ...





faudrait peut-être commencer par savoir dans quelle box tu effectues ta recherche, non?....



faire en sorte que si TEXTBOX1 contient
"16 partants" ou "15 partants" ET "1,5" ou "1,4" = beep par exemple




pour çà il faut utiliser des parenthèses !!

1ère étape : faire du code clair
tu fais des INSTR depuis 1 dans une même zone.
fais toi une fonction plus lisible

private function Exists(byval sStr as string) as boolean


Exists = (instr(1, text1.text, sstr)>0)
end function





ensuite le test :
16 OU 15
ET
1.5

OU


1.4






If (exists(" 14 partants ") Or exists(" 15 partants ")) _
   And _
   (exists(" 1,4 ") Or exists(" 1,5 ")) Then
  beep
End If







on s'y retrouve mieux non?





<hr size="2" width="100%" />
3
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
28 juin 2009 à 16:15
Je reponds a mon post:
j'avait donc fait n'importe quoi etcette fois ci ca marche:

posTxt2 = InStr(pos1 + 1, Text11.Text, "14 partants") Or InStr(pos1 + 1, Text11.Text, "15 partants") Or InStr(pos1 + 1, Text11.Text, "16 partants") Or InStr(pos1 + 1, Text11.Text, "17 partants") Or InStr(pos1 + 1, Text11.Text, "18 partants") Or InStr(pos1 + 1, Text11.Text, "19 partants") Or InStr(pos1 + 1, Text11.Text, "20 partants")
posTxt3 = InStr(pos1 + 1, Text11.Text, "1,6") Or InStr(pos1 + 1, Text11.Text, "1,5") Or InStr(pos1 + 1, Text11.Text, "1,4") Or InStr(pos1 + 1, Text11.Text, "1,3") Or InStr(pos1 + 1, Text11.Text, "1,2") Or InStr(pos1 + 1, Text11.Text, "1,21")
If (posTxt2 And posTxt3 > pos1) And (posTxt2 And posTxt3 < pos2) Then MsgBox "bidul bien trouvé dans la partie voulue, à la position " & CStr(posTxt1)

J'imagine que l'on peut faire plus simple, mais bon je debute !!
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
28 juin 2009 à 16:43
NON !!

tu fais des "opérations logiques"

pos = pos1 or pos2 ne va que te donner une valeur TRUE ou FALSE

si çà marche, c'est pas pur hasard !!!

utilises plutôt directement cette fonction, sur des tronçons choisis :



<hr />
'    RÉCUPÉRER UNE CHAÎNE (INCONNUE) PLACÉE ENTRE DEUX CHAÎNES
(CONNUES)
'    http://www.codyx.org/snippet_recuperer-chaine-inconnue-placee-entre-deux-chaines-connues_334.aspx#1043
'    Posté par [ PCPT ] le 04/03/2007
<hr />




Private Function 
MyMid(
ByRef 
Expression 
As String
, sLeft
As String
, sRight
As String
,
Optional
Start
As Long
=
1
)
As
String

    Dim lPosL As Long, lPosR As Long
    lPosL = InStr(Start, Expression, sLeft): lPosR = InStr(lPosL + 1, Expression,
sRight)
    If lPosL > 0 And lPosR > 0 Then
        MyMid = Mid$(Expression, lPosL + Len(sLeft), lPosR - lPosL - Len(sLeft))
    Else
        MyMid = vbNullString
    End If
End Function
'EXEMPLE  D'UTILISATION
Private Sub Form_Load()
    Dim sStr As String
    MsgBox MyMid("
machin
", "'>", "</")
    Unload Me
End Sub
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
29 juin 2009 à 13:21
Bon je ne comprend pas comment faire
Dans mon textbox1 j'ai ceci :

Course 2 : PX reg h normandie - 14H25, 16 partants N° 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Cotes 50 19 13 6,9 24 29 7,1 19 10 11 21 12 9,2 7,8 32 45
Relevées à 12:41

Et je ne sais pas comment programmer pour faire en sorte que si TEXTBOX1 contient
"16 partants" ou "15 partants" ET "1,5" ou "1,4" = beep par exemple


j'ai essayé ceci mais sans succes, il beep parceque 14 partants existe seulement
meme si 1,4 ou 1,5 est absent.
Dans le sens inverse ca marche pas, il ne beep pas si 1,4 existe :

If InStr(1, Text11.Text, (" 14 partants ")) Or InStr(1, Text11.Text, (" 15 partants ")) And InStr(1, Text11.Text, (" 1,4 ")) Or InStr(1, Text11.Text, (" 1,5 ")) Then
beep
End If

Merci de votre aide
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
29 juin 2009 à 13:55
Effectivement !!
C'est du travail de pro et en plus ça marche impec !! merci beaucoup monsieur l'admi
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
29 juin 2009 à 16:17
M'sieur PCPT si je peux faire appel une fois de plus a votre savoir.
Voila grace a toi une partie de mon code qui fonctionne trés bien :

y = InStr(1, gg, "Réunion 1")
Z = InStr(1, gg, "Météo :")
Form1.Label4.Caption = Mid(gg, y, Z - (y))
S = InStr(1, gg, "Course 1 :") 'on chope l'emplacement de ça
P = InStr(1, gg, "Course 2 :") 'on chope l'emplacement de ça
If P False Then P InStr(i + 1, gg, "Réunion 2")
Form1.Text11.Text = Mid(gg, S, P - (S + 5))


Comme tu peux le voir sur cette page : http://www.pmu.fr/pmu/servlet/pmu.web.servlet.www.infos.ListeToutesCotes?dd=29062009

Il existe plusieur REUNION et donc pour la capture de la 1 ER tous va bien mais dés que l'on passe a la réunion 2 ca ne passe plus.
Aurais tu une idée ?
Merci d'avance
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
29 juin 2009 à 16:42
tu cherches i+1
i vaut zéro, donc tu cherches toujours depuis le même emplacement

au moins 6e fois que je te le dis : instr renvoie la position. utilise là

cf tes autres topics !
0
marty14 Messages postés 104 Date d'inscription lundi 21 août 2006 Statut Membre Dernière intervention 29 mai 2011
29 juin 2009 à 19:36
Oui j'ai enfin compris, merci de ta patience :)
0
Rejoignez-nous