help with un working converted C# code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hie there,
im having problems Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms


Namespace WindowsApplication1
Public Partial Class CashOnHand
Inherits Form
Public Sub New()
InitializeComponent()
Dim fi As New System.IO.FileInfo(path)
Try


If fi.Exists Then
ds.ReadXml(path)
End If

If ds.Tables.Count <= 0 Then

dc = New DataColumn()
dc.DataType = System.Type.[GetType]("System.DateTime")
dc.ColumnName = "Date"
dc.Caption = "Date and Time "
dt.Columns.Add(dc)

dc = New DataColumn()
dc.DataType = System.Type.[GetType]("System.String")
dc.ColumnName = "Description"
dc.Caption = "Message to be display"
dt.Columns.Add(dc)

dc = New DataColumn()
dc.DataType = System.Type.[GetType]("System.String")
dc.ColumnName = "Cr"
dc.Caption = "Message to be display"
dt.Columns.Add(dc)

dc = New DataColumn()
dc.DataType = System.Type.[GetType]("System.String")
dc.ColumnName = "Dr"
dc.Caption = "Message to be display"
dt.Columns.Add(dc)

dc = New DataColumn()
dc.DataType = System.Type.[GetType]("System.String")
dc.ColumnName = "Amount"
dc.Caption = "Message to be display"
dt.Columns.Add(dc)
ds.Tables.Add(dt)
GetOpeningBalance()
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub

Private Sub GetOpeningBalance()
Object myValue =Microsoft.VisualBasic.Interaction.InputBox("Enter the Opening Balance or cash on hand", "Expenses Statement", "0");

Try

Dim dr As DataRow = ds.Tables(0).NewRow()
dr("Date") = DateTime.Now
dr("Description") = "Opening Balance"
dr("Cr") = "Cr"
dr("Dr") = "0.00"
Dim myValue As [String] = Microsoft.VisualBasic.Interaction.InputBox("Enter the Opening Balance or cash on hand", "Expenses Statement", "0", Me.Width 2, Me.Height 2)
If Microsoft.VisualBasic.Information.IsNumeric(myValue) Then
dr("Amount") = myValue
Else
dr("Amount") = 0.0
End If
ds.Tables(0).Rows.Add(dr)
ds.WriteXml(path)

Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try


End Sub


#Region "Global Declaration"


Public dt As New DataTable("CashOnHand")
Public ds As New DataSet()
Public dc As DataColumn
= new DataColumn();
Private path As [String] = Environment.CurrentDirectory & "Muhil.xml"
Private dv As New DataView()
#End Region

Private Sub btnSave_Click(sender As Object, e As EventArgs)
Try
Dim Boo As [Boolean] = PermitToSave()

If Boo = True Then
Save()
LoadCashOnHand()
Microsoft.VisualBasic.Interaction.Beep()
End If

Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
End Sub
Private Function PermitToSave() As [Boolean]

If txtDate.Text.Trim() = "" OrElse txtDate.Text.Trim().Length <> 10 Then

MessageBox.Show("Enter Date")
txtDate.Focus()
Return False
End If
If txtAmount.Text.Trim() = "" Then

MessageBox.Show("Enter Amount")
txtAmount.Focus()
Return False
End If
If DateChecking(txtDate.Text) = False Then
Return False
End If
Dim Amt As String = txtAmount.Text.Trim()
If Amt.Contains(".") Then
Dim substr As String() = Amt.Split("."C)
If substr.Length > 2 Then

MessageBox.Show("Amount Format Should be XXX.XX")
Return False
Else
If substr(1).ToString().Length <> 2 Then
MessageBox.Show("Amount Format Should be XXX.XX")
Return False

End If
End If
Else
txtAmount.Text = txtAmount.Text.Trim() & ".00"
End If

Return True

End Function
Private Function DateChecking(str As [String]) As [Boolean]
Dim temp As [Char]() = str.ToCharArray()
Dim Len As Int64 = str.Length

Dim Case10 As Int16() = {0, 1, 3, 4, 6, 7, _
8, 9}
Select Case Len
Case 10
For iLp As Integer = 0 To Case10.Length - 2

If CharChecking(Convert.ToInt16(temp(Case10(iLp)))) = False Then
errMsg()
Return False
End If
Next
Dim Mn As Int16 = Convert.ToInt16(str.Substring(3, 2))
If MonthChk(Mn) = False Then
errMsg()
Return False
End If
Exit Select
End Select
Return True
End Function
Private Sub errMsg()
MessageBox.Show("Enter Correct Date format should be 02-12-2009")
txtDate.Focus()

End Sub
Private Function MonthChk(Mon As Int16) As [Boolean]
If Mon < 1 OrElse Mon > 12 Then
Return False
End If
Return True
End Function
Private Function CharChecking(Val As Int16) As [Boolean]
If Val < 48 OrElse Val > 57 Then
Return False
End If
Return True
End Function
Private Sub Save()

