Advertisement
Zidinjo

Vba

Apr 6th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.30 KB | None | 0 0
  1. Public Sub clearFormulare(ByVal newControl As Controls, ByVal rowFormulare As Integer, ByVal columnPerRow As Integer, ByVal nameOfInput As String, ByVal inputDigit As Integer, ByVal inputRange As String)
  2.  
  3. For i = 1 To (rowFormulare * columnPerRow) + 1
  4.         newControl(nameOfInput & i).Value = ""
  5. Next i
  6.  
  7. Tabelle2.Cells(inputDigit, inputRange).Value = 0
  8. Tabelle2.Cells(inputDigit, inputRange).Interior.ColorIndex = 0
  9. End Sub
  10.  
  11. Public Sub returnValues(ByVal newControl As Controls, ByVal saveColumn As Integer, ByVal nameOfInput As String, ByVal uniqNumber As Integer)
  12.  
  13. Dim countOfTextboxes As Integer
  14. Dim endPoint As Integer
  15.  
  16. For i = 1 To (uniqNumber) - 1
  17.     endPoint = endPoint + GetSetting("SaveData", "startFrom", i)
  18. Next i
  19.  
  20. 'dont override the last value of the calculate before from class one
  21. endPoint = endPoint + 1
  22. For countOfTextboxes = 1 To GetSetting("SaveData", "EndPoint", 2)
  23.     newControl(nameOfInput & countOfTextboxes).Value = Tabelle6.Cells(saveColumn, endPoint).Value
  24.     endPoint = endPoint + 1
  25. Next countOfTextboxes
  26.  
  27. End Sub
  28.  
  29. Public Sub buttonBerechnung(ByVal newControl As Controls, ByVal nameOfInput As String, ByVal saveColumn As Integer, ByVal inputRange As String, ByVal inputDigit As Integer, ByVal rowFormulare As Integer, ByVal columnPerRow As Integer, ByVal uniqNumber As Integer)
  30.  
  31. Dim countOfTextboxes As Integer
  32. Dim allInformations() As Double
  33. Dim valueTax As Double
  34. Dim decimalPlaces As Integer
  35. Dim eigcounter As Integer
  36. Dim resultOfCalculate As Double
  37. Dim queueOfClass As Integer
  38.  
  39. 'Define var
  40. valueTax = 1.19
  41. decimalPlaces = 2
  42. eigcounter = 1
  43. queueOfClass = 2
  44.  
  45. ReDim allInformations(rowFormulare, columnPerRow)
  46.  
  47. For i = 1 To rowFormulare
  48.     For j = 1 To columnPerRow
  49.         If (newControl(nameOfInput & eigcounter) = "") Then
  50.             allInformations(i, j) = 0
  51.         Else
  52.             allInformations(i, j) = newControl(nameOfInput & eigcounter)
  53.         End If
  54.         eigcounter = eigcounter + 1
  55.     Next j
  56. Next i
  57.  
  58. 'Calculate brutto netto of input
  59. '1 = amount z.B Quadratmeter
  60. '2 = single price netto
  61. '3 = total netto
  62. '4 = single price brutto
  63. '5 = total brutto
  64.     For i = 1 To rowFormulare
  65.         For j = 2 To columnPerRow
  66.             If (allInformations(i, j) > 0) Then
  67.                 Select Case j
  68.                     'If input is single price and amount
  69.                     Case 2
  70.                         allInformations(i, 3) = allInformations(i, 1) * allInformations(i, 2)
  71.                         newControl(nameOfInput & 3 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 3), decimalPlaces)
  72.                         allInformations(i, 4) = allInformations(i, 2) * valueTax
  73.                         newControl(nameOfInput & 4 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 4), decimalPlaces)
  74.                        
  75.                         allInformations(i, 5) = allInformations(i, 4) * allInformations(i, 1)
  76.                         newControl(nameOfInput & 5 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 5), decimalPlaces)
  77.                     'If input is total netto and amount
  78.                     Case 3
  79.                         allInformations(i, 2) = (allInformations(i, 2) / valueTax)
  80.                         newControl(nameOfInput & 2 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 2), decimalPlaces)
  81.                        
  82.                         allInformations(i, 3) = allInformations(i, 2) * allInformations(i, 1)
  83.                         newControl(nameOfInput & 3 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 3), decimalPlaces)
  84.                        
  85.                         allInformations(i, 5) = allInformations(i, 4) * allInformations(i, 1)
  86.                         newControl(nameOfInput & 5 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 5), decimalPlaces)
  87.                     'If input is single brutto and amount
  88.                     Case 4
  89.                         allInformations(i, 2) = allInformations(i, 3) / allInformations(i, 1)
  90.                         newControl(nameOfInput & 2 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 2), decimalPlaces)
  91.                        
  92.                         allInformations(i, 4) = allInformations(i, 2) * valueTax
  93.                         newControl(nameOfInput & 4 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 4), decimalPlaces)
  94.                        
  95.                         allInformations(i, 5) = allInformations(i, 4) * allInformations(i, 1)
  96.                         newControl(nameOfInput & 5 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 5), decimalPlaces)
  97.  
  98.                     'If input is total brutto and amount
  99.                     Case 5
  100.                         allInformations(i, 4) = allInformations(i, 5) / allInformations(i, 1)
  101.                         newControl(nameOfInput & 4 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 4), decimalPlaces)
  102.                        
  103.                         allInformations(i, 2) = (allInformations(i, 4) / valueTax)
  104.                         newControl(nameOfInput & 2 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 2), decimalPlaces)
  105.                        
  106.                         allInformations(i, 3) = allInformations(i, 2) * allInformations(i, 1)
  107.                         newControl(nameOfInput & 3 + (columnPerRow * (i - 1))).Value = Round(allInformations(i, 3), decimalPlaces)
  108.                     Case Else
  109.                    End Select
  110.                 'Otherwise all cases will be true and the program calculate all cases
  111.                 j = columnPerRow
  112.           End If
  113.         Next j
  114.     Next i
  115.  
  116. 'result
  117. For indexOfResult = 1 To rowFormulare
  118.      resultOfCalculate = resultOfCalculate + allInformations(indexOfResult, 5)
  119. Next indexOfResult
  120. newControl(nameOfInput & ((rowFormulare * columnPerRow) + 1)).Value = resultOfCalculate
  121.  
  122. 'painting the cell of the destination > 0
  123. With Tabelle2
  124.     If (resultOfCalculate <> 0) Then
  125.         .Cells(inputDigit, inputRange).Value = resultOfCalculate
  126.         'Tabelle2.Cells(inputDigit, inputRange).NumberFormat = "#,##0.00 $"
  127.         .Cells(inputDigit, inputRange).Interior.ColorIndex = 15
  128.     Else
  129.         .Cells(inputDigit, inputRange).Value = 0
  130.         .Cells(inputDigit, inputRange).Interior.ColorIndex = 0
  131.     End If
  132. End With
  133.  
  134. 'save the data
  135. 'Find out how much textboxes are in the controlfield
  136. 'For Each c In Me.Controls
  137. '    If TypeName(c) = "TextBox" Then
  138. '        countOfTextboxes = countOfTextboxes + 1
  139. '    End If
  140. 'Next
  141.  
  142. 'save information to table 6
  143. 'Every Formulare get a unique id which help to find out the correct position of class in save table
  144.  
  145. Dim z As Integer
  146. SaveSetting "SaveData", "startFrom", uniqNumber, GetSetting("SaveData", "EndPoint", queueOfClass)
  147.  
  148. 'Its nessesary to fill the textboxes with values
  149. Dim muchTextboxes
  150. muchTextboxes = ((rowFormulare * columnPerRow) + 1)
  151. SaveSetting "SaveData", "EndPoint", uniqNumber, muchTextboxes
  152.  
  153. For b = 1 To (uniqNumber - 1)
  154.     z = z + GetSetting("SaveData", "startFrom", b)
  155. Next b
  156.  
  157. 'To get a gape between the classes
  158. z = z + 1
  159.  
  160. For k = 1 To rowFormulare
  161.     For h = 1 To columnPerRow
  162.         Tabelle6.Cells(saveColumn, z).Value = allInformations(k, h)
  163.         z = z + 1
  164.     Next h
  165. Next k
  166. 'For the resultBox
  167. Tabelle6.Cells(saveColumn, z).Value = resultOfCalculate
  168.  
  169. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement