08-05-14, 10:36 PM
وعليكم السلام ورحمة الله وبركاته
اعمل مثل الصورة :
وقم بنسخ الكود كامل ولصقه في الفورم :
اعمل مثل الصورة :
وقم بنسخ الكود كامل ولصقه في الفورم :
كود :
Public Class Form1
Public Shared Function RandomNumStr(ByVal intStrLength As Integer) As String
'الوظيفة المسئولة عن توليد الرقم العشوائي
Dim chars = "0123456789"
Dim intLength As Integer = intStrLength - 1
Dim stringChars = New Char(intLength) {}
Dim random = New Random()
For i As Integer = 0 To stringChars.Length - 1
stringChars(i) = chars(random.[Next](chars.Length))
Next
Dim finalString = New [String](stringChars)
Return finalString
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'لو التكست فارغ لا ينفذ الكود
If TextBox1.Text = "" Or TextBox1.Text = "0" Then Exit Sub
'تعبئة التكست بالرقم العشوائي حسب طول الرقم المكتوب في التكست بوكس 1
TextBox2.Text = RandomNumStr(TextBox1.Text)
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
'لمنع كتابة احرف في التكست
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
If Asc(e.KeyChar) = 8 Then
e.Handled = False
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim fs As System.IO.FileStream = System.IO.File.Create(Application.StartupPath & "\FileName.txt")
Dim info As Byte() = New System.Text.UTF8Encoding(True).GetBytes(TextBox2.Text)
fs.Write(info, 0, info.Length)
Process.Start(Application.StartupPath & "\FileName.txt")
fs.Close()
End Sub
End Class
