Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
dataman86 said:You can't enter data into the table
Public Class Pull
Private Function TestIt() As DataTable
Dim sParm As String = Chr(39) & Me.TextBox1.Text.ToString & Chr(39)
Dim tParm As String = Chr(39) & Me.TextBox2.Text.ToString & Chr(39)
Dim uParm As String = Chr(39) & Me.TextBox3.Text.ToString & Chr(39)
Dim vParm As String = Chr(39) & Me.TextBox4.Text.ToString & Chr(39)
Dim wParm As String = Chr(39) & Me.TextBox5.Text.ToString & Chr(39)
Dim connectionString As String = "Data Source=10.3.3.248; " & _
"Initial Catalog=PROD; " & _
"Persist Security Info=True; " & _
"User ID=lawson; " & _
"Password=lawson"
Dim sSQL As String = "SELECT COMPANY, FISCAL_YEAR, ACCT_PERIOD, CONTROL_GROUP, LINE_NBR, POSTING_DATE, OBJ_ID, STATUS, ACCT_UNIT, ACCOUNT, TRAN_AMOUNT, ACCT_AMOUNT, VAR_LEVELS FROM GLTRANS WHERE COMPANY = " & sParm & " AND FISCAL_YEAR = " & tParm & " AND ACCT_PERIOD = " & uParm & " AND CONTROL_GROUP = " & vParm & " AND POSTING_DATE = " & wParm & ";"
Dim oCn As New SqlConnection(connectionString)
Dim oCm As New SqlCommand(sSQL, oCn)
oCm.CommandType = CommandType.Text
Dim oDa As New SqlDataAdapter(oCm)
Dim oTable As New DataTable()
oCn.Open()
oDa.Fill(oTable)
oCn.Close()
oCn.Dispose()
Return oTable
End Function
Private Sub BtnPull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPull.Click
Me.Hide()
Dim dt As DataTable
dt = TestIt()
[Red]dt.Columns.Add("Type", System.Type.GetType("System.String"))[/Red] 'Add a blank column to the data table
Dim rc As New Record_frm(dt, 12)
rc.Show()
End Sub
End Class
Public Class Record_frm
Dim FormTable As DataTable
Public Sub New(ByVal CurrentData As DataTable, ByVal MaxRows As Integer)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
SetupForm(CurrentData, MaxRows)
End Sub
Private Sub SetupForm(ByVal cData As DataTable, ByVal mRows As Integer)
Dim Row, Column, X, Y, RowHeight, RowSpace As Integer
RowHeight = 42
RowSpace = 35
For Row = 0 To mRows - 1
For Column = 0 To cData.Columns.Count - 1
Y = RowHeight + (RowSpace * Row)
Dim tb As New TextBox
With tb
.Name = "TextBox" & Format(Row, "00") & Format(Column, "00")
'Add Text
Dim TextData As String = ""
If IsDBNull(cData.Rows(Row).Item(Column)) = False Then TextData = cData.Rows(Row).Item(Column)
.Text = TextData
'Calculate location
If Column = 0 Then
X = 38
Else
Dim LastTB As TextBox = Me.Controls("TextBox" & Format(Row, "00") & Format((Column - 1), "00"))
X = (LastTB.Location.X + LastTB.Width) + 6 'Default padding between controls is 6.
End If
.Location = New Point(X, Y)
'Set size
Select Case Column
Case 0, 1, 2, 3 ' These tb are almost the same size already so lets make them the same size.
.Size = New Size(39, RowHeight)
Case 4 ' Is there a reason this one is so much bigger? If not add to above case.
.Size = New Size(46, RowHeight)
Case 5, 6
.Size = New Size(35, RowHeight)
Case 7, 8
.Size = New Size(42, RowHeight)
Case 9
.Size = New Size(83, RowHeight)
Case 10, 11, 12, 13 ' these tb are almost the same size already so lets make them the same size.
.Size = New Size(92, RowHeight)
Case Else
.Size = New Size(42, RowHeight)
End Select
End With
Me.Controls.Add(tb)
Next
Next
'Use below if you want to autocalculate form size
Dim FinalTB As String = "TextBox00" & Format((cData.Columns.Count - 1), "00")
Me.Width = (Me.Controls(FinalTB).Location.X + Me.Controls(FinalTB).Width) + Me.Controls("TextBox0000").Location.X * 2
Me.Height = RowHeight + (RowSpace * (mRows + 2))
End Sub
End Class
Public Class Record_frm
Dim FormTable As DataTable
Dim FormRows As Integer
Dim FormPages As Integer
Public Sub New(ByVal CurrentData As DataTable, ByVal MaxRows As Integer)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
FormTable = CurrentData
FormRows = MaxRows
FormPages = Decimal.Ceiling(CurrentData.Rows.Count / MaxRows)
SetupForm()
End Sub
Private Sub SetupForm()
Dim Row, Column, X, Y, RowHeight, RowSpace As Integer
Dim PageTotal As Decimal
RowHeight = 42
RowSpace = 35
For Row = 0 To FormRows - 1
For Column = 0 To FormTable.Columns.Count - 1
Y = RowHeight + (RowSpace * Row)
Dim tb As New TextBox
With tb
.Name = "TextBox" & Format(Row, "00") & Format(Column, "00")
'Add Text
Dim TextData As String = ""
If IsDBNull(FormTable.Rows(Row).Item(Column)) = False Then TextData = FormTable.Rows(Row).Item(Column)
.Text = TextData
'Calculate location
If Column = 0 Then
X = 38
Else
Dim LastTB As TextBox = Me.Controls("TextBox" & Format(Row, "00") & Format((Column - 1), "00"))
X = (LastTB.Location.X + LastTB.Width) + 6 'Default padding between controls is 6.
End If
.Location = New Point(X, Y)
'Set size
Select Case Column
Case 0, 1, 2, 3 ' These tb are almost the same size already so lets make them the same size.
.Size = New Size(39, RowHeight)
Case 4 ' Is there a reason this one is so much bigger? If not add to above case.
.Size = New Size(46, RowHeight)
Case 5, 6
.Size = New Size(35, RowHeight)
Case 7, 8
.Size = New Size(42, RowHeight)
Case 9
.Size = New Size(83, RowHeight)
Case 10, 11, 12, 13 ' these tb are almost the same size already so lets make them the same size.
.Size = New Size(92, RowHeight)
Case Else
.Size = New Size(42, RowHeight)
End Select
End With
Me.Controls.Add(tb)
Next
'change below to the correct column to calculate
If IsDBNull(FormTable.Rows(Row).Item(0)) = False Then
PageTotal += FormTable.Rows(Row).Item(3)
End If
Next
'Use below if you want to autocalculate form size
Dim FinalTBName As String = "TextBox00" & Format((FormTable.Columns.Count - 1), "00")
Dim FinalTB As TextBox = Me.Controls(FinalTBName)
Me.Width = (FinalTB.Location.X + FinalTB.Width) + Me.Controls("TextBox0000").Location.X '* 2
Me.Height = RowHeight + (RowSpace * (FormRows + 2))
Dim BtnSize As New Size(25, 23)
Dim BottomRow As Integer = RowHeight + (RowSpace * (FormRows))
Dim PreviousBtn As New Button
PreviousBtn.Name = "previous_btn"
PreviousBtn.Text = "<-"
PreviousBtn.Size = BtnSize
PreviousBtn.Location = New Point(38, BottomRow)
PreviousBtn.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
AddHandler PreviousBtn.Click, AddressOf PreviousPage
Me.Controls.Add(PreviousBtn)
Dim PageLbl As New Label
PageLbl.Name = "page_lbl"
PageLbl.Text = "001"
PageLbl.TextAlign = ContentAlignment.MiddleCenter
PageLbl.Size = New Size(30, 23)
PageLbl.Location = New Point((38 + PreviousBtn.Width), BottomRow)
PageLbl.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Controls.Add(PageLbl)
Dim NextBtn As New Button
NextBtn.Name = "next_btn"
NextBtn.Text = "->"
NextBtn.Size = BtnSize
NextBtn.Location = New Point((38 + PreviousBtn.Width + PageLbl.Width), BottomRow)
NextBtn.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
AddHandler NextBtn.Click, AddressOf NextPage
Me.Controls.Add(NextBtn)
Dim PageTotalTB As New TextBox
PageTotalTB.Name = "pagetotal_tb"
PageTotalTB.Text = PageTotal
PageTotalTB.Size = New Size(50, 23)
PageTotalTB.Location = New Point((FinalTB.Location.X + FinalTB.Size.Width) - PageTotalTB.Width, BottomRow)
PageTotalTB.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Controls.Add(PageTotalTB)
Dim PageTotalLbl As New Label
PageTotalLbl.Name = "page_lbl"
PageTotalLbl.Text = "Page Total"
PageTotalLbl.TextAlign = ContentAlignment.MiddleLeft
PageTotalLbl.Size = New Size(65, 23)
PageTotalLbl.Location = New Point((PageTotalTB.Location.X - (PageTotalLbl.Width)), BottomRow)
PageTotalLbl.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Controls.Add(PageTotalLbl)
End Sub
Private Sub PreviousPage(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim PageNumber As Integer = Me.Controls("page_lbl").Text
If PageNumber > 1 Then
PageNumber -= 1
SelectPage(PageNumber)
Me.Controls("page_lbl").Text = Format(PageNumber, "000")
End If
End Sub
Private Sub NextPage(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim PageNumber As Integer = Me.Controls("page_lbl").Text
If PageNumber < FormPages Then
PageNumber += 1
SelectPage(PageNumber)
Me.Controls("page_lbl").Text = Format(PageNumber, "000")
End If
End Sub
Private Sub SelectPage(ByVal PageNumber As Integer)
Dim NewPageTotal As Decimal = 0.0
Dim StartRow As Integer = (PageNumber * FormRows) - 1
If StartRow < FormTable.Rows.Count - 1 Then
For Rows As Integer = 0 To FormRows - 1
For Columns As Integer = 0 To 13
If IsDBNull(FormTable.Rows(StartRow + Rows).Item(Columns)) = False Then
Me.Controls("TextBox" & Format(Rows, "00") & Format(Columns, "00")).Text = FormTable.Rows(StartRow + Rows).Item(Columns)
Else
Me.Controls("TextBox" & Format(Rows, "00") & Format(Columns, "00")).Text = ""
End If
Next
'change below to the correct column to calculate
NewPageTotal += FormTable.Rows(StartRow + Rows).Item(3)
Next
End If
Me.Controls("pagetotal_tb").Text = NewPageTotal
End Sub
End Class
Generally you don't want to do calculations on the form. What you want to do is run calculations from the DataTable like I did for the Page Total. BTW you want to change the row calculated to the row you needed calculated.Do you know if I can reference the textboxes that are named such as TextBoxoo + TextBox01 + TextBox02 and so on on the new ainstance of the form each time. It is important to be able to do calculations with the named textboses.
variable = format(.GetValue(6), "0.0")
variable = format(ctype(.GetValue(6), Decimal), "0.0")
sParams(iLvalue, 6) = .GetValue(6).ToString()
sParams(iLvalue, 6) = format(.GetValue(6), "0.0")
sParams(iLvalue, 6) = format(ctype(.GetValue(6), Decimal), "0.0")