Results 1 to 10 of 10

Thread: Bring messagebox from textbox

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    58

    Bring messagebox from textbox

    Hi
    I have a textbox and the users type something there.. Now there is a button and i want when you pust the button a message will appear(Messagebox) with the text that exist in the textbox.. if the textbox is empty bring an another message "like sorry you have to type something"... Any code ideas....
    Thanks

  2. #2
    Member
    Join Date
    Aug 2008
    Posts
    59

    Re: Bring messagebox from textbox

    Quote Originally Posted by Leite33
    Hi
    I have a textbox and the users type something there.. Now there is a button and i want when you pust the button a message will appear(Messagebox) with the text that exist in the textbox.. if the textbox is empty bring an another message "like sorry you have to type something"... Any code ideas....
    Thanks
    use an if statement.

    Code:
    if txtInput.text = "" then
    msgbox "You have to input some text"
    else
    msgbox txtInput.text
    end if

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Bring messagebox from textbox

    My Suggestions

    vb Code:
    1. Sub Test()
    2.     'Trim() will remove Leading and Trailing spaces before and
    3.     'after the text. Len() will give the length of the string.
    4.     'Together they will ensure that even when the user enters
    5.     'a blank space, it will prompt the user to enter a text
    6.     Select Case Len(Trim(Text1.Text))
    7.     Case 0
    8.         MsgBox "You have to input some text"
    9.     Case Is > 0
    10.         MsgBox Text1.Text
    11.     End Select
    12. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    58

    Re: Bring messagebox from textbox

    Thanks guys.. This site is great. Everyone can learn.. And what about if the case of if is number for example...
    I wanna check the textbox if its number ok else bring a message that you have to put numbers... Generall check if its number or letter

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Bring messagebox from textbox

    Either
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 32 To 64, 91 To 96, 123 To 126
            MsgBox ("Must be a letter! Please try again!")
            KeyAscii = 0
            Exit Sub
    End Select
    End Sub
    
    'also place this code in the change event
    Private Sub Text1_Change()
        If IsNumeric(Text1.Text) Then
           MsgBox "Only Letters Are Allowed"
           Text1.Text = ""
           Exit Sub
        End If
    End Sub
    Or
    Code:
    'Place in keypress event of text box to prevent
    'typing in non numeric text
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 46 And KeyAscii <> 13 Then
        MsgBox "Only numbers are allowed for this entries"
        KeyAscii = 0
        Exit Sub
    End If
    End Sub
    
    'also, in the change event put this code
    'to prevent pasting in non numeric text
    Private Sub Text1_Change()
    If Not IsNumeric(Text1.Text) Then
       MsgBox "Only Numbers Are Allowed"
       Text1.Text = vbNullString
       Exit Sub
    End If
    End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2008
    Posts
    58

    Re: Bring messagebox from textbox

    Wow thanks...
    If i want for example 2 TextBoxes... And i wanna write a if statement to check both Text boxes what is the symbols....
    To be more specifiec:

    If Text1.Text="Car" .... and (the symbol) Text2.Text="Cat"
    same with or
    How the syntaz will be so check the boxes for and or for or

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Bring messagebox from textbox

    For VB it is just the words And/Or, eg:
    Code:
    If Text1.Text="Car" And Text2.Text="Cat" Then

  8. #8
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Bring messagebox from textbox

    Text1.Text = "ABC ABC ABC"

    MsgBox Text1.Text, 48, "Message"

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Bring messagebox from textbox

    Code:
    If Text1.Text="Car" And Text2.Text="Cat" Then
    Code:
    If Text1.Text="Car" Or Text2.Text="Cat" Then

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Bring messagebox from textbox

    Quote Originally Posted by Leite33
    Wow thanks...
    If i want for example 2 TextBoxes... And i wanna write a if statement to check both Text boxes what is the symbols....
    To be more specifiec:

    If Text1.Text="Car" .... and (the symbol) Text2.Text="Cat"
    same with or
    How the syntaz will be so check the boxes for and or for or
    Whether you use AND or OR will depend on what you need to check for.

    AND will require BOTH be true
    OR will only require one to be true

    In akhileshbc's example, the first statement will evaluate to True ONLY is Car is in text1 and Cat is in text2 - anything else will evaluate to False

    In the second example, True will be returned if only one it correct.

    A very common new person mistake is using AND when you actually need OR, or, vice versa.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width