IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Générateur de nom


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Par défaut Générateur de nom
    Bonjour me revoilà et oui encore un probléme avec mon générateurs de noms décidément il m'en fait voir
    Donc il fonctionnait très bien au début puis j'ai commencer a faire amélioré le graphisme et le message d'erreur suivent revient :La valeur ne peut pas être null

    Voici mon code que j'avais déjà réparé avec votre aide:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    Option Strict Off
    Option Explicit On
    Friend Class Form1
        Inherits System.Windows.Forms.Form
        Dim a As Short
        Dim pass As String
        Dim charactere(287) As String
     
        Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
            charactere(0) = "Ai"
            charactere(1) = "An"
            charactere(2) = "Anad"
            charactere(3) = "Bin"
            charactere(3) = "Anu"
            charactere(4) = "Bar"
            charactere(5) = "Ek"
            charactere(6) = "Nai"
            charactere(7) = "Nu"
            charactere(8) = "Ok"
            charactere(9) = "Or"
            charactere(10) = "Sar"
            charactere(11) = "Um"
            charactere(12) = "Un"
            charactere(13) = "Ut"
            charactere(14) = "Wanrag"
            charactere(15) = "Wanarak"
            charactere(16) = "Ong"
            charactere(17) = "Tuk"
            charactere(18) = "Dwe"
            charactere(19) = "Fut"
            charactere(20) = "Sak"
            charactere(21) = "Siz"
            charactere(22) = "Set "
            charactere(23) = "Odro"
            charactere(24) = "Nuk"
            charactere(25) = "Don"
            charactere(26) = "Kantuz"
            charactere(27) = " Milluz"
            charactere(28) = "Agril"
            charactere(29) = "Agrul"
            charactere(30) = "Aimên"
            charactere(31) = "Ang"
            charactere(32) = "Ankor"
            charactere(33) = "Arm"
            charactere(34) = "Az"
            charactere(35) = "Az"
            charactere(36) = "Azgal"
            charactere(37) = "Azril"
            charactere(38) = "Azul"
            charactere(39) = "Bar"
            charactere(40) = "Barag"
            charactere(41) = "Baraz"
            charactere(42) = "Bezek"
            charactere(43) = "Baruk"
            charactere(44) = "Boga"
            charactere(45) = "Bok"
            charactere(46) = "Bolg"
            charactere(47) = "Bran"
            charactere(48) = "Brog"
            charactere(49) = "Bryn"
            charactere(50) = "Chuf"
            charactere(51) = "Damnaz"
            charactere(52) = "Dal"
            charactere(53) = "Dammaz"
            charactere(54) = "Dammaz"
            charactere(55) = "Dar"
            charactere(56) = "Dawi"
            charactere(57) = "Dawr"
            charactere(58) = "Deb"
            charactere(59) = "Dharkhangron"
            charactere(60) = "Doh"
            charactere(61) = "Dok"
            charactere(62) = "Dongliz"
            charactere(63) = "Drakendrengi"
            charactere(64) = "Drakk"
            charactere(65) = "Drangthrong"
            charactere(66) = "Drazh"
            charactere(67) = "Drek"
            charactere(68) = "Dreng"
            charactere(69) = "Drin"
            charactere(70) = "Dron"
            charactere(71) = "Drongnel"
            charactere(72) = "Drung"
            charactere(73) = "Duk"
            charactere(74) = "Dum"
            charactere(75) = "Durak"
            charactere(76) = "Duraz"
            charactere(77) = "Ekrund"
            charactere(78) = "Elgi"
            charactere(79) = "Elgram"
            charactere(80) = "Elgraz"
            charactere(81) = "Endrinkuli"
            charactere(82) = "Frongol"
            charactere(83) = "Galaz"
            charactere(84) = "Garaz"
            charactere(85) = "Gand"
            charactere(86) = "Gazan"
            charactere(87) = "Gazul"
            charactere(88) = "Ghal"
            charactere(89) = "Gibal"
            charactere(90) = "Girt"
            charactere(91) = "git"
            charactere(92) = "Gnol"
            charactere(93) = "Gnollengrom"
            charactere(94) = "Gore"
            charactere(95) = "Gorak"
            charactere(96) = "Gorl"
            charactere(97) = "Gorm"
            charactere(98) = "Gorog"
            charactere(99) = "Goruz"
            charactere(100) = " Got"
            charactere(101) = "Grik"
            charactere(102) = "Grim"
            charactere(103) = "Grimnir"
            charactere(104) = "Grindal"
            charactere(105) = "Grint"
            charactere(106) = "Grizal"
            charactere(107) = "Grizdal"
            charactere(108) = "Grob"
            charactere(109) = "Grobi"
            charactere(110) = "Grobkaz"
            charactere(111) = " Grobkul"
            charactere(112) = "Grog"
            charactere(113) = " Grom"
            charactere(114) = " Gromdal"
            charactere(115) = "Gromthi"
            charactere(116) = "Grong"
            charactere(117) = "Grongol"
            charactere(118) = " Gronit"
            charactere(119) = "Gronti"
            charactere(120) = "Grumbak"
            charactere(121) = "Grund"
            charactere(122) = "Grung"
            charactere(123) = "Grungni"
            charactere(124) = "Grungnaz"
            charactere(125) = "Grungron"
            charactere(126) = "Guz"
            charactere(127) = "Har"
            charactere(128) = "Hazkal"
            charactere(129) = "Hirn"
            charactere(130) = "Hunk"
            charactere(140) = "Huzhrung"
            charactere(141) = "Ik"
            charactere(142) = "Irkul"
            charactere(143) = " Izor"
            charactere(145) = "Izril "
            charactere(146) = "Kadrin "
            charactere(147) = "Karag"
            charactere(148) = "Karak"
            charactere(149) = "Karaz"
            charactere(150) = "Karugromthi "
            charactere(156) = "Khazukan"
            charactere(157) = "Khrum"
            charactere(158) = "Khulghur"
            charactere(159) = "Klad"
            charactere(160) = " Klinka"
            charactere(161) = " Klinkarun"
            charactere(162) = "Kol"
            charactere(163) = "Konk"
            charactere(164) = "Krink"
            charactere(165) = "Kron"
            charactere(166) = "Kruk"
            charactere(167) = "Krunk"
            charactere(168) = "Krut"
            charactere(169) = "Kulgur"
            charactere(170) = "Kuri"
            charactere(171) = "Langk"
            charactere(172) = "Lhune"
            charactere(173) = "Lok"
            charactere(174) = "Makaz"
            charactere(175) = "Maraz"
            charactere(176) = "Mhornar"
            charactere(177) = "Migdhal"
            charactere(178) = "Mingol"
            charactere(179) = "Mizpal"
            charactere(175) = "Morgrim"
            charactere(176) = "Muzkhgru"
            charactere(178) = "Nar"
            charactere(179) = "Nathgar"
            charactere(180) = "Naggrund"
            charactere(181) = "Nogarung"
            charactere(182) = "Norn"
            charactere(184) = "Nu"
            charactere(185) = "Ogri"
            charactere(186) = "Ok"
            charactere(187) = "Okri"
            charactere(188) = "Ongrun"
            charactere(189) = "Onk"
            charactere(190) = "Ori"
            charactere(191) = "Orrud"
            charactere(192) = "Ragarin"
            charactere(193) = "Rhun"
            charactere(194) = "Rhunki"
            charactere(195) = "Rhyn"
            charactere(196) = "Rik"
            charactere(197) = "Rikkit"
            charactere(198) = "Ril"
            charactere(199) = "Rinn"
            charactere(200) = "Rorkaz"
            charactere(201) = "Ruf"
            charactere(202) = "Runk"
            charactere(203) = "Rutz"
            charactere(204) = "Ruvalk"
            charactere(205) = "Sar"
            charactere(206) = "Skaud"
            charactere(207) = "Skarrenruf"
            charactere(208) = "Skaz"
            charactere(209) = "Skof"
            charactere(210) = "Skrat"
            charactere(211) = "Skree"
            charactere(212) = "Skruff"
            charactere(213) = "Skrund"
            charactere(214) = "Slotch"
            charactere(215) = "Smednir"
            charactere(216) = "Stok"
            charactere(217) = "Strol"
            charactere(218) = "Stromez"
            charactere(219) = "Thag"
            charactere(220) = "Thindrongol"
            charactere(221) = "Thingaz"
            charactere(222) = "Thongli"
            charactere(223) = "Thrag"
            charactere(224) = "Tragh"
            charactere(225) = "Throng"
            charactere(226) = "Throngrink"
            charactere(227) = "Thrund"
            charactere(228) = "Thrung"
            charactere(229) = "Thrynaz"
            charactere(230) = "Thryng"
            charactere(231) = "Thungni"
            charactere(232) = "Tiwaz "
            charactere(233) = "Trogg "
            charactere(234) = "Trolldrengi "
            charactere(235) = "Tromm "
            charactere(236) = "Ufdi"
            charactere(237) = "Um"
            charactere(238) = "Umanar "
            charactere(239) = "Umgak "
            charactere(240) = "Umgi "
            charactere(241) = "Un "
            charactere(242) = "Unbaraki "
            charactere(243) = "Und "
            charactere(244) = "Ungdrin "
            charactere(245) = "Ungor "
            charactere(246) = "Ungrim "
            charactere(247) = "Urbar "
            charactere(248) = "Urbaz "
            charactere(249) = "Urk"
            charactere(250) = "Urkgrengi "
            charactere(251) = "Ut "
            charactere(252) = "Uzgul"
            charactere(253) = "Valaya"
            charactere(254) = "Valdahaz "
            charactere(255) = "Varag "
            charactere(256) = "Varn "
            charactere(257) = "Varrkhulg "
            charactere(258) = "Vengryn "
            charactere(259) = "Vithang "
            charactere(260) = "Vlag "
            charactere(261) = "Vongal "
            charactere(262) = "Vorkhul "
            charactere(263) = "Vorn "
            charactere(264) = "Vulkhrund "
            charactere(265) = "Wan"
            charactere(266) = "Wanaz "
            charactere(267) = "Wand "
            charactere(268) = "Wanrag "
            charactere(269) = "Wanrak "
            charactere(270) = "Wattock"
            charactere(271) = "Wazzok "
            charactere(272) = "Werit "
            charactere(273) = "Wutraz"
            charactere(274) = "Wulthrung"
            charactere(275) = "Wutroth "
            charactere(276) = "Wyr "
            charactere(277) = "Yar"
            charactere(278) = "Zagaz "
            charactere(279) = "Zak"
            charactere(280) = "Zan "
            charactere(281) = "Zaraz"
            charactere(282) = "Zharr "
            charactere(283) = "Zhuf "
            charactere(284) = "Zilfin "
            charactere(285) = "Zorn"
            charactere(286) = "Zon "
            charactere(287) = "Zunthrum "
     
        End Sub
     
        Private Sub generate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles button1.Click
            Randomize()
            pass = ""
            a = 0
            While (a <= 1)
                pass = pass & charactere(CShort(Rnd() * 287))
                a = a + 1
            End While
            textbox1.Text = pass
            My.Computer.Clipboard.Clear()
            If Not String.IsNullOrEmpty(TextBox1.Text) Then My.Computer.Clipboard.SetText(TextBox1.Text)
        End Sub
    End Class
    Merci d'avance

  2. #2
    Membre Expert
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Billets dans le blog
    7
    Par défaut
    Pourquoi ne déclares-tu pas ton tableau délimité en l initialisant de suite :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim charactere as string() = new string(){"Ai","An","Anad","Bin"}
    De plus si tu souhaites accéder a ton tableau uniquement depuis cette classe alors remplace ton attribut de visibilité "Dim" par "Private" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Private charactere as string() = new string(){"Ai","An","Anad","Bin"}
    A+

  3. #3
    Membre Expert Avatar de _Ez3kiel
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2013
    Messages : 836
    Par défaut
    Il y a des erreurs dans les index de tableau de tes noms :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    charactere(3) = "Bin"
    charactere(3) = "Anu"
     
    [...]
     
    charactere(143) = " Izor"
    charactere(145) = "Izril "
     
    [...]
     
    charactere(150) = "Karugromthi "
    charactere(156) = "Khazukan"
     
    [...]
     
    charactere(179) = "Mizpal"
    charactere(175) = "Morgrim"
    charactere(176) = "Muzkhgru"
    charactere(178) = "Nar"
    charactere(179) = "Nathgar"
    Oui j'avais que ça à faire de tout regarder ...

    Par exemple si ton générateur de chiffre te retourne 151, il va planter car il n'y pas de noms à l'index 151.

    Pour éviter cela,tu peux utiliser la méthode de wallace1, qui a le mérite d'éviter les étourderies d'index. Ou si tu veux développer un peu tes compétences, tu peux stocker tes noms dans des fichiers textes, des bases de données, etc

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Par défaut
    tu a l’œil Ez3kiel lol faut dire aussi que j'ai écrit les nom et les chiffre a la main un par un donc j'ai fait des faute merci juste j'ai du mal a comprendre la technique plus haut je débute encore^^

  5. #5
    Membre Expert

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 067
    Par défaut
    Pourquoi ne pas utiliser une liste plutôt qu'un tableau comme ça tu n'as pas besoin de spécifier l'index à chaque fois que tu ajoutes un élément.

  6. #6
    Membre Expert Avatar de _Ez3kiel
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    836
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Janvier 2013
    Messages : 836
    Par défaut
    Ce sont des étourderies qui peuvent arriver.

    Pour expliquer un peu la méthode de Wallace1, lorsque tu fais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Public Class 1
     
    Dim charactere(2) As String
     
     Private Sub Form1_Load(sender As object, e As eventargs) Handles MyBase.Load
     
    charactere(0) = " toto"
    charactere(1) = " tata"
    charactere(2) = " titi"
     
    End sub
     
    End Class
    Tu déclares un tableau de string dans ta classe Form1, et tu définis que ce tableau aura 3 "cases" pour y ranger du texte. Puis dans ton événement Load, tu remplis une à une les cases en définissant quel mot va dans quelle case. A hauteur de 3 mots et 3 cases, on s'y retrouve, à hauteur de 287, on peut se perdre dans les index ...

    La solution de Wallace consiste à faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    Public Class 1
     
    Dim charactere(2) As String = new string(){"Toto","tata","titi"}
     
     Private Sub Form1_Load(sender As object, e As eventargs) Handles MyBase.Load
     
    End sub
     
    End Class
    C'est dire qu'il déclares comme toi un tableau de string dans la classe, à la différence qu'il le remplit immédiatement en instanciant un objet de type String avec son constructeur, ce même constructeur a la possibilité d'instancier l'objet String avec les données qu'il aura dans les paramètres (Toto, Tata, Titi). Et cette instanciation à la déclaration permet de ne pas avoir les index à fournir car c'est le constructeur qui s'occupe de remplir les cases avec le texte.

    (Bon, OK, je suis très mauvais pédagogue, mais j'essaye. )


    Et la notion de private, c'est pour la maintenance du code, c'est à dire que un jour un codeur utilisera ta classe Form1, il n'aura pas accès à cette liste. Dans la mesure où elle ne doit pas être utilisée hors de ta classe c'est une bonne chose. Dans ton cas à toi, ça ne changera pas le fait que ce soit fonctionnel ou non, mais c'est une très bonne habitude à prendre pour programmer (Voir Public/Friend/Private/Abstract etc sur Google).


    Cependant, il existe encore une autre solution, permettant une lisibilité des noms plus facile, et t'ouvrant des portes quand à la manipulation de tes "noms" : La List(of T), qui te permettra d'avoir une liste de noms, qui gère elle-même la position du nom à son ajout.

    Exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
        Private listeNom As List(Of String)
     
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
     
            listeNom = New List(Of String)
     
            listeNom.Add("toto")
            listeNom.Add("tata")
            listeNom.Add("titi")
     
            MsgBox(listeNom(1)) 'Retourne tata
     
     
        End Sub

    Ainsi, plus de soucis d'index, et toujours fonctionnel avec ton code.

    EDIT : Bon ba le temps que j'écris mon pavé, youtpout978 avait suggéré mon idée.

  7. #7
    Membre averti
    Homme Profil pro
    Inscrit en
    Octobre 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Octobre 2013
    Messages : 16
    Par défaut
    Merci beaucoup pour votre aide j'essaye tout de suite

Discussions similaires

  1. Algorithmique : générateur de nom
    Par Caxton dans le forum Qt
    Réponses: 1
    Dernier message: 22/03/2012, 14h15
  2. Réponses: 2
    Dernier message: 02/02/2009, 08h48
  3. Réponses: 13
    Dernier message: 22/03/2007, 23h46
  4. Réponses: 1
    Dernier message: 23/12/2005, 00h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo