|
-
Sep 10th, 2008, 01:31 AM
#1
Thread Starter
Member
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
-
Sep 10th, 2008, 02:44 AM
#2
Member
Re: Bring messagebox from textbox
 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
-
Sep 10th, 2008, 03:07 AM
#3
Re: Bring messagebox from textbox
My Suggestions
vb Code:
Sub Test()
'Trim() will remove Leading and Trailing spaces before and
'after the text. Len() will give the length of the string.
'Together they will ensure that even when the user enters
'a blank space, it will prompt the user to enter a text
Select Case Len(Trim(Text1.Text))
Case 0
MsgBox "You have to input some text"
Case Is > 0
MsgBox Text1.Text
End Select
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
-
Sep 10th, 2008, 05:23 AM
#4
Thread Starter
Member
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
-
Sep 10th, 2008, 06:43 AM
#5
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
-
Sep 10th, 2008, 03:49 PM
#6
Thread Starter
Member
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
-
Sep 10th, 2008, 03:56 PM
#7
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
-
Sep 10th, 2008, 10:08 PM
#8
PowerPoster
Re: Bring messagebox from textbox
Text1.Text = "ABC ABC ABC"
MsgBox Text1.Text, 48, "Message"
-
Sep 11th, 2008, 05:28 AM
#9
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,...
-
Sep 11th, 2008, 06:21 AM
#10
Re: Bring messagebox from textbox
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|