8 Replies - 2550 Views - Last Post: 02 March 2011 - 03:23 AM Rate Topic: -----

#1 razree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 01-March 11

sum values of dynamic textboxes

Posted 01 March 2011 - 01:44 PM

Hello
I'm new to this forum and quite new to visual basic. I started editing an existing code (basicaly to learn vb) without any real previou experience. Well let's get to the point; I have a form that gathers data from db ordering by user ID (on click count). I have one DataGridView with a list of user, some have data in db, some have not. I came so far that if I CLICK on a user that have data, all data is dissplayed in 6 dinamyc textboxes. If user has no data inly first (emty) row with 6 dinamyc textboxes is created.

Then I have a button that simultaneously adds a row of dinamyc textboxes bellow and multiplyies textbox04 (name is clickcount & 4) and textbox05 and displays the result in textbox06.
Now I got stucked; I want to add a messagebox that shows if textbox04 & 05 are empty and in that case exits sub. Of course if they are not empty, their sum should be multiplyed in textbox06 (on 2 decimal places exact) Here is my code so far:

	Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	 
	        'Reset warnings
	        lblNotifyPrint.Text = ""
	        lblNotifySave.Text = ""
	        lblNotifyStorno.Text = ""
	 
	        Dim yPosition As Integer
	        Dim num As Integer
	 
	        If ClickCount = 0 Then
	 
	            yPosition = 480
	            ReDim TextBoxes(5)
	            Dim TextBoxWidth As Integer = 0
	            Dim TextboxX As Integer = 0
	 
	            For TextBox = 0 To TextBoxes.Count() - 1
	 
	                num += 1
	                TextBoxes(num - 1) = New MyTextBox()
	 
	                Select Case TextBox
	                    'V.P
	                    Case 0
	                        TextBoxWidth = 89
	                        TextboxX = 5
	 
	                        'Opis stroška
	                    Case 1
	                        TextBoxWidth = 177
	                        TextboxX = 99
	 
	                        'Konto
	                    Case 2
	                        TextBoxWidth = 60
	                        TextboxX = 281
	 
	                        'Kolicina
	                    Case 3
	                        TextBoxWidth = 60
	                        TextboxX = 346
	 
	                        'Cena
	                    Case 4
	                        TextBoxWidth = 60
	                        TextboxX = 411
	 
	                        'Znesek
	                    Case 5
	                        TextBoxWidth = 89
	                        TextboxX = 476
	 
	                End Select
	                With TextBoxes(num - 1)
	                    .Name = "Textbox" & ClickCount & num
	                    .Size = New Size(TextBoxWidth, 22)
	                    .Text = "Textbox" & ClickCount & num
	                    .Location = New System.Drawing.Point(TextboxX, yPosition)
	                End With
	 
	                Me.Controls.AddRange(New System.Windows.Forms.Control() {TextBoxes(num - 1)})
	            Next
	 
	        Else
	            ReDim TextBoxes(5)
	            Dim TextBoxWidth As Integer = 0
	            Dim TextboxX As Integer = 0
	 
	            yPosition = 450 + (30 * ClickCount)
	 
	            For TextBox = 0 To TextBoxes.Count() - 1
	 
	                num += 1
	                TextBoxes(num - 1) = New MyTextBox()
	 
	                Select Case TextBox
	                    'V.P
	                    Case 0
	                        TextBoxWidth = 89
	                        TextboxX = 5
	 
	                        'Opis stroška
	                    Case 1
	                        TextBoxWidth = 177
	                        TextboxX = 99
	 
	                        'Konto
	                    Case 2
	                        TextBoxWidth = 60
	                        TextboxX = 281
	 
	                        'Kolicina
	                    Case 3
	                        TextBoxWidth = 60
	                        TextboxX = 346
	 
	                        'Cena
	                    Case 4
	                        TextBoxWidth = 60
	                        TextboxX = 411
	 
	                        'Kolicina
	                    Case 5
	                        TextBoxWidth = 89
	                        TextboxX = 476
	 
	                End Select
	 
	                With TextBoxes(num - 1)
	                    .Name = "Textbox" & ClickCount & num
	                    .Size = New Size(TextBoxWidth, 22)
	                    .Location = New System.Drawing.Point(TextboxX, yPosition)
	                End With
	 
	                Me.Controls.AddRange(New System.Windows.Forms.Control() {TextBoxes(num - 1)})
	            Next
	 
	        End If
	 
	        Dim Kolicina As Decimal
	        Dim Cena As Decimal
	 
	        If ClickCount = 0 Then
	 
	            For Each ctrl As Control In Me.Controls
	 
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 4 Then
	                    Kolicina = ctrl.Text
	                End If
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 5 Then
	                    Cena = ctrl.Text
	                End If
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 6 Then
	                    ctrl.Text = Kolicina * Cena
	                End If
	 
	            Next
	        Else
	 
	            For Each ctrl As Control In Me.Controls
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 4 Then
	                    Kolicina = ctrl.Text
	                End If
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 5 Then
	                    Cena = ctrl.Text
	                End If
	 
	                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 6 Then
	                    ctrl.Text = Kolicina * Cena
	                End If
	 
	            Next
	 
	        End If
	 
	        For Each ctrl As Control In Me.Controls
	 
	            If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 6 Then
	                ctrl.Enabled = False
	                ctrl.BackColor = Color.White
	 
	 
	            End If
	 
	        Next
	 
	        Button1.Location = New Point(571, yPosition)
	 
	        Me.Height = Me.Height + 30
	        ButtonPregled.Location = New Point(ButtonPregled.Location.X, ButtonPregled.Location.Y + 30)
	        PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + 30)
	        ButtonIzhod.Location = New Point(ButtonIzhod.Location.X, ButtonIzhod.Location.Y + 30)
	        ButtonTiskanje.Location = New Point(ButtonTiskanje.Location.X, ButtonTiskanje.Location.Y + 30)
	        PictureBox3.Location = New Point(PictureBox3.Location.X, PictureBox3.Location.Y + 30)
	        lblNotifySave.Location = New Point(lblNotifySave.Location.X, lblNotifySave.Location.Y + 30)
	        lblNotifyPrint.Location = New Point(lblNotifyPrint.Location.X, lblNotifyPrint.Location.Y + 30)
	        lblNotifyStorno.Location = New Point(lblNotifyStorno.Location.X, lblNotifyStorno.Location.Y + 30)
	 
	        ClickCount += 1
	 
	    End Sub


