Inputbox et msgbox

cs_roro69 Messages postés 70 Date d'inscription vendredi 27 décembre 2002 Statut Membre Dernière intervention 29 septembre 2018 - 13 juin 2015 à 22:13
cs_roro69 Messages postés 70 Date d'inscription vendredi 27 décembre 2002 Statut Membre Dernière intervention 29 septembre 2018 - 15 juin 2015 à 14:39
Bonjour et merci de l'aide et du temps accordé
Voici mon problème:
J'ai voudrais que dans mon projet l'utilisateur entre des infos dans des inputbox
Lorsque ces infos ne sont pas celle désiré je voudrais que l'inputbox soit rappellé.
Voici le codes qui ne fonctionnent malheureusement pas.
Si quelqu'un pouvait m'aider se serait sympa

Public Class Form1
Public Const vbNewLine As String = vbCrLf


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mess1, mess2, mess3 As String
Dim titre As String
Dim s, s1, s2 As String
Dim i, j, k As Integer
Dim rep1, rep2, rep3, reponse As Integer
mess1 = "Saisissez le numéro de la première page de votre livre" & vbNewLine & vbNewLine & "Numéro entre 1 et 50"
mess2 = "Saisissez le numéro de la dernière page de votre livre" & vbNewLine & vbNewLine & "Numéro entre 250 et 1000"
mess3 = "Saisissez la hauteur de votre livre" & vbNewLine & vbNewLine & "Hauteur en cm sans décimal entre 20 et 40"
titre = "Patron Livre"
ligne0:
s = InputBox(mess1, titre)

