06-02-16, 03:14 AM (آخر تعديل لهذه المشاركة : 07-02-16, 01:59 AM {2} بواسطة Mohammed Yousry Abdullah.)
احاول عمل مشروع بسيط مما يستلزم كتابة كود معين
المشكلة :
لنفرض اننا اعطينا كل حرف من الحروف الأبجدية قيمة حسابية معينة مثلا الألف = 1 والباء = 2 والتاء =3 ... وهكذا ثم قمنا بكتابة نص أبجدي في صندوق نصوص داخل مشروع بفيجوال بيسك - فهل هناك كود معين يعطيني قيمة هذا النص حسابيا ؟ بدون ما أقوم بجمع حروفه الأبجدية ؟أي أن ما علي الكود إلا قراءة النص الموجود داخل مربع النص ثم تحويله إلي قيمته الحسابية المفروضة مسبقا ( Dim (أ ) as integer = 1 وهكذا الباء والتاء الخ أرجو الإجابة --- وشكرا
شكرا جزيلا علي كل الردود - وقد استفدت فعلا بتلك الردود - ولكن ما أريده هو ( بعد ما يقوم هذا الكود بتحويل النص إلي ما يساويه من أرقام - أريد أن يقوم هذا الكود بجمع أرقام النص ثم إظهار المجموع في مربع نص آخر أو في ليبل - وشكرا
Public Class Form1 Dim stringg As String Dim q1 As Integer = 1 Dim w2 As Integer = 2 Dim e3 As Integer = 3 Dim r4 As Integer = 4 Dim t5 As Integer = 5 Dim y6 As Integer = 6 Dim U7 As Integer = 7 Dim I8 As Integer = 8 Dim O9 As Integer = 9 Dim P10 As Integer = 10 Dim a11 As Integer = 11 Dim s12 As Integer = 12 Dim d13 As Integer = 13 Dim f14 As Integer = 14 Dim g15 As Integer = 15 Dim h16 As Integer = 16 Dim j17 As Integer = 17 Dim k18 As Integer = 18 Dim l19 As Integer = 19 Dim z20 As Integer = 20 Dim x21 As Integer = 21 Dim c22 As Integer = 22 Dim v23 As Integer = 23 Dim b24 As Integer = 24 Dim n25 As Integer = 25 Dim m26 As Integer = 26
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click For Each aa As String In TextBox1.Text.ToString If aa = "q" Then TextBox2.SelectedText = q1 ElseIf aa = "w" Then TextBox2.SelectedText = w2 ElseIf aa = "e" Then TextBox2.SelectedText = e3 ElseIf aa = "r" Then TextBox2.SelectedText = r4 ElseIf aa = "t" Then TextBox2.SelectedText = t5 ElseIf aa = "y" Then TextBox2.SelectedText = y6 ElseIf aa = "U" Then TextBox2.SelectedText = U7 ElseIf aa = "I" Then TextBox2.SelectedText = I8 ElseIf aa = "O" Then TextBox2.SelectedText = O9 ElseIf aa = "P" Then TextBox2.SelectedText = P10 ElseIf aa = "a" Then TextBox2.SelectedText = a11 ElseIf aa = "s" Then TextBox2.SelectedText = s12 ElseIf aa = "d" Then TextBox2.SelectedText = d13 ElseIf aa = "f" Then TextBox2.SelectedText = f14 ElseIf aa = "g" Then TextBox2.SelectedText = g15 ElseIf aa = "h" Then TextBox2.SelectedText = h16 ElseIf aa = "j" Then TextBox2.SelectedText = j17 ElseIf aa = "k" Then TextBox2.SelectedText = k18 ElseIf aa = "l" Then TextBox2.SelectedText = l19 ElseIf aa = "z" Then TextBox2.SelectedText = z20 ElseIf aa = "x" Then TextBox2.SelectedText = x21 ElseIf aa = "c" Then TextBox2.SelectedText = c22 ElseIf aa = "v" Then TextBox2.SelectedText = v23 ElseIf aa = "b" Then TextBox2.SelectedText = b24 ElseIf aa = "n" Then TextBox2.SelectedText = n25 ElseIf aa = "m" Then TextBox2.SelectedText = m26 End If Next End Sub
End Class
اذا هاذي الطريقه المطلوبه فقط قم بتغيير الاحرف الى عربي
06-02-16, 07:50 PM (آخر تعديل لهذه المشاركة : 06-02-16, 07:57 PM {2} بواسطة moftah70.
تعديل السبب: توضيح المفهوم من البرنامج
)
(06-02-16, 01:12 PM)hassan كتب : تفضل هاذي فكرتك بالانقليزي
PHP كود :
Public Class Form1 Dim stringg As String Dim q1 As Integer = 1 Dim w2 As Integer = 2 Dim e3 As Integer = 3 Dim r4 As Integer = 4 Dim t5 As Integer = 5 Dim y6 As Integer = 6 Dim U7 As Integer = 7 Dim I8 As Integer = 8 Dim O9 As Integer = 9 Dim P10 As Integer = 10 Dim a11 As Integer = 11 Dim s12 As Integer = 12 Dim d13 As Integer = 13 Dim f14 As Integer = 14 Dim g15 As Integer = 15 Dim h16 As Integer = 16 Dim j17 As Integer = 17 Dim k18 As Integer = 18 Dim l19 As Integer = 19 Dim z20 As Integer = 20 Dim x21 As Integer = 21 Dim c22 As Integer = 22 Dim v23 As Integer = 23 Dim b24 As Integer = 24 Dim n25 As Integer = 25 Dim m26 As Integer = 26
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click For Each aa As String In TextBox1.Text.ToString If aa = "q" Then TextBox2.SelectedText = q1 ElseIf aa = "w" Then TextBox2.SelectedText = w2 ElseIf aa = "e" Then TextBox2.SelectedText = e3 ElseIf aa = "r" Then TextBox2.SelectedText = r4 ElseIf aa = "t" Then TextBox2.SelectedText = t5 ElseIf aa = "y" Then TextBox2.SelectedText = y6 ElseIf aa = "U" Then TextBox2.SelectedText = U7 ElseIf aa = "I" Then TextBox2.SelectedText = I8 ElseIf aa = "O" Then TextBox2.SelectedText = O9 ElseIf aa = "P" Then TextBox2.SelectedText = P10 ElseIf aa = "a" Then TextBox2.SelectedText = a11 ElseIf aa = "s" Then TextBox2.SelectedText = s12 ElseIf aa = "d" Then TextBox2.SelectedText = d13 ElseIf aa = "f" Then TextBox2.SelectedText = f14 ElseIf aa = "g" Then TextBox2.SelectedText = g15 ElseIf aa = "h" Then TextBox2.SelectedText = h16 ElseIf aa = "j" Then TextBox2.SelectedText = j17 ElseIf aa = "k" Then TextBox2.SelectedText = k18 ElseIf aa = "l" Then TextBox2.SelectedText = l19 ElseIf aa = "z" Then TextBox2.SelectedText = z20 ElseIf aa = "x" Then TextBox2.SelectedText = x21 ElseIf aa = "c" Then TextBox2.SelectedText = c22 ElseIf aa = "v" Then TextBox2.SelectedText = v23 ElseIf aa = "b" Then TextBox2.SelectedText = b24 ElseIf aa = "n" Then TextBox2.SelectedText = n25 ElseIf aa = "m" Then TextBox2.SelectedText = m26 End If Next End Sub
End Class
اذا هاذي الطريقه المطلوبه فقط قم بتغيير الاحرف الى عربي
طبعنا في طرق ابصط
وشكرا
بعد اذن الاخ حسان اعتقد والله اعلم يريدها بهذه الطريقه
تحويل الحروف الي ارقام والعكس طبعاً مجرد تحويل فقط اقصد لا ينفع في حالة تشفير مثلاً بمعنى اذا كتبت اسمك وقمت بتحويله الي ارقام وقمت بوضع نفس الرقم وقمت بتحويله الي حروف لن تجد اسمك
الأخوة الأعزاء أعضاء المنتدي
السلام عليكم ورحمة الله وبركاته
برجاء قراءة رسالتي بشء من التمعن ....
قلت من قبل أنني أقوم بعمل مشروع معين وأحتاج لإتمام هذا المشروع إلي كود يقوم بتحويل الأبجدية العربية إلي قيم حسابية معطاة مسبقا لهذه الحروف الأبجدية - ثم يقوم هذا الكود بجمع هذه القيم وإظهار النتيجة في مربع نص أو ليبل - مثال :
لو فرضنا أن حرف ال م = 4 وحرف ال ح = 18 وحرف ال د = 16 ... إذن كلمة محمد = 4+18+4+16 = 42 ... وهذا هو الرقم المراد إظهاره في مربع نص أو ليبل - هل هذا واضح ؟ OK
ما وصلني من الردود لم تكن كافية أو لم تجيب إجابة كاملة علي سؤالي حيث أن جميعها اشتملت علي أكواد تقوم بتحويل الأحرف الأبجدية إلي ما يساويها من قيم حسابية فقط - ولم تقم بجمع هذه القيم في مربع نص مثلا - أرجو التركيز معي
وشكرا جزيلا
والسلام عليكم ورحمة الله وبركاته
28-02-16, 01:49 AM (آخر تعديل لهذه المشاركة : 28-02-16, 02:02 AM {2} بواسطة Fantastico.)
إذا كنت تريد حساب القيمة العددية (الجمل) للنصوص
إستخدم هذه الدالة
PHP كود :
Function ABGD(ByVal str As String) As Integer
Dim sum As Integer = 0 Dim chrVal() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, _ 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000} Dim Letters(27) As String For i = 0 To 27 Letters(i) = ("ابجدهوزحطيكلمنسعفصقرشتثخذضظغ").Substring(i, 1) Next
For i = 0 To str.Length - 1 Dim n As Integer = 0
If str.Substring(i, 1) = "ء" _ Or str.Substring(i, 1) = "ؤ" _ Or str.Substring(i, 1) = "ئ" _ Or str.Substring(i, 1) = "أ" _ Or str.Substring(i, 1) = "إ" Then
n = 1 ElseIf str.Substring(i, 1) = "آ" Then n = 2 ElseIf str.Substring(i, 1) = "ة" Then n = 5 ElseIf str.Substring(i, 1) = "ى" Then n = 10 Else For j = 0 To 27 If str.Substring(i, 1) = Letters(j) Then n = chrVal(j) Exit For End If Next
Function g(ByVal str As String)
Dim chr As String = "ابتثجحخدذرزسشصضطظعغفقكلمنهوي"
Dim a As String = ""
For i = 0 To str.Length - 1
a += chr.IndexOf(str(i)).ToString
Next
Return a
End Function
28-02-16, 03:01 PM (آخر تعديل لهذه المشاركة : 28-02-16, 03:06 PM {2} بواسطة silverlight.)
يمكن استخدام الكلاس التالي كبداية لما تريده و يمكن التعديل عليه بتغيير الحروف و الارقام لكنه ف النهاية سيؤدي الغرض المطلوب
PHP كود :
Public Class Accumulator
Public Sub New() End Sub
Public Function Accumulate(text As String) As Integer Return AccumulateIntegers(ConvertTextToIntegers(text)) End Function
Protected ReadOnly Property letters As List(Of String) Get Return New List(Of String) From {"a", "b", "c", "d", "e", "f", "J", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} End Get End Property
Protected ReadOnly Property Numerics As List(Of String) Get Return New List(Of String) From {"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"} End Get End Property
Private Function ConvertTextToIntegers(text As String) As List(Of Integer) Dim sourceValue As String = CType(text, String) Dim result As List(Of Integer) = CType(Nothing, List(Of Integer)) If Not (String.IsNullOrEmpty(sourceValue)) Then result = New List(Of Integer)() For j = 0 To sourceValue.Length - 1 Dim s As String = sourceValue(j) If letters.Contains(s) Then Dim index As Integer = letters.IndexOf(s) Dim value As String = Numerics(index) result.Add(ParseInteger(value)) End If Next End If Return result End Function
Private Function AccumulateIntegers(source As IEnumerable(Of Integer)) As Integer Return source.Aggregate(New Func(Of Integer, Integer, Integer)(Function(a, b) Return a + b End Function)) End Function
Private Function ParseInteger(stringToParse As String) As Integer Return ParseInteger(stringToParse, False) End Function
Private Function ParseInteger(stringToParse As String, throwException As Boolean) As Integer Dim result As Integer = 0 If throwException Then result = Integer.Parse(stringToParse, Globalization.NumberStyles.Any, Globalization.CultureInfo.InvariantCulture) Else If Not Integer.TryParse(stringToParse, Globalization.NumberStyles.Any, Globalization.CultureInfo.InvariantCulture, result) Then Integer.TryParse(stringToParse, Globalization.NumberStyles.Any, Globalization.CultureInfo.CurrentCulture, result) End If End If
Return result End Function
End Class
الإستخدام
PHP كود :
Dim total As Integer = New Accumulator().Accumulate("fcx")
ملحوظة الكلاس حتي الان يعمل مع الحروف الإنجليزية الصغيرة small letters فقط و لكي يعمل مع اي حروف أخري عليك ان تضيف تلك الحروف الجديدة و الأرقام الجديدة الي كل من letters Property و Numerics Property
بالتاكيد تستطيع تغيير الحروف و الارقام كما شئت و ستحصل ف النهاية علي نفس النتائج المرجوة
ملحوظة أخيرة
في المستقبل ياريت تركز انت شوية و تكتب عنوان مناسب لموضوعك
و كمان الناس هنا بتحاول تساعدك بما يستطيعون
لذلك كن راقيا في طلب المساعدة تنال اجابة راقية