Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vb TextBoxes

Posted on 2014-09-24
8
175 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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