اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

الردود الموصى بها

قام بنشر

السلام عليكم ورحمة الله وبركاتة

الرجاء مساعدتى

يوجد خطاء فى توزيعة الخاصة بالفئات 100 اما الباقى مظبوط

اولا الرجاء ادخال الارقام اولا ثم ادخال القيمة 1 او القيمة 2

ستجد القيمة 2 يوجد بها خطاء فى توزيع الارقام فى خانة 100

15 =8+8 بدل 15 =8+7

فئات.png

توزيع فئات2 .xlsm

  • أفضل إجابة
قام بنشر
 Dim totalValue As Double
    Dim targetValue1 As Double
    Dim targetValue2 As Double

    ' Get values from TextBoxes
    totalValue = Val(TextBox10.Value)
    targetValue1 = Val(TextBox11.Value)
    targetValue2 = Val(TextBox12.Value)

    ' Check for feasibility
    If targetValue1 + targetValue2 <> totalValue Then
        MsgBox "Target values do not match total value.", vbCritical
        Exit Sub
    End If

    ' Initialize banknote counts
    Dim count200 As Integer: count200 = Val(TextBox1.Value)
    Dim count100 As Integer: count100 = Val(TextBox2.Value)
    Dim count50 As Integer: count50 = Val(TextBox3.Value)

    ' Create arrays to store distribution
    Dim group1(1 To 3) As Integer
    Dim group2(1 To 3) As Integer

    ' Random distribution loop
    Do
        ' Reset group values
        For i = 1 To 3
            group1(i) = 0
            group2(i) = 0
        Next i

        ' Randomly assign 200 denomination banknotes
        Randomize
        For i = 1 To count200
            If Rnd() < 0.5 Then
                group1(1) = group1(1) + 1
            Else
                group2(1) = group2(1) + 1
            End If
        Next

        ' Randomly assign 100 denomination banknotes
        Randomize
        For i = 1 To count100
            If Rnd() < 0.5 Then
                group1(2) = group1(2) + 1
            Else
                group2(2) = group2(2) + 1
            End If
        Next

        ' Randomly assign 50 denomination banknotes
        Randomize
        For i = 1 To count50
            If Rnd() < 0.5 Then
                group1(3) = group1(3) + 1
            Else
                group2(3) = group2(3) + 1
            End If
        Next

        ' Calculate the total value of each group
        Dim group1Total As Double: group1Total = group1(1) * 200 + group1(2) * 100 + group1(3) * 50
        Dim group2Total As Double: group2Total = group2(1) * 200 + group2(2) * 100 + group2(3) * 50
    Loop Until group1Total = targetValue1 And group2Total = targetValue2

    ' Display the distribution in TextBoxes or other controls
    TextBox4.Value = group1(1)
    TextBox7.Value = group2(1)
    TextBox5.Value = group1(2)
    TextBox8.Value = group2(2)
    TextBox6.Value = group1(3)
    TextBox9.Value = group2(3)
    

لقد وجدت الحل بحمدلله

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information