Results 1 to 17 of 17

Thread: Newbie Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Question 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.

  2. #2
    New Member
    Join Date
    Dec 2002
    Location
    Brussels
    Posts
    6
    VB Code:
    1. Private Sub Command1_Click()
    2.     Text1.Text = "Hello"
    3. End Sub

  3. #3
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    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:
    1. Private Sub Command1_Click()
    2. Text1.Text = "Hello World"
    3. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Talking 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.

  5. #5
    Lively Member
    Join Date
    Dec 2002
    Location
    Under the Boardwalk
    Posts
    79
    This places the contents of text1 into text2.

    VB Code:
    1. Private Sub Command1_Click()
    2. text2.text = text1.text
    3. End Sub

    I suggest getting a book or searching google for Visual Basic tutorials. They seem to answer alot of "simple" questions.
    -=]{ i ( ( er =-

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Talking 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?

  7. #7
    Lively Member
    Join Date
    Dec 2002
    Location
    Under the Boardwalk
    Posts
    79
    Well you could just use this

    VB Code:
    1. Private Sub Command1_Click()
    2. text2.text = " "
    3. 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:
    1. Private Sub ClearAll()
    2. Dim ctrl as Control
    3. For each ctrl in me.controls
    4.  if typename(ctrl) = "TextBox" then
    5.    ctrl.text = ""
    6. endif
    7. next ctrl
    8. 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 =-

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Question 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?

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Question 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..

  10. #10
    New Member
    Join Date
    Dec 2002
    Location
    Brussels
    Posts
    6
    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:
    1. Private Sub Command1_Click()
    2.     'If there is content in the box, add a line break
    3.     If Text2.Text <> "" Then
    4.         Text2.Text = Text2.Text & vbCrLf
    5.     End If
    6.     'Add text. Instead of the context of Text1
    7.     'you can use literal text or a string variable
    8.     Text2.Text = Text2.Text & Text1.Text
    9. End Sub

    Don't forget to set the Multiline property of your textbox to True.

  11. #11
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    Exclamation DOH!

    DOH! I came too late, i wanted to answer those questions, cus its somet i actually know! unlike everything else...

    nvc, take their advise, its all right

    ask me somet pls aswell if u got time in a pm! I wana help somone... although probably the question u ask i wont know.... worth a try haha!




  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Talking 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..

  13. #13
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  14. #14
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    You can also clear like this:

    VB Code:
    1. Private Sub Command1_Click()
    2.     Text1.Text = Chr(0)
    3. End Sub

    Makes no diff, and about the text1.text = " ", remember space is still a charecter, so do "" like the above post says.
    asdf

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Question 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?

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Dec 2002
    Posts
    109

    Question 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.

  17. #17
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    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
  •  



Click Here to Expand Forum to Full Width