Zufallszahl in VB6 Generieren
Schwierigkeitsgrad: |||| ( Für Fortgeschrittene )
Also hier wird es jetzt dass erstmal etwas Kniffliger ![]()
Also ihr benötigt ein Modul, klickt in VB6 auf:
Project --> Add Module
Klickt auf Öffnen.
So hier zunächst der Code:
Public Function Zufallszahl(vMinimum As Currency, vMaximum As Currency) As Currency
If vMinimum >= vMaximum Then
MsgBox "Ungültige Argumente", vbCritical
Else
Zufallszahl = Int((vMaximum - vMinimum + 1) * Rnd + vMinimum)
End If
End Function
Dass muss in dass Modul rein.
So, dann setzt ihr ein Objekt auf der Form und nennt es z.B. lblText
So als Label natürlich ![]()
So dann schreibt ihr bei cmdZufallszahl_Click() Also müsst ihr auch einen Button erstellen folgendes Rein:
Private Sub cmdZufallszahl_Click()
lblText.Caption = Zufallszahl(1,10) ' Sorgt dafür dass lblText.Caption Zufallszahl(1,10) erhält. 1 steht für die Minimale zahl also die niedrigtse die er genereieren kann und 10 dass Größte.
End Sub
So Fertig,
Dies ist allerdings nur für Fortgeschrittene