|
-
Dec 30th, 2002, 10:28 PM
#1
Thread Starter
Lively Member
Newbie Question
Hi guys I'm a new student to VB, I am using VB 6 and love it. but I am fairly new and I need some help. ok I want to create a program that when a command button it pressed it automaticatly puts text into a text box.. (like predefined text)
for example
(command 1) when pressed will say hello in a text box (so that I can manipulate the text after in the text box.. so not a pop up. maybe a label not quick sure what term. thanks and love this site.
-
Dec 30th, 2002, 10:32 PM
#2
New Member
VB Code:
Private Sub Command1_Click()
Text1.Text = "Hello"
End Sub
-
Dec 30th, 2002, 10:32 PM
#3
PowerPoster
start a new project and drop a textbox control and a command button control on the form. Double click command button and make the code look like this:
VB Code:
Private Sub Command1_Click()
Text1.Text = "Hello World"
End Sub
-
Dec 30th, 2002, 10:58 PM
#4
Thread Starter
Lively Member
wow! Thanks
that worked great thanks.. I have another question..
I now have a text box and I want to have the text that I type in that text box to goto my main text2.
for for example.
( hello this is user 1 ) [Command1] if I type something in that text field I would like it to go to
[text field2]
User: hello this is user one
So I hope this makes sense.. so pretty much I have a text box I type anything in that box and press a command button that takes the value from my text1 and places it in text2 with a quick comment.
-
Dec 30th, 2002, 11:09 PM
#5
Lively Member
This places the contents of text1 into text2.
VB Code:
Private Sub Command1_Click()
text2.text = text1.text
End Sub
I suggest getting a book or searching google for Visual Basic tutorials. They seem to answer alot of "simple" questions.
-
Dec 30th, 2002, 11:17 PM
#6
Thread Starter
Lively Member
Thanks ..
I did get a VB book "well my brother left it here for me but it's not for beginners.." one last simple question what is the clear command.
to clear a text box? when a command button is pressed?
-
Dec 30th, 2002, 11:23 PM
#7
Lively Member
Well you could just use this
VB Code:
Private Sub Command1_Click()
text2.text = " "
End Sub
Im not really sure how effective this is... i have never really had to clear a textbox! So i hope that this helps 
--------------------------------------------
edit
-----------------------------------------------
if you want to clear all text boxes on a form:
VB Code:
Private Sub ClearAll()
Dim ctrl as Control
For each ctrl in me.controls
if typename(ctrl) = "TextBox" then
ctrl.text = ""
endif
next ctrl
End Sub
I found this on experts-exchange forum thought it might be useful
Last edited by killerSD; Dec 30th, 2002 at 11:32 PM.
-=]{ i ( ( er =-
-
Dec 31st, 2002, 12:20 AM
#8
Thread Starter
Lively Member
Question, thanks for all your help
I can now place text into text box2 however if I want to copy more than 1 word like a paragraph.. so command1
text1.text = " hello" works but what if I want to diplay a paragraph?
-
Dec 31st, 2002, 01:18 AM
#9
Thread Starter
Lively Member
Question
I'm having a difficult time with one thing. I can now send stuff to text2.. but I want to put a line break and send other stuff to text 2 (and not over right what command did..
so command 1 writes code to text2 I want command 2 to right code bellow text 2.. ect..
-
Dec 31st, 2002, 04:23 AM
#10
New Member
A small correction to the clearing code: be sure to use "" and not " ", which will put a space in the textbox.
As to the new question, you can do something like this:
VB Code:
Private Sub Command1_Click()
'If there is content in the box, add a line break
If Text2.Text <> "" Then
Text2.Text = Text2.Text & vbCrLf
End If
'Add text. Instead of the context of Text1
'you can use literal text or a string variable
Text2.Text = Text2.Text & Text1.Text
End Sub
Don't forget to set the Multiline property of your textbox to True.
-
Dec 31st, 2002, 04:47 AM
#11
Fanatic Member
-
Dec 31st, 2002, 11:09 AM
#12
Thread Starter
Lively Member
haha thanks..
Well my question is..
I'm having a difficult time with one thing. I can now send stuff to text2.. but I want to put a line break and send other stuff to text 2 (and not over right what command did..
Example:
command 1 (when pressed) writes code to text2
I want command 2 to right code bellow text 2.. ect..
because what is happening I have 2 commmand buttons, and they both once pressed fill out text2. the problem is they over write the text, I would like it to not over right the next use the next line. is there a line break I can put after? thanks..
-
Dec 31st, 2002, 11:17 AM
#13
If you want to add new text to a text box:
text2.text = text2.text & "The new text"
this takes the previous text of text2 and adds The new text to it.
To put in a new line use vbCrLf
text2.text = text2.text & "blah" & vbCrLf
Think of & as a plus sign for text.
so if you wanted to add 1 + 1 into a textbox you would say
text2.text = 1 + 1
but you use & for text adding the text together
text2.text = " Hello " & "world"
text2.text will of course say Hello world.
-
Dec 31st, 2002, 11:33 AM
#14
Fanatic Member
You can also clear like this:
VB Code:
Private Sub Command1_Click()
Text1.Text = Chr(0)
End Sub
Makes no diff, and about the text1.text = " ", remember space is still a charecter, so do "" like the above post says.
-
Dec 31st, 2002, 12:37 PM
#15
Thread Starter
Lively Member
I.E within VB
quick question I want to disply a webpage within my VB do I use a label?
for example I want it to display withing a box..
so www.lycos.com (entered in textbox1)
and would like it to
display withing another text box or label on the form?
-
Jan 1st, 2003, 03:33 AM
#16
Thread Starter
Lively Member
Question?!
How do you call a form, for example I want to be able to open up another form2. how do I do it? thank you.
-
Jan 1st, 2003, 08:13 AM
#17
Hyperactive Member
hi,
write this code in command1_click event
form2.show
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
|