Solved

vb TextBoxes

Posted on 2014-09-24
8
165 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
Comment Utility
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
Comment Utility
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
Comment Utility
*** 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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
Comment Utility
you can try:

integer.tryparse(txt.Text, i)

Open in new window

0
 
LVL 12

Assisted Solution

by:ktaczala
ktaczala earned 250 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
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.
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…
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…

771 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

10 Experts available now in Live!

Get 1:1 Help Now