borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Database)Next Topic (Create an ini file) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Dynamic Changing Text... Please Help me.
Poster Message
phantom coder
Level: Trainee

Registered: 28-10-2009
Posts: 1

Ads by Lake Quincy Media
icon Dynamic Changing Text... Please Help me.

I have 3 textboxes and 3 labels and using the keypress event i can get it to dynamically change the text in the labels correct except the first letter does not show up until i press the second letter and the last letter does not show up until i press another key.

Also on the formatting issues the third format where I use a , in the formatting it shows up like this in the label.text as ,Phanto until i switch to another textbox and press a key then it will show up as Pantom, the m shows up and the comma goes tot he correct place and if i press another key then the C in coder shows up but the o in coder is still not there until i press another key.

the follow is the code im using.

Public Class Form1
   'Declare the varibles
    Dim FirstText As String
    Dim MiddleText As String
    Dim LastText As String



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initializes the varibles
        FirstText = ""
        MiddleText = ""
        LastText = ""
        Label5.Text = FirstText
        Label6.Text = MiddleText
        Label7.Text = LastText
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        'Combines all the data into a string
        FirstText = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
        MiddleText = TextBox3.Text + " " + TextBox1.Text + " " + TextBox2.Text
        LastText = TextBox3.Text + ", " + TextBox1.Text + " " + TextBox2.Text
        
        'Fills the label.text fields
        Label5.Text = FirstText
        Label6.Text = MiddleText
        Label7.Text = LastText
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        FirstText = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
        MiddleText = TextBox3.Text + " " + TextBox1.Text + " " + TextBox2.Text
        LastText = TextBox3.Text + ", " + TextBox1.Text + " " + TextBox2.Text
        Label5.Text = FirstText
        Label6.Text = MiddleText
        Label7.Text = LastText
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        FirstText = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
        MiddleText = TextBox3.Text + " " + TextBox1.Text + " " + TextBox2.Text
        LastText = TextBox3.Text + ", " + TextBox1.Text + " " + TextBox2.Text
        Label5.Text = FirstText
        Label6.Text = MiddleText
        Label7.Text = LastText
    End Sub


End Class


With the combobox i really have a problem but that can be sorted out after i get the dynamic text updating to work properly.

anyhelp will be greatfull I looked for a change or onchange event within the textbox but found none, i also tryied textchanged event and it did not work at all.

BTW i use vb.net 2k3,2k5,2k8 and 2k10


____________________________
All Things Possible Thru Code!

The Phantom

28-10-2009 at 05:39 PM
View Profile Send Email to User Show All Posts | Quote Reply
GeoffS
Level: VB Lord


Registered: 29-09-2004
Posts: 606
icon Re: Dynamic Changing Text... Please Help me.

The problems you are having are because you are using the wrong Event to read the Text property of the TextBox Control.
The KeyPress Event occurs BEFORE the value of the pressed key reaches the TextBox, that is the reason for the Event, it allows you to intercept keystrokes and modify them if necessary before the data is entered into the TextBox. An example of why you would use this is where you want to prevent letters from being inserted into a field that should only contain numbers.
Use the TextChanged Event to read the updated contents of your TextBox.


____________________________
multi-tasking - the ability to hang more than one app. at the same time.

Ads by Lake Quincy Media
29-10-2009 at 03:41 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Dynamic Changing Text... Please Help me.
Previous Topic (Database)Next Topic (Create an ini file) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2010 Andrea Tincaniborder