This post has been edited by AdamSpeight2008: 01 March 2011 - 03:21 PM
Reason for edit:: Removing Line Numbers


Is This A Good Question/Topic? 0
  • +

Replies To: sum values of dynamic textboxes

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9091
  • View blog
  • Posts: 34,142
  • Joined: 12-June 08

Re: sum values of dynamic textboxes

Posted 01 March 2011 - 01:47 PM

Dude, what gives? You've posted this in three other posts and now you made one yourself? WHY!?
Was This Post Helpful? 0
  • +
  • -

#3 razree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 01-March 11

Re: sum values of dynamic textboxes

Posted 01 March 2011 - 02:00 PM

View Postmodi123_1, on 01 March 2011 - 01:47 PM, said:

Dude, what gives? You've posted this in three other posts and now you made one yourself? WHY!?


Thought that opening a new topic is a bit inconsiderate if there are already topics regarding similar question. I just did not notice that I have posted in Java in vb6 topic... :S Why my own? Because I was instantly told that posting your own question in another persons topic is wrong...? And I thought this is the point...
Oh hell, we learn something every day... :)
Now I known how the forum works, let's look at my code shall we?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9091
  • View blog
  • Posts: 34,142
  • Joined: 12-June 08

Re: sum values of dynamic textboxes

Posted 01 March 2011 - 02:10 PM

Odd but fair enough. Do me a favor and edit your code to remove the text numbers on each line of your code (not the line numbers that appear BECAUSE you used the code tags). It appears you just did a copy (and not copy code) from a previous post or danny's web and dumped your code here. I don't have the time to go through and remove the numbers from 200ish lines of code so I can debug it for you.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9091
  • View blog
  • Posts: 34,142
  • Joined: 12-June 08

Re: sum values of dynamic textboxes

Posted 01 March 2011 - 02:19 PM

FYI those are not "text boxes", per say, showing up in the grid. They are grid cells.

Now I am confused. Where did you get this code from? I would like to see the whole thing to get an idea what it is doing.

This post has been edited by modi123_1: 01 March 2011 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2256
  • View blog
  • Posts: 9,444
  • Joined: 29-May 08

Re: sum values of dynamic textboxes

Posted 01 March 2011 - 03:17 PM

I'll edit the code to remove the line numbers.( Be Patient, it may take a while. :surrender: )
Was This Post Helpful? 0
  • +
  • -

#7 razree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 01-March 11

Re: sum values of dynamic textboxes

Posted 02 March 2011 - 01:16 AM

@modi123_1; tnx, next time I'll post without line numbers & I know now what grid cell are.

About the code; when started I knew what I would like the program is doing, gathered some pieces of code on the web, written some myself. Upper code is just a piece of one of the forms I have. Like I said, I have a button1 which (onclick) created six textboxes which are named like this: "ctrl.Name = "Textbox" & ClickCount - 1 & 4". -1 at clickcount is because I want that when button1 is clicked next time, it multiplyes values in previous row. Now this is part of a code where the point of my problem is:
Dim     Kolicina As Decimal
        Dim Cena As Decimal

        If ClickCount = 0 Then

            For Each ctrl As Control In Me.Controls

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 4 Then
                    'MessageBox.Show(ctrl.Name & " : " & Kolicina)
                    Kolicina = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 5 Then
                    'MessageBox.Show(ctrl.Name & " : " & Cena)
                    Cena = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount & 6 Then
                    ctrl.Text = Kolicina * Cena
                End If

            Next
        Else

            For Each ctrl As Control In Me.Controls
    
                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 4 Then
                    Kolicina = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 5 Then
                    Cena = ctrl.Text
                End If

                If TypeOf ctrl Is TextBox And ctrl.Name = "Textbox" & ClickCount - 1 & 6 Then
                    ctrl.Text = Kolicina * Cena
                End If
next 
end if



I'm not saying the code is wrong, I just need to add a function that notifyes me if "Textbox" & ClickCount - 1 & 4 and "Textbox" & ClickCount - 1 & 5 are empty (and than return to the form to fill in the values) and if not multiply their values in "Textbox" & ClickCount - 1 & 6 Then.

This post has been edited by AdamSpeight2008: 02 March 2011 - 04:54 AM

Was This Post Helpful? 0
  • +
  • -

#8 razree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 01-March 11

Re: sum values of dynamic textboxes

Posted 02 March 2011 - 01:24 AM

Forgot to say that the first part of code (If ClickCount = 0 Then) isn't relevant in this case (I think) because clickcount will always be different that 0.
Was This Post Helpful? 0
  • +
  • -

#9 razree  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 01-March 11

Re: sum values of dynamic textboxes

Posted 02 March 2011 - 03:23 AM

And in adition to that I want that on ever clickcount is checked if content of all previous "Textbox" & ClickCount - 1 & 4 or "Textbox" & ClickCount - 1 & 5 in upper rows has changed and if then multiply values again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1