Solved

vb TextBoxes

Posted on 2014-09-24
8
172 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 70

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 70

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 
LVL 70

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 70

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 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