If Not IsNumeric(s) Then reponse = MsgBox("Vous devez tapez un numéro", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne0
Case MsgBoxResult.Cancel
Exit Sub
End Select
If IsNumeric(s) Then i = CType(s, Integer)
If i <> 0 And i < 51 Then
rep1 = i
Else
reponse = MsgBox("Saisissez une page comprise entre 1 et 50", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne0
Case MsgBoxResult.Cancel
Exit Sub
End Select
End If
ligne1:
s1 = InputBox(mess2, titre)
If Not IsNumeric(s) Then reponse = MsgBox("Vous devez tapez un numéro", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne1
Case MsgBoxResult.Cancel
Exit Sub
End Select
If IsNumeric(s1) Then j = CType(s1, Integer)
If j > 200 And j < 1500 Then
rep2 = j
Else
reponse = MsgBox("Saisissez une page comprise entre 200 et 1500", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne1
Case MsgBoxResult.Cancel
Exit Sub
End Select
End If
ligne2:
s2 = InputBox(mess3, titre)

If Not IsNumeric(s2) Then reponse = MsgBox("Vous devez tapez un numéro", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne2
Case MsgBoxResult.Cancel
Exit Sub
End Select
If IsNumeric(s2) Then k = CType(s2, Integer)
If k > 20 And k < 31 Then
rep3 = k
Else
reponse = MsgBox("Saisissez une hauteur non decimal comprise entre 20 et 30", MsgBoxStyle.RetryCancel, vbDefaultButton1)
Select Case reponse
Case MsgBoxResult.Retry
GoTo ligne2
Case MsgBoxResult.Cancel
Exit Sub
End Select
End If
End Sub
End Class



Merci de votre aide et de vos conseils
--
A voir également:

2 réponses

Whismeril Messages postés 19022 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 17 avril 2024 656
13 juin 2015 à 23:43
Bonsoir, deux choses importantes:
  • Goto instruction à bannir et ce depuis VB1 peut-être bien....
  • Tu as laissé l'importation de certaines instructions VB6 dans ton projet, et donc tu mélanges torchons et serviettes, des fois ça marche, des fois moins bien. (voir cet aperçu dans VS2013)



A noter, que l'inputbox n'existe pas en .Net, soit tu en as codé une, soit elle y est "à cause" de cet import (je ne dis pas grâce), dans ce cas regarde ce lien http://codes-sources.commentcamarche.net/faq/11107-interactions-entre-form-en-net-c-et-vb-net

Maintenant pour répondre à ton problème, une boucle Until devrait le faire (tant que mon résultat n'est pas celui attendu => refaire la boucle).

0
cs_roro69 Messages postés 70 Date d'inscription vendredi 27 décembre 2002 Statut Membre Dernière intervention 29 septembre 2018
14 juin 2015 à 20:54
Bonsoir Whismeril
Merci beaucoup pour ta réponse.
Je m'aperçois que je vais devoir arrêter mon petit projet ; et essayer d'apprendre un petit peu le vb net.
En tout cas merci des conseils ; de l'aide apporté et du temps consacré
0
cs_roro69 Messages postés 70 Date d'inscription vendredi 27 décembre 2002 Statut Membre Dernière intervention 29 septembre 2018
15 juin 2015 à 14:39
Bonjour
Je reviens sur cette discussion car j'ai tenté de recodé autrement et j'aurais aimé avoir des conseils sur le code pour pouvoir essayer de continuer d'apprendre.
Je joint le code et remercie d'avance ceux qui auront la gentillesse de me donner des conseils

Public Class Form1
'Déclaration des variables à utiliséer jusqu'a la fin
Dim hautlivre, larglivre, prempage, derpage As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctl As Control In Me.Controls '// Parcours tout les controle.
If TypeOf ctl Is TextBox Then '// Si TextBox.
AddHandler ctl.KeyPress, AddressOf txt_KeyPress '// J'associe l'evenement KeyPress avec les TextBox.

End If
Next
End Sub

Private Sub txt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) ' Handles TextBox.KeyPress
If e.KeyChar <> ChrW(Keys.Back) And e.KeyChar <> ChrW(Keys.Enter) Then 'accepte touche retour et touche entrée
If Char.IsNumber(e.KeyChar) Then 'accepte que des nombres
Else 'Si pas un nombre alors.......
MessageBox.Show("Que des nombres", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
e.Handled = True
End If
End If
End Sub


Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
Dim test As Integer = 0 'Variable pour le test du textbox

If Not Integer.TryParse(TextBox1.Text, test) Then 'test si le textbox est vide ........
ErrorProvider1.SetError(TextBox1, "Entrée Non valide.") 'Information de l'erreur
TextBox1.SelectAll()
e.Cancel = False
Else
If test < 1 Or test > 20 Then 'condition pour la variable test
ErrorProvider1.SetError(TextBox1, "La valeur doit être entre 1 et 20") 'info pour rectifier l'erreur
TextBox1.Clear() 'nettoyage de la textbox

Else 'Si valeur ok alors
ErrorProvider1.Clear()
End If
End If

End Sub

Private Sub TextBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
Dim test1 As Integer = 0 'Variable pour le test du textbox

If Not Integer.TryParse(TextBox2.Text, test1) Then
ErrorProvider2.SetError(TextBox2, "Entrée Non valide.")
e.Cancel = False
Else
If test1 < 300 Or test1 > 1200 Then
ErrorProvider2.SetError(TextBox2, "La valeur doit être entre 300 et 1200")
TextBox2.Clear()

Else
ErrorProvider2.Clear()
End If
End If
End Sub

Private Sub TextBox3_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox3.Validating
Dim test2 As Integer = 0 'Variable pour le test du textbox

If Not Integer.TryParse(TextBox3.Text, test2) Then
ErrorProvider2.SetError(TextBox3, "Entrée Non valide.")
TextBox3.SelectAll()
e.Cancel = False
Else
If test2 < 15 Or test2 > 30 Then
ErrorProvider2.SetError(TextBox3, "La valeur doit être entre 15 et 30")
TextBox3.Clear()

Else
ErrorProvider2.Clear()
End If
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MessageBox.Show("Toute les informations doivent être renseignées", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
prempage = CInt(TextBox1.Text)
derpage = CInt(TextBox2.Text)
hautlivre = CInt(TextBox3.Text) * 10
larglivre = (derpage - prempage) / 2
MessageBox.Show(larglivre, "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If

End Sub


End Class

Merci pour l'aide apporté et pour le temps accordé
--
0
Rejoignez-nous