Dim dr As DataRow = ds.Tables(0).NewRow()
DateTime dt = (DateTime)txtDate.Text;
dr("Date") = txtDate.Text.ToString()
dr("Description") = txtDesc.Text.Trim().ToUpper()
If CrDr.SelectedItem.ToString() = "Cr" Then
dr("Cr") = "Cr"
dr("Dr") = ""
Else

dr("Dr") = "Dr"
dr("Cr") = ""
End If
dr("Amount") = txtAmount.Text.Trim()
ds.Tables(0).Rows.Add(dr)
ds.WriteXml(path)

End Sub

Private Sub CashOnHand_Load(sender As Object, e As EventArgs)
CrDr.SelectedIndex = 1
LoadCashOnHand()
End Sub
Private Sub LoadCashOnHand()
PlsWaitEnabled()
Dim dr As Double = CalcDr()
Dim cr As Double = CalcCr()
lblCashOnHand.Text = Convert.ToString(cr - dr)
PlsWaitDisabled()
End Sub
Private Sub PlsWaitEnabled()
label3.Visible = True
txtDate.Enabled = False
txtDesc.Enabled = False
txtAmount.Enabled = False
CrDr.Enabled = False
End Sub
Private Sub PlsWaitDisabled()
label3.Visible = False
txtDate.Enabled = True
txtDesc.Enabled = True
txtAmount.Enabled = True
CrDr.Enabled = True
End Sub

Private Function CalcDr() As Double
label1.Text="Debit Amount is " + fnSplit("Dr");
Return fnSplit("Dr")

End Function
Private Function CalcCr() As Double
label2.Text = "Credit Amount is " + fnSplit("Cr");
Return fnSplit("Cr")

End Function
Private Function fnSplit(s As String) As Double

dv = ds.Tables(0).DefaultView
If s = "Dr" Then
dv.RowFilter = "Dr = Dr"
Else
dv.RowFilter = "Cr = Cr"
End If

Dim Amt As [Double] = 0
For i As Integer = 0 To dv.Count - 1

Amt = Amt + Convert.ToDouble(dv(i)(4))
Next

Return Amt
End Function

Private Sub CashOnHand_FormClosing(sender As Object, e As FormClosingEventArgs)
Me.Dispose()
End Sub

Private Sub txtDate_KeyPress(sender As Object, e As KeyPressEventArgs)
If (e.KeyChar < 48 OrElse e.KeyChar > 57) AndAlso e.KeyChar <> 45 AndAlso e.KeyChar <> 8 Then
e.Handled = True
End If
End Sub

Private Sub txtAmount_KeyPress(sender As Object, e As KeyPressEventArgs)
If (e.KeyChar < 48 OrElse e.KeyChar > 57) AndAlso e.KeyChar <> 46 AndAlso e.KeyChar <> 8 Then
e.Handled = True
End If
End Sub

Private Sub label10_Click(sender As Object, e As EventArgs)

End Sub



End Class


End Namespace
(cash at hand)


Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Namespace WindowsApplication1
Public Partial Class Statements
Inherits Form
#Region "Global Declaration"


Public dt As New DataTable("CashOnHand")
Public ds As New DataSet()
Public dc As DataColumn
= new DataColumn();
Private path As [String] = Environment.CurrentDirectory + "Muhil.xml"
Private dv As New DataView()

#End Region

Public Sub New()
InitializeComponent()
ds.ReadXml(path)
End Sub

Private Sub Statements_Load(sender As Object, e As EventArgs)

dataGridView1.DataSource = ds.Tables(0)
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
dataGridView1.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight




Dim Cr As Double = fnSplit("Cr")
Dim dr As Double = fnSplit("Dr")
label1.Text = "Total Cr value is =" & Cr
label2.Text = "Total Dr value is =" & dr
label3.Text = "Balance in Hand=" & (Cr - dr)

End Sub


Private Function fnSplit(s As String) As Double
dv = ds.Tables(0).DefaultView
If s = "Dr" Then
dv.RowFilter = "Dr = Dr"
Else
dv.RowFilter = "Cr = Cr"
End If

Dim Amt As [Double] = 0
For i As Integer = 0 To dv.Count - 1

Amt = Amt + Convert.ToDouble(dv(i)(4))
Next

Return Amt
End Function


Private Sub ReadExpensesList()

dv = ds.Tables[0].DefaultView;
dv.Sort = "Date Asc";
dataGridView1.DataSource = dv;
/dv.RowFilter="DateTime" ;
dataGridView1.DataSource = ds.Tables(0)
BindComboBox();

dataGridView1.Columns(4).Visible = False
dataGridView1.Columns(2).DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.BottomRight
dataGridView1.Columns(3).DefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.BottomRight

For Each row As DataGridViewRow In dataGridView1.Rows
if (row.IsNewRow) continue;
row.HeaderCell.Value = "Row " + rowNumber;
rowNumber = rowNumber + 1;

if (row.Index < dataGridView1.RowCount-1 )
{
Dim tmpdate As DateTime = Convert.ToDateTime(row.Cells(0).Value)
row.Cells(0).Value = tmpdate.ToString("dd/MM/yyyy")
If row.Cells(3).Value.ToString() = "Dr" Then
row.Cells(3).Value = row.Cells(4).Value
Else
row.Cells(3).Value = "0.00"
End If
If row.Cells(2).Value.ToString() = "Cr" Then
row.Cells(2).Value = row.Cells(4).Value
Else
row.Cells(2).Value = "0.00"

}
End If
Next

