Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1564 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [vb] Probleme de test de chaine

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[vb] Probleme de test de chaine

n°308198
sbucci2
Posté le 13-02-2003 à 11:24:54  profilanswer
 

j ai ce code :
 
je met rien dans txtref dans le formulaire
 
If TxtRef = Null Then
MsgBox "probleme"
Exit Sub
End If
 
pkoi il ne rentre pas le if  :??:  
 
merci


Message édité par sbucci2 le 13-02-2003 à 11:32:34
mood
Publicité
Posté le 13-02-2003 à 11:24:54  profilanswer
 

n°308208
MagicBuzz
Posté le 13-02-2003 à 11:36:32  profilanswer
 

Code :
  1. Option Explicit
  2. Private Sub Command1_Click()
  3.     Dim toto As String * 12  ' toto est rempli avec 12 caractères vbNullChar
  4.    
  5.     MsgBox (Len(toto))
  6.    
  7.     If toto = vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar & vbNullChar Then
  8.         MsgBox ("toto contient 12 vbNullChar" )
  9.     End If
  10.    
  11.     toto = String(12, " " ) ' C'est plus pratique de bosser avec des espaces " "
  12.    
  13.     If Trim(toto) = "" Then
  14.         MsgBox ("toto ne contient pas de caractère visibles" )
  15.     End If
  16.    
  17.     If Len(Trim(toto)) = 0 Then
  18.         MsgBox ("toto ne contient que des caractères invisibles" )
  19.     End If
  20. End Sub

n°308210
MagicBuzz
Posté le 13-02-2003 à 11:37:23  profilanswer
 

Euh, remet ton ancienne question, on pouvait y répondre, là y'a plus les éléments nécessaires ;)

n°308212
drasche
Posté le 13-02-2003 à 11:38:45  profilanswer
 

oubliez les déclarations As String * 10
 
Les chaînes de taille fixe ne seront plus supportées par les versions suivantes de VB.
 
Le problème est tout bête.  La propriété Text de ton TextBox est de type String et Null ne l'est pas.  Ils ne peuvent donc être comparés.  Ton Text doit être comparé à "" ou à vbNullString qui veut en fait dire "" également.
 
Le Null ne peut être utilisé que sur des variables de type Variant.


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°308215
mareek
Et de 3 \o/
Posté le 13-02-2003 à 11:41:07  profilanswer
 

sbucci2 a écrit :

j ai ce code :
 
je met rien dans txtref dans le formulaire
 
If TxtRef = Null Then
MsgBox "probleme"
Exit Sub
End If
 
pkoi il ne rentre pas le if  :??:  
 
merci

une string ne peut pas prendre la valeur Null, cette valeur est réservée au variables de type Variant.
 
si tu veux tester si ta chaine est vide, essaye le code suivant:

Code :
  1. If TxtRef = vbNullString Then
  2.     MsgBox "probleme"
  3.     Exit Sub
  4. End If


---------------
"I wonder if the internal negative pressure in self pumping toothpaste tubes is adjusted for different market altitudes." John Carmack
n°308216
drasche
Posté le 13-02-2003 à 11:42:46  profilanswer
 

MagicBuzz a écrit :

Euh, remet ton ancienne question, on pouvait y répondre, là y'a plus les éléments nécessaires ;)


 
au contraire il est limpide son problème :??:


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°308219
MagicBuzz
Posté le 13-02-2003 à 11:45:29  profilanswer
 

