Max caractères

Résolu
1217meyrin Messages postés 159 Date d'inscription lundi 5 avril 2004 Statut Membre Dernière intervention 6 février 2007 - 5 janv. 2007 à 09:05
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 - 5 janv. 2007 à 09:43
Bonjour,
j'ai trois textbox, dans les 2 premières, je rentre des chiffres et lorsque j'appuie sur un bouton ok, la moyenne des 2 chiffre s'inscrit dans la 3ème textbox.
question:
comment limiter le nombre de chiffres à 4 dans la 3ème texbox, le maxlenght ne marche pas?

8 réponses

drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
5 janv. 2007 à 09:43
Tu rigoles ou quoi?

' User-defined numeric formats.
' Returns "5,459.40".
TestStr = Format(5459.4, "##,##0.00")
' Returns "334.90".
TestStr = Format(334.9, "###0.00")

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
3
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
5 janv. 2007 à 09:12
Utilise un type décimal et la fonction math.round ou alors voit pour passer par format

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
5 janv. 2007 à 09:15
Salut au fait,
Sinon c'est normal que maxlenght ne fonctionne pas cela définit seulement le nombre maxi de caractère que utilisateur peut saisir mais dans ce cas c'est toi par le code qui affiche cette valeur donc cela peut être supérieur à 4! (voila pour la partie explication)

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
1217meyrin Messages postés 159 Date d'inscription lundi 5 avril 2004 Statut Membre Dernière intervention 6 février 2007
5 janv. 2007 à 09:21
comment faire avec format a-tu un exemple?
0

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

Posez votre question
malhivertman1 Messages postés 489 Date d'inscription mardi 16 novembre 2004 Statut Membre Dernière intervention 22 novembre 2007 1
5 janv. 2007 à 09:27
Si tu fais
Format(tonchiffre, "####")

ca marche?
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
5 janv. 2007 à 09:34
Et F1 me donna la réponse!

Returns a string formatted according to instructions contained in a format String expression.







|

----

Public Shared Function Format( _
ByVal Expression As Object, _
Optional ByVal Style As String = "" _
) As String









Parameters

* : Expression

Required. Any valid expression.

* : Style

Optional. A valid named or user-defined format String expression.



Settings




For information on how to create the Style argument, see the appropriate topic listed below:










To format |
Do this |

----

Numbers,
Use predefined numeric formats or create user-defined numeric formats.,

----

Dates and times,
Use predefined date/time formats or create user-defined date/time formats.,

----

Date and time serial numbers,
Use date and time formats or numeric formats.



If you try to format a number without specifying Style, the Format function provides functionality similar to the Str function, although it is internationally aware. However, positive numbers formatted as strings using the Format function don't include a leading space reserved for the sign of the value; those converted using the Str function retain the leading space.






Remarks




If you are formatting a nonlocalized numeric string, you should use a user-defined numeric format to ensure that you get the look you want.


The <?XML:NAMESPACE PREFIX MSHelp NS "http://msdn.microsoft.com/mshelp" /??><mshelp:link tabindex="0" keywords="Overload:System.String.Format">System.String.Format</mshelp:link> method also provides similar functionality.






Example




<description xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
This example shows various uses of the Format function to format values using both String formats and user-defined formats. For the date separator (/), time separator (:), and the AM/PM indicators (t and tt), the actual formatted output displayed by your system depends on the locale settings the code is using. When times and dates are displayed in the development environment, the short time format and short date format of the code locale are used.




Note |

----

For locales that use a 24-hour clock, the AM/PM indicators (t and tt) display nothing.



</description>



Visual Basic  |

Copy Code
|

----

Dim TestDateTime As Date = #1/27/2001 5:04:23 PM#
Dim TestStr As String
' Returns current system time in the system-defined long time format.
TestStr = Format(Now(), "Long Time")
' Returns current system date in the system-defined long date format.
TestStr = Format(Now(), "Long Date")
' Also returns current system date in the system-defined long date
' format, using the single letter code for the format.
TestStr = Format(Now(), "D")

' Returns the value of TestDateTime in user-defined date/time formats.
' Returns "5:4:23".
TestStr = Format(TestDateTime, "h:m:s")
' Returns "05:04:23 PM".
TestStr = Format(TestDateTime, "hh:mm:ss tt")
' Returns "Saturday, Jan 27 2001".
TestStr = Format(TestDateTime, "dddd, MMM d yyyy")
' Returns "17:04:23".
TestStr = Format(TestDateTime, "HH:mm:ss")
' Returns "23".
TestStr = Format(23)

' User-defined numeric formats.
' Returns "5,459.40".
TestStr = Format(5459.4, "##,##0.00")
' Returns "334.90".
TestStr = Format(334.9, "###0.00")
' Returns "500.00%".
TestStr = Format(5, "0.00%")






 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
5 janv. 2007 à 09:34
Ce qui sur différente ligne donne:

Dim TestDateTime As Date = #1/27/2001 5:04:23 PM#
Dim TestStr As String
' Returns current system time in the system-defined long time format.
TestStr = Format(Now(), "Long Time")
' Returns current system date in the system-defined long date format.
TestStr = Format(Now(), "Long Date")
' Also returns current system date in the system-defined long date
' format, using the single letter code for the format.
TestStr = Format(Now(), "D")


' Returns the value of TestDateTime in user-defined date/time formats.
' Returns "5:4:23".
TestStr = Format(TestDateTime, "h:m:s")
' Returns "05:04:23 PM".
TestStr = Format(TestDateTime, "hh:mm:ss tt")
' Returns "Saturday, Jan 27 2001".
TestStr = Format(TestDateTime, "dddd, MMM d yyyy")
' Returns "17:04:23".
TestStr = Format(TestDateTime, "HH:mm:ss")
' Returns "23".
TestStr = Format(23)


' User-defined numeric formats.
' Returns "5,459.40".
TestStr = Format(5459.4, "##,##0.00")
' Returns "334.90".
TestStr = Format(334.9, "###0.00")
' Returns "500.00%".
TestStr = Format(5, "0.00%")

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
1217meyrin Messages postés 159 Date d'inscription lundi 5 avril 2004 Statut Membre Dernière intervention 6 février 2007
5 janv. 2007 à 09:40
je doit formater cette expression:
mp2.Text = (Val(pr1_2.Text) * Val(coefficient1.Text) + Val(pr2_2.Text) * Val(coefficient2.Text)) / b
0
Rejoignez-nous