Solved

vb TextBoxes

Posted on 2014-09-24
8
180 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

717 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