How to reuse textbox variable in two procedure

Hewlett-packard Hp 630
November 4, 2013 at 15:40:08
Specs: Windows 7, 2.399 GHz / 2997 MB
Hi guys, i'm working with on creating textbox at run time with lostfocus event. I generate variable of textbox in sub procedure GroupName with lostfocus event and second is lostfocus event to retrieve data from database and display it but the error is, if you declare the variable in first sub procedure, it will generate the set of textbox contineously in flowlayoutpanel but the variable cannot be use in second sub procedure. However, if you declare variable globally it will only generate set of textbox once flowlayoutpanel and stopped but you can reuse it in two or more subs to retrieve data from database... Please anyone with solution should kindly help me out

Public Sub GroupsName()

Dim cboTransType As New ComboBox
Dim txtAccount1 As New TextBox
Dim txtCurrentBal As New TextBox
Dim txtTitle As New TextBox
Dim txtMemoDescription As New TextBox
Dim cboInstrument As New ComboBox
Dim txtTypeNo As New TextBox
Dim txtNarration As New TextBox
Dim txtNarration2 As New TextBox
Dim txtAmount As New TextBox
Dim cboDebitCredit As New ComboBox
Dim txtFilled As New Label

cboTransType.Name = "TransType"
cboTransType.Width = 120
cboTransType.Height = 21
'AddHandler cboTransType.SelectedIndexChanged, AddressOf cboTransType_SelectedIndexChange
cboTransType.DropDownStyle = ComboBoxStyle.DropDownList
txtAccount1.Name = "Account No"
txtAccount1.Width = 100
txtAccount1.Height = 21
AddHandler txtAccount1.LostFocus, AddressOf txtAccount1_LostFocus
txtCurrentBal.Name = "Current Bal"
txtCurrentBal.Width = 100
txtCurrentBal.Height = 21
txtCurrentBal.ReadOnly = True
cboInstrument.Name = "Instrument"
cboInstrument.Width = 60
cboInstrument.Height = 21
cboInstrument.DropDownStyle = ComboBoxStyle.DropDownList
txtTypeNo.Name = "TypeNo"
txtTypeNo.Width = 83
txtTypeNo.Height = 21
txtNarration.Name = "Narration"
txtNarration.Width = 200
txtNarration.Height = 21
txtAmount.Name = ""
txtAmount.Width = 150
txtAmount.Height = 21
txtAmount.Text = ".00"
txtAmount.TextAlign = HorizontalAlignment.Right
txtAmount.ForeColor = Color.Blue
'' ''AddHandler txtAmount.LostFocus, AddressOf txtAmount_LostFocus
txtTitle.Name = "Title"
txtTitle.Width = 487
txtTitle.Height = 21
AddHandler txtTitle.TextChanged, AddressOf txtTitle_TextChanged
txtNarration2.Name = "Depositor"
txtNarration2.Width = 200
txtNarration2.Height = 21
cboDebitCredit.Name = "Debit Credit"
cboDebitCredit.Width = 150
cboDebitCredit.Height = 21
cboDebitCredit.DropDownStyle = ComboBoxStyle.DropDownList
txtMemoDescription.Name = "Memo Description"
txtMemoDescription.Width = 487
txtMemoDescription.Height = 21
txtFilled.Name = "Filled"
txtFilled.Width = 355
txtFilled.Height = 21
txtFilled.Enabled = False
'txtFilled.BackColor = Color.SkyBlue

End Sub

Private Sub txtAccount1_LostFocus(ByVal txtAccount1 As TextBox, ByVal e As System.EventArgs)

sqlfind = "select * from customer_account where account_no='" & txtAccount1.Text & "'"

dafind2 = New OleDb.OleDbDataAdapter(sqlfind, conn)
dafind2.Fill(dsfind, "customer_account")

If dsfind.Tables("customer_account").Rows.Count < 1 Then
MsgBox("Record not in Database", MsgBoxStyle.Critical, "No Records Found")
'Exit Sub
txtAccount1.Text = Trim(dsfind.Tables("customer_account").Rows(0).Item(5))

pd = Trim(dsfind.Tables("customer_account").Rows(0).Item(2))
If pd = Trim("pending") Then
MsgBox("Awaiting Approval", MsgBoxStyle.Information, "Approval")
Exit Sub
End If
txtTitle.Text = dsfind.Tables("customer_account").Rows(0).Item(9)
txtCurrentBal.Text = FormatNumber(Val(dsfind.Tables("customer_account").Rows(0).Item(23)))
txtCurrentBal.ForeColor = Color.Blue
txtCurrentBal.ReadOnly = True
txtCurrentBal.BackColor = Color.White
txtMemoDescription.Text = dsfind.Tables("customer_account").Rows(0).Item(8)
End If

End Sub

See More: How to reuse textbox variable in two procedure

Report •

November 5, 2013 at 05:07:21
I'm not sure I get the gist of what's happening here. You shouldn't need to store the text box in a non-local variable if you just need it for an event handler. The first parameter of any event handler is the object that fired that event.

How To Ask Questions The Smart Way

Report •

November 5, 2013 at 13:15:20
Thanks for looking to my problem. My problem is how to reuse txtTitle.text and txtMemoDescription.text in txtAccount1_Lostfocus event, bcus i wanted to call customer account to display name in txtTitle.text and txtMemoDescription.text. Meanwhile, GroupName is been called inside a button

But the issue here are; these two object are declare in Sub GroupName to generate at runtime. Therefore if you declare them globally it will generate the object in one row.

What i wanted is to generate set of TextBox and call (customer account) data from database to display them thank you.

message edited by Ruffy

Report •

Related Solutions

Ask Question