dv = ds.Tables[0].DefaultView;



End Sub
Private Sub BindComboBox()
Dim ds1 As New DataSet()
ds1.ReadXml(path)

Dim dvl As DataView = ds1.Tables(0).DefaultView
dvl.Sort = "Description"
For k As Integer = 0 To dvl.Count - 1
Dim dr As DataRowView() = dvl.FindRows(dvl(k)(1).ToString())
Dim tmplen As Integer = dr.Length
Dim tmpk As Integer = k
For j As Integer = 1 To tmplen - 1
dvl.Delete(tmpk)
tmplen = tmplen - 1
tmpk = tmpk + 1
Next
Next
cmbSelect.DataSource = ds1.Tables(0)
cmbSelect.DisplayMember = "Description"
cmbSelect.ValueMember = "Description"
End Sub

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
if (comboBox1.SelectedIndex == 1)
{
DateTime frm = DateTime.Parse("11/01/2008");
DateTime to = DateTime.Parse("11/30/2008");
FilterMonthWise(frm,to);
}
End Sub
Private Sub FilterMonthWise(FromDate As DateTime, ToDate As DateTime)
dv = ds.Tables(0).DefaultView
String filter = "Date > #"+FromDate + "#" + " and Date > #"+ ToDate + "#";//and Date < #"+ToDate+"#";
String filter = "Date > #" + FromDate + "#" + " and Date > #" + ToDate + "#";//and Date < #"+ToDate+"#";

dv.RowFilter = "date >= #01/12/2008# and date <= #30/12/2008#"
filter;//"Date > # " + FromDate +"# and Date < #" +ToDate +"#" ; //"Date month(birthdate)=3 //01/12/2008";
dv.Sort = "Date Asc"
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)

Dim frm As DateTime = DateTime.Parse("11/01/2008")
Dim [to] As DateTime = DateTime.Parse("01/01/2009")
FilterMonthWise(frm, to);
dv = ds.Tables(0).DefaultView
Dim s As [String] = cmbSelect.SelectedValue.ToString()
Dim filter As [String] = "Description = " & s & " and Date > #" & frm & "# and Date < #" & [to] & "#"
dv.RowFilter = "Description = " & s & " and Date >= #" & frm & "# and Date <= #" & [to] & "#"
+" and Date > #" + to + "#";
dv.Sort = "Date Asc"
Dim tmpcount As Integer = dv.Count
Dim crAmt As Double = CalcAmt(2, dv)
Dim drAmt As Double = CalcAmt(3, dv)
label1.Text = "Total Credit Value is :" & crAmt.ToString()
label2.Text = "Total Debit Value is :" & drAmt.ToString()

End Sub
Private Function CalcAmt(index As Integer, v As DataView) As Double
Dim amt As Double = 0
For i As Integer = 0 To v.Count - 1
amt = amt + Convert.ToDouble(dv(i)(index))
Next

Return amt
End Function
Private Sub cmbSelect_SelectedIndexChanged(sender As Object, e As EventArgs)
If cmbSelect.SelectedItem = "Dr" Then
Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = "Dr = Dr"
dataGridView1.DataSource = dv
Else
Dim dv As DataView = ds.Tables(0).DefaultView
dv.RowFilter = "Cr = Cr"
dataGridView1.DataSource = dv
End If
End Sub
End Class
End Namespace

(Statement)


Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Namespace WindowsApplication1
Public Partial Class ExpensesSheet
Inherits Form
Public Sub New()
InitializeComponent()
SetBackGroundColorOfMDIForm()
End Sub

Private Sub expensesSheetEntryToolStripMenuItem_Click(sender As Object, e As EventArgs)
Dim coh As New CashOnHand()
coh.Show()
coh.MdiParent = Me


End Sub

Private Sub fileToolStripMenuItem_Click(sender As Object, e As EventArgs)

End Sub
Private Sub SetBackGroundColorOfMDIForm()
For Each ctl As Control In Me.Controls
If TypeOf (ctl) Is MdiClient Then

ctl.BackColor = System.Drawing.Color.FloralWhite
End If
Next

End Sub

Private Sub statementsToolStripMenuItem_Click(sender As Object, e As EventArgs)
Dim stmt As New Statements()
stmt.Show()
stmt.MdiParent = Me
End Sub

Private Sub exitToolStripMenuItem_Click(sender As Object, e As EventArgs)
Me.Close()
End Sub

Private Sub ExpensesSheet_Load(sender As Object, e As EventArgs)
Dim dt As DateTime = DateTime.Now

toolStripStatusLabel2.Text = dt.ToShortDateString()
End Sub

End Class
End Namespace

(Main Menu)















to use these codes i converted from c# to vb.net. when i use them the application does not respond" to any event. can someone help please?
codes attached.
thanks in advance.

View the full article
 
Back
Top