Results 1 to 13 of 13

Thread: visual basic 6.0 question

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    4

    Red face visual basic 6.0 question

    I have a form with three text boxes and a command button. I have to write the instructions such that when the button is pressed the strings in txtBox1 and txtBox2 are concatenated and the results are displayed in txtOutput. Can you please show me how this is done?
    Thank you

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Private Sub Command1_Click()
    Text3.Text = Text1 & Text2
    End Sub

    something like that?

  3. #3
    Member
    Join Date
    Nov 2001
    Posts
    42
    code:


    txtbox3 = txtbox1.text + txtbox2.text

    if they r numbers then

    txtbox3 = val(txtbox1.text) + val(txtbox2.text)

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350

    Don't listen to him.....

    Originally posted by holy1
    code:


    txtbox3 = txtbox1.text + txtbox2.text

    Don't concatenate strings with +, use & as Major da Silvy said. Then read my signature
    .

  5. #5
    Member
    Join Date
    Nov 2001
    Posts
    42

    Question

    whats the harm in using "+" ?

  6. #6
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    For one, if you use Val() and +, it will add them not concatenate them.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  7. #7
    Member
    Join Date
    Nov 2001
    Posts
    42
    i know that

    didnt u read "IF THEY ARE NUMBERS THEN" USE VAL() else

    dont use them

  8. #8
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Yes, I did read that part and that was why I said what I said, if you use Val() and Text1 = 3 and Text2 = 3 then you would have 6 not 33. So you would be ADDING not CONCATENATING, so you would never use the Val() function with concatenation!
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  9. #9
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Or like this if you happened to need a space between them

    Code:
    Private Sub Command1_Click() 
    
    Text3.Text = Text1 & " " & Text2 
    
    End Sub
    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  10. #10
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    i use
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Text3.Text = Text1.text & " " & Text2.text
    4.  
    5. End Sub


    like JO does i think that is the best way to do it and the easyist

  11. #11
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    i use
    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3. Text3.Text = Text1.text & " " & Text2.text
    4.  
    5. End Sub


    like JO does i think that is the best way to do it and the easyist

  12. #12
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by holy1
    i know that

    didnt u read "IF THEY ARE NUMBERS THEN" USE VAL() else

    dont use them
    no one reads any more

    like motox posted same thing twice and it was already posted

  13. #13
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    350

    MSDN....

    Originally posted by holy1
    whats the harm in using "+" ?
    MSDN says:

    When you use the + operator, you may not be able to determine whether addition or string concatenation will occur. Use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.
    It prevents the dreaded "evil type coercion"
    .

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