Solved

vb TextBoxes

Posted on 2014-09-24
8
170 Views
Last Modified: 2014-09-25
Hi All
Creating new Textboxes

 dim txt as new system.windows.forms.textbox
 dim cnt as integer = 0

 on a tabpage button Click event create the textbox

 tabpage.controls.Add(txt)

 cnt = cnt + 1
 txt.top =  = 25
 txt.name = "TextNam" & cnt.tstring

Creating 5 or more new textboxes named textnam1 - 5

I would like to create a handler / check to ensure txtname1 2 & 3 have no contol over the entry but 4 integer and 5 currency entries only


Thanks
0
Comment
Question by:Kevinfeening
  • 4
  • 2
  • 2
8 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 40342985
you need to use AddHandler to bind your event to a method. See http://msdn.microsoft.com/en-us/library/6yyk8z93(v=vs.90).aspx
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 40342987
for 4 and 5, instead of a textbox, you should use a NumericUpDown control: http://www.dotnetheaven.com/article/numericupdown-control-in-vb.net
0
 
LVL 12

Expert Comment

by:ktaczala
ID: 40343224
*** I know using the try catch block in this manner is not good practice but I've seen it done in training videos.
For the integer textbox try:
        AddHandler txt.TextChanged, AddressOf Text_Changed
    Private Sub Text_Changed(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
        Try
            Dim i As Integer
            i = Int(txt.Text)
        Catch ex As Exception
            MsgBox("Invalid Character")
        End Try
    End Sub
0
 

Author Comment

by:Kevinfeening
ID: 40343284
Tried
 
Private Sub Text_Changed(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
         Try
             Dim i As Integer
             i = Int(txt.Text)

but txt.text errors txt not declared

This is along the lines I need
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 40343596
you need to use the eventsender:

Private Sub Text_Changed(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
         Try
             dim txt = directcast(eventsender, textbox)
             Dim i As Integer
             i = Int(txt.Text)

Open in new window

0
 

Author Comment

by:Kevinfeening
ID: 40343612
Thanks
But

i = Int(txt.Text)

now has error

Option strict on Disallows implicit conversion from object to integer
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 40343717
you can try:

integer.tryparse(txt.Text, i)

Open in new window

0
 
LVL 12

Assisted Solution

by:ktaczala
ktaczala earned 250 total points
ID: 40343864
again saw that you are inserting in a tabpage:
        AddHandler TabPage.Controls(txt.Name).TextChanged, AddressOf Text_Changed

   Private Sub Text_Changed(ByVal eventsender As System.Object, ByVal eventargs As System.EventArgs)
        Try
            Dim i As Integer
            i = CInt(Int(TabPage.Controls(txt.Name).Text))
        Catch ex As Exception
            MsgBox("Invalid Character")
        End Try
    End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now