• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Soru Textboxlarda Çarpma

sirkülasyon

Altın Üye
Katılım
10 Temmuz 2012
Mesajlar
2,543
Excel Vers. ve Dili
2021 LTSC TR
Ustam









Kod:
Private Sub TextBox3_Change()
If TextBox3 = "" Then TextBox3 = 0
If TextBox4 = "" Then TextBox4 = 0
miktar = TextBox3 * 1
fiyat = TextBox4 * 1
TextBox5 = Format(miktar * fiyat, "#,##0.00")
End Sub

Private Sub TextBox4_Change()
If TextBox3 = "" Then TextBox3 = 0
If TextBox4 = "" Then TextBox4 = 0
miktar = TextBox3 * 1
fiyat = TextBox4 * 1
TextBox5 = Format(miktar * fiyat, "#,##0.00")
End Sub

kodu yerine For döngüsü kullanarak 5 step kullanarak textboxlarda çarpma işlemini gerçekleştirmek için ne yapabilirim?

Textbox3 * Textbox4 = Textbox5
Textbox8 * Textbox9 = Textbox10
Textbox13 * Textbox14 = Textbox15
Textbox18 * Textbox19 = Textbox20
gibi
 
Merhaba,

Deneyiniz.
Kod:
For i = 3 To 18 Step 5
     Controls("TextBox" & i + 2) = Controls("TextBox" & i) * Controls("TextBox" & i + 1)
Next i
 
Son düzenleme:
Ömer abi
Commandbutton' a bağladım kodu.
Controls("Textbox" & i + 2)

kısmı hata veriyor.
 
Son düzenleme:
Ters yazmışım, üsteki kodu güncelledim.
 
Boş texboxlarda deneniz sanırım.
Bu şekilde deneyiniz.
Kod:
For i = 3 To 88 Step 5
    Adet = Controls("TextBox" & i)
    Birim = Controls("TextBox" & i + 1)
    If Controls("TextBox" & i) = "" Then Adet = 0
    If Controls("TextBox" & i + 1) = "" Then Birim = 0
    Controls("TextBox" & i + 2) = Adet * Birim
Next i
 
Kod:
Sub hesapla(tNo As Integer)
    al = ("TextBox" & tNo - 2)
    Set t1 = Controls("TextBox" & tNo - 2)
    Set t2 = Controls("TextBox" & tNo - 1)
    Set t3 = Controls("TextBox" & tNo)
    If t1.Value = "" Then t1.Value = 0
    If t2.Value = "" Then t2.Value = 0
    t3.Text = Format(Val(t1.Text) * Val(t2.Text), "#,##0.00")
End Sub

Private Sub TextBox3_Change()
    Call hesapla(5)
End Sub
Private Sub TextBox4_Change()
    Call hesapla(5)
End Sub
Private Sub TextBox8_Change()
    Call hesapla(10)
End Sub
Private Sub TextBox9_Change()
    Call hesapla(10)
End Sub
Private Sub TextBox13_Change()
    Call hesapla(15)
End Sub
Private Sub TextBox14_Change()
    Call hesapla(15)
End Sub
Private Sub TextBox18_Change()
    Call hesapla(20)
End Sub
Private Sub TextBox19_Change()
    Call hesapla(20)
End Sub
 
Ömer Abi teşekkür ederim.
Veysel abi size de ayrıca teşekkür ederim.
Konu Çözüldü
 
Class modulle cozmek daha pratik olacak bir soru...

Class modul ekleyin. Class1 in kod sayfasına ekleyin.
Kod:
Private WithEvents txtbox As MSForms.TextBox
Dim ctlr As Control

Public Property Set TextBox(ByVal t As MSForms.TextBox)
    Set txtbox = t
End Property

Private Sub txtbox_Change()

    tNo = Replace(txtbox.Name, "TextBox", "")
    md = (Val(tNo) Mod 5)
    If tNo < 90 And (md = 3 Or md = 4) Then

        If md = 3 Then tNo = tNo + 2
        If md = 4 Then tNo = tNo + 1

        Set t1 = UserForm1.Controls("TextBox" & tNo - 2)
        Set t2 = UserForm1.Controls("TextBox" & tNo - 1)
        Set t3 = UserForm1.Controls("TextBox" & tNo)

        If t1.Value = "" Then t1.Value = 0
        If t2.Value = "" Then t2.Value = 0

        t3.Text = Format(Val(t1.Value) * Val(t2.Value), "#,##0.00")
        For i = 3 To 88 Step 5
            top1 = top1 + Val(UserForm1.Controls("TextBox" & i))
            top2 = top2 + Val(UserForm1.Controls("TextBox" & i + 1))
            top3 = top3 + Val(UserForm1.Controls("TextBox" & i + 2))
        Next i
        UserForm1.TextBox91.Text = Format(top1, "#,##0.00")
        UserForm1.TextBox92.Text = Format(top2, "#,##0.00")
        UserForm1.TextBox93.Text = Format(top3, "#,##0.00")
    End If

End Sub


Userform1 kod sayfasına ekleyin.

Kod:
Private myEventHandlers As Collection

Private Sub UserForm_Initialize()
    Dim txtbox As Class1

    Set myEventHandlers = New Collection

    Dim c As Control
    For Each c In Me.Controls
        If TypeName(c) = "TextBox" Then
            tNo = Val(Replace(c.Name, "TextBox", ""))
            If (tNo Mod 5) = 3 Or (tNo Mod 5) = 4 Then
                Set txtbox = New Class1
                Set txtbox.TextBox = c
                myEventHandlers.Add txtbox
            End If
        End If
    Next c
End Sub
 

Ekli dosyalar

Geri
Üst