PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] VB6 Clipboard problem-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] VB6 Clipboard problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    10

    Resolved [RESOLVED] VB6 Clipboard problem

    Need help with error trapping clipboard code so that if one of the text boxes is empty it moves to the next one and doesnt leave a blank line in the clipboard. this is what Im using so far.



    Dim str As String
    str = Text19.Text & vbCrLf & _
    Text28.Text & vbCrLf & _
    Text37.Text & vbCrLf & _
    Text46.Text & vbCrLf & _
    Text55.Text & vbCrLf & _
    Text64.Text & vbCrLf & _
    Text73.Text & vbCrLf & _
    Text82.Text & vbCrLf & _
    Text92.Text & vbCrLf & _
    Text20.Text & vbCrLf & _
    Text30.Text & vbCrLf & _
    Text38.Text & vbCrLf & _
    Text47.Text




    Clipboard.Clear
    Clipboard.SetText str



    now if text box20 has no text, for example, it leaves a blank line, I want it to just display the next textbox which isnt blank.



    I tried something like this, and it didnt work

    If Text19.Text = "" Then

    exit sub
    Else
    Clipboard.SetText str


    If Text28.Text = "" Then

    exit sub

    Else


    Clipboard.SetText str





    End If
    End If

    and so on to text47.text



    hope you can help

  2. #2
    Lurker
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,651

    Re: VB6 Clipboard problem

    Thread moved from CodeBank, which is for posting working code examples.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    12,919

    Re: VB6 Clipboard problem

    You do not want to exit the sub when you encounter a blank entry you just want to ignore that one and not add it to your string.

    vb Code:
    1. Dim str As String
    2.  
    3. If Not text19.Text = "" Then
    4.     str = str & text19.Text & vbCrLf
    5. End If
    6. If Not text28.Text = "" Then
    7.     str = str & text28.Text & vbCrLf
    8. End If
    9. ' and so on for each item
    10.  
    11. Clipboard.Clear
    12. Clipboard.SetText str

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,132

    Re: VB6 Clipboard problem

    In your case a little helper function may be the easiest way to do it.
    Code:
    Private Sub Command1_Click()
    Dim strTextBoxEntries As String
        
        strTextBoxEntries = AddText(strTextBoxEntries, Text19)
        strTextBoxEntries = AddText(strTextBoxEntries, Text28)
        strTextBoxEntries = AddText(strTextBoxEntries, Text37)
        strTextBoxEntries = AddText(strTextBoxEntries, Text46)
        strTextBoxEntries = AddText(strTextBoxEntries, Text55)
        strTextBoxEntries = AddText(strTextBoxEntries, Text64)
        strTextBoxEntries = AddText(strTextBoxEntries, Text73)
        strTextBoxEntries = AddText(strTextBoxEntries, Text82)
        strTextBoxEntries = AddText(strTextBoxEntries, Text92)
        strTextBoxEntries = AddText(strTextBoxEntries, Text20)
        strTextBoxEntries = AddText(strTextBoxEntries, Text30)
        strTextBoxEntries = AddText(strTextBoxEntries, Text38)
        strTextBoxEntries = AddText(strTextBoxEntries, Text47)
    
        Clipboard.Clear
        Clipboard.SetText strTextBoxEntries
    
    End Sub
    
    Private Function AddText(ByVal strText As String, txt As TextBox) As String
    Dim strTemp As String
    
        ' Trim the input from the textbox
        strTemp = Trim(txt.Text)
        
        ' If the textbox is empty then there is no need to process it
        If strTemp = "" Then
            strTemp = strText
        Else
        ' Add the textbox value to the string
            ' If the string has been initialized then add a line break
            ' before adding the text from the textbox
            If strText <> "" Then
                strText = strText & vbCrLf
            End If
            
            'add the textbox value to the end of the string
            strTemp = strText & strTemp
        End If
        
        ' return the new line
        AddText = strTemp
    End Function
    Last edited by MarkT; Mar 5th, 2012 at 07:32 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2011
    Posts
    10

    Re: VB6 Clipboard problem

    Quote Originally Posted by DataMiser View Post
    You do not want to exit the sub when you encounter a blank entry you just want to ignore that one and not add it to your string.

    vb Code:
    1. Dim str As String
    2.  
    3. If Not text19.Text = "" Then
    4.     str = str & text19.Text & vbCrLf
    5. End If
    6. If Not text28.Text = "" Then
    7.     str = str & text28.Text & vbCrLf
    8. End If
    9. ' and so on for each item
    10.  
    11. Clipboard.Clear
    12. Clipboard.SetText str
    Awesome piece of code, thanks very much did it this way and is working excellently.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width