Tout à l'heure, il avait écrit un truc en C, et demandait comment le transcrire en VB. Ce que j'ai pondu (j'ai oublié le vbNullString) correspond à son code, là on se demande pourquoi je part d'une chaîne de longueur fixe.
 
 
Sinon, les chaînes de longueur fixe sont très pratique pour lire/écrire dans des fichiers plats à l'autre d'un masque (struct) je trouve ça très mal de ne plus les supporter.

n°308221
sbucci2
Posté le 13-02-2003 à 11:48:23  profilanswer
 

Citation :

If TxtRef = vbNullString Then
   MsgBox "probleme"
   Exit Sub
End If  


 
Ca marche pas non plus   :??:  :??:  
 
données du prob
http://sbucci2.free.fr/f.gif
 
Private Sub Lance_recherche()
Dim Mabase As Database
Dim Monrs As DAO.Recordset
Dim I As Long
'Dim TxtSearch As String
Dim Query As String
 
Set Mabase = CurrentDb
 
If TxtRef = vbNull Then
MsgBox "Saisissez une réference"
Exit Sub
End If
 
Query = "select * from reference where ref like '" & TxtRef & "*'"
I = 0
' TxtSearch = TxtRef
Set Monrs = Mabase.OpenRecordset(Query)
'Monrs.MoveFirst
List14.RowSource = "select * from reference where ref like '" & TxtRef & "*'"
'List9.ColumnCount = 2
 
'While Not Monrs.EOF
'    DoEvents
 
    'list9.ItemData(0)=
'    List14.Value = Monrs.Fields("id_reference" )
'    List14.Value = Monrs.Fields("ref" )
'    I = I + 1
'    List14.ItemData(0) = I
'    Monrs.MoveNext
'Wend
Monrs.Close
 
End Sub
 
 
 

n°308224
MagicBuzz
Posté le 13-02-2003 à 11:50:10  profilanswer
 

essaie
 
trim(txtref) = ""


Message édité par MagicBuzz le 13-02-2003 à 11:50:25
n°308231
sbucci2
Posté le 13-02-2003 à 11:55:04  profilanswer
 

marche pas,
ca me saoule :fou:

mood
Publicité
Posté le 13-02-2003 à 11:55:04  profilanswer
 

n°308232
mareek
Et de 3 \o/
Posté le 13-02-2003 à 11:55:39  profilanswer
 

sbucci2 a écrit :

Citation :

If TxtRef = vbNullString Then
   MsgBox "probleme"
   Exit Sub
End If  


 
Ca marche pas non plus   :??:  :??:  
 
données du prob
http://sbucci2.free.fr/f.gif
 
Private Sub Lance_recherche()
Dim Mabase As Database
Dim Monrs As DAO.Recordset
Dim I As Long
'Dim TxtSearch As String
Dim Query As String
 
Set Mabase = CurrentDb
 
If TxtRef = vbNull Then
MsgBox "Saisissez une réference"
Exit Sub
End If
 
Query = "select * from reference where ref like '" & TxtRef & "*'"
I = 0
' TxtSearch = TxtRef
Set Monrs = Mabase.OpenRecordset(Query)
'Monrs.MoveFirst
List14.RowSource = "select * from reference where ref like '" & TxtRef & "*'"
'List9.ColumnCount = 2
 
'While Not Monrs.EOF
'    DoEvents
 
    'list9.ItemData(0)=
'    List14.Value = Monrs.Fields("id_reference" )
'    List14.Value = Monrs.Fields("ref" )
'    I = I + 1
'    List14.ItemData(0) = I
'    Monrs.MoveNext
'Wend
Monrs.Close
 
End Sub
 
 
 
 

pour avoir la chaine de caractère du texte de la "zone de texte" TxtRef tu dois faire TxtRef.Text
 

Code :
  1. If TxtRef.Text = vbNullString Then
  2.    MsgBox "probleme"
  3.    Exit Sub
  4. End If



---------------
"I wonder if the internal negative pressure in self pumping toothpaste tubes is adjusted for different market altitudes." John Carmack
n°308234
drasche
Posté le 13-02-2003 à 11:56:28  profilanswer
 

bon, que contient ton txtref exactement au moment du test?


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°308240
MagicBuzz
Posté le 13-02-2003 à 12:01:54  profilanswer
 

Au fait...
 
txtRef est un champ, pas une chaîne :sarcastic:
 
La chaîne c'est txtRef.text :sarcastic:
 
-- oups, désolé mareek, j'avais pas vu ton post :D --


Message édité par MagicBuzz le 13-02-2003 à 12:02:43
n°308241
sbucci2
Posté le 13-02-2003 à 12:02:04  profilanswer
 

http://sbucci2.free.fr/g.gif


Message édité par sbucci2 le 13-02-2003 à 12:02:17
n°308247
sbucci2
Posté le 13-02-2003 à 12:07:11  profilanswer
 

Citation :

If TxtRef.Text = vbNullString Then
  MsgBox "probleme"
  Exit Sub
End If  
 


 
=>
http://sbucci2.free.fr/h.gif

n°308248
MagicBuzz
Posté le 13-02-2003 à 12:09:28  profilanswer
 

Euh...
 
Poste tout ton code, parceque j'ai l'impression que c'est un joyeux bordel...

n°308250
sbucci2
Posté le 13-02-2003 à 12:10:59  profilanswer
 

Option Compare Database
 
Private Sub Command11_Click()
    Lance_recherche
End Sub
 
Private Sub Command16_Click()
    '    Dim Mabase As Database
    'mabase.Execute(query)
End Sub
 
Private Sub Command4_Click()
    Dim Mabase As Database
    Dim Monrs As DAO.Recordset
     
    Dim Query As String
 
    Set Mabase = CurrentDb
    Query = "Select * from lien, centre where lien.id_centre = centre.id_centre and " & _
                 "lien.id_pays=" & Combo0.ItemData(Combo0.ListIndex) & " and lien.id_reference = '" & List14.ItemData(List14.ListIndex) & "'"
     
    Set Monrs = Mabase.OpenRecordset(Query)
    If Monrs.EOF Then
        Text7 = ""
        MsgBox "Pas de centre associé"
        Exit Sub
    End If
    Monrs.MoveFirst
     
    'while not monrs.EOF then
    '   text...
    '   monrs.MoveNext
    'wend
    If Not Monrs.EOF Then
        Text7 = Monrs.Fields("Adresse" )
    End If
     
    Monrs.Close
End Sub
 
Private Sub TxtRef_KeyPress(KeyAscii As Integer)
   
    If KeyAscii = 13 Then
        Lance_recherche
     
    End If
End Sub
 
Private Sub Lance_recherche()
Dim Mabase As Database
Dim Monrs As DAO.Recordset
Dim I As Long
'Dim TxtSearch As String
Dim Query As String
 
Set Mabase = CurrentDb
 
    If TxtRef.Text = vbNullString Then
MsgBox "Saisissez une réference"
Exit Sub
End If
 
Query = "select * from reference where ref like '" & TxtRef & "*'"
I = 0
' TxtSearch = TxtRef
Set Monrs = Mabase.OpenRecordset(Query)
'Monrs.MoveFirst
List14.RowSource = "select * from reference where ref like '" & TxtRef & "*'"
'List9.ColumnCount = 2
 
'While Not Monrs.EOF
'    DoEvents
 
    'list9.ItemData(0)=
'    List14.Value = Monrs.Fields("id_reference" )
'    List14.Value = Monrs.Fields("ref" )
'    I = I + 1
'    List14.ItemData(0) = I
'    Monrs.MoveNext
'Wend
Monrs.Close
 
End Sub
 

n°308296
drasche
Posté le 13-02-2003 à 12:40:00  profilanswer
 

bingo!
 
tu dois alors faire IsNull(txtref) qui renverra True ou False suivant son état :D


---------------
Whichever format the fan may want to listen is fine with us – vinyl, wax cylinders, shellac, 8-track, iPod, cloud storage, cranial implants – just as long as it’s loud and rockin' (Billy Gibbons, ZZ Top)
n°308301
sbucci2
Posté le 13-02-2003 à 12:45:43  profilanswer
 

ca marche
 
bravo au gagnant  :jap:  :jap:  
 
et encore merci pour votre coup de main :jap:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  [vb] Probleme de test de chaine

 

Sujets relatifs
[.NET] Enumérations (problème résolu)Probleme popup
[SQL] problème avec des INValidateur W3C + Probleme lors de son installation
Probleme dimmensionnement celluleProblème d'importation de classe d'une DLL
[DOS] Remplacer une chaine de caractereproblème dans easyphp 1.6
[Javascript] Petit problème de redirection { résolu }[Apache / PHP] Problème de transmission de variable avec mod_rewrite
Plus de sujets relatifs à : [vb] Probleme de test de chaine


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR