|
-
Jan 31st, 2010, 06:32 AM
#1
Thread Starter
New Member
[RESOLVED] Multiple Text Box Copy, Skip if Textbox if Not Populated
Hey there,
I am running Visual Basic Express 2008. I realize this forum category is for VB6 or earlier, so please kindly inform me of where to post this if this is incorrect.
This is actually the first forum I have joined ever because I can't figure it out on my own and can't find the code off the website.
So here's the deal. I am almost done, i I have a ComboBox and 4 text boxes. At the bottom it has CLEAR, UNDO CLEAR, COPY ALL TO CLIPBOARD & COPY SOLUTION which does so for the ComboBox and all 4 text boxes. The format like this (CORP is the ComboBox):
CORP - Workstation - Won't power on - HOSTNAME/USERNAME
PROBLEM/REQUEST:
started happening today
TROUBLESHOOTING/ACTIONS:
reseated cables
pings as offline
And then due to the ticket entry system we use, I have a separate COPY SOLUTION button and that works just fine, but that would read as:
Dispatching tech
Now here's where I'm caught up on, I need to take a textbox where I don't use it because I don't have a use for it dependent on the issue of the person I'm working with and it'll look like this:
CORP - Windows - Password Reset - USERNAME
But, this is where I'm getting stuck, it keeps putting stuff like:
CORP - Windows - Password Reset - /USERNAME
or
- Windows - Password Reset - /USERNAME
it's doing weird stuff like that all over the place. I really appreciate any help.
Here's the code:
vb.net Code:
Public Class Form1
Private Sub Text1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
If ComboBox1.Text = "" Then
My.Computer.Clipboard.SetText(Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
End If
If Me.Text1.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
End If
If Me.Text2.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
End If
If Me.Text3.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
End If
If Me.Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text & vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & _
Text6.Text)
End If
If Me.Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text6.Text)
End If
If Me.Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text & vbCrLf & vbCrLf & "PROBLEM/REQUEST:" & vbCrLf & _
Text5.Text)
End If
If (Me.Text5.Text & Me.Text6.Text) = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text & Chr(92) & _
Text4.Text)
End If
If (Me.Text3.Text & Me.Text4.Text & Me.Text5.Text & Text6.Text) = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text)
End If
If (Me.Text4.Text & Me.Text5.Text & Me.Text6.Text) = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text3.Text)
End If
If (Me.Text3.Text & Me.Text5.Text & Me.Text6.Text) = "" Then
My.Computer.Clipboard.SetText(ComboBox1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text1.Text & Chr(32) & Chr(45) & Chr(32) & _
Text2.Text & Chr(32) & Chr(45) & Chr(32) & _
Text4.Text)
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
My.Computer.Clipboard.SetText(Text7.Text)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ComboBox1.ResetText()
Text1.SelectAll()
Text1.Copy()
Text1.SelectAll()
Text1.Cut()
Text2.SelectAll()
Text2.Copy()
Text2.SelectAll()
Text2.Cut()
Text3.SelectAll()
Text3.Copy()
Text3.SelectAll()
Text3.Cut()
Text4.SelectAll()
Text4.Copy()
Text4.SelectAll()
Text4.Cut()
Text5.SelectAll()
Text5.Copy()
Text5.SelectAll()
Text5.Cut()
Text6.SelectAll()
Text6.Copy()
Text6.SelectAll()
Text6.Cut()
Text7.SelectAll()
Text7.Copy()
Text7.SelectAll()
Text7.Cut()
ComboBox1.Focus()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Text1.Undo()
Text2.Undo()
Text3.Undo()
Text4.Undo()
Text5.Undo()
Text6.Undo()
Text7.Undo()
End Sub
End Class
Last edited by Hack; Feb 4th, 2010 at 07:07 AM.
Reason: Added Highlight Tags
-
Jan 31st, 2010, 08:32 AM
#2
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Welcome to the forums 
VB2008 is released after VB6.. So, this isn't the correct section. It will be Visual Basic.Net...
I will inform a mod to move this thread.
Also, when posting code, enclose it in [ CODE ] [ /CODE ] tags... Which makes it easier to read...
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,...
-
Jan 31st, 2010, 10:03 AM
#3
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
(thanks for letting us know akhileshbc )
-
Jan 31st, 2010, 06:34 PM
#4
Thread Starter
New Member
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Thank you, I will await a response.
-
Feb 1st, 2010, 09:31 AM
#5
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Welcome to the forum.
Might I suggest you reword the problem in a technical manner and explain what is the problem rather then a design issue and you will get faster responses. Also what version of Express are you using i.e. VS2010, VS2008?
-
Feb 1st, 2010, 01:09 PM
#6
Thread Starter
New Member
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Yes, I'll try. BTW I have VB 2008 Express. So I a total of 7 different text boxes and a Copy to Clipboard at the bottom. I can't find the code to do this, but I just want to have the textbox be skipped if it's empty and copy all the others in formatting that I have setup. I would like to try and do it this way instead of trying to think of every different scenario the user would put in like putting in textbox4 and textbox 6 and leaving the rest blank.
-
Feb 3rd, 2010, 11:22 AM
#7
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
 Originally Posted by w4itwh4t?
Yes, I'll try. BTW I have VB 2008 Express. So I a total of 7 different text boxes and a Copy to Clipboard at the bottom. I can't find the code to do this, but I just want to have the textbox be skipped if it's empty and copy all the others in formatting that I have setup. I would like to try and do it this way instead of trying to think of every different scenario the user would put in like putting in textbox4 and textbox 6 and leaving the rest blank.
The following code shows how to get all TextBoxes where the parent conrol is the form, not something like a panel etc.
Code:
Public Class Form1
Dim TextBoxList As New List(Of TextBox)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim TextBoxes = From tbs In Me.Controls Where TypeOf (tbs) Is TextBox
Dim EmptyBoxes = From tbs In TextBoxes.Cast(Of TextBox)() Where tbs.Text = ""
Console.WriteLine("Number of textboxes {0}", TextBoxes.Count)
Console.WriteLine("Empty textboxes {0}", EmptyBoxes.Count)
For Each tb In EmptyBoxes
TextBoxList.Add(CType(tb, TextBox))
Next
' Later in another sub or function
For Each tb In TextBoxList
Console.WriteLine("TextBox [{0}] is empty", tb.Name)
Next
' Manipulating them
For Each tb In TextBoxList
tb.Text = "Hello World"
Next
End Sub
End Class
-
Feb 4th, 2010, 06:44 AM
#8
Thread Starter
New Member
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
I will check this out after work
-
Feb 5th, 2010, 12:04 AM
#9
Thread Starter
New Member
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Hmm, well I'm a beginner in VB and I tried the code, but I guess I don't understand what you posted. The picture below is what the form looks like. Really all I'm trying to do now is simplify it.
The output should look like this when the Copy all to Clipboard is pressed:
CORP - Component - Issue goes here - HOSTNAME - USERNAME
DETAILS:
Details go here.
TROUBLESHOOTING/ACTIONS:
Troubleshooting goes here.
Actions can also go here.
Here is the code I currently have now:
Code:
Public Class Form1
Private Sub Text1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim ComboBox
Dim Textbox1
Dim Textbox2
Dim Textbox3
Dim Textbox4
Dim Textbox5
Dim Textbox6
ComboBox = ComboBox1.Text
Textbox1 = Chr(32) & Chr(45) & Chr(32) & Text1.Text
Textbox2 = Chr(32) & Chr(45) & Chr(32) & Text2.Text
Textbox3 = Chr(32) & Chr(45) & Chr(32) & Text3.Text
Textbox4 = Chr(32) & Chr(45) & Chr(32) & Text4.Text
Textbox5 = vbCrLf & vbCrLf & "DETAILS:" & vbCrLf & Text5.Text
Textbox6 = vbCrLf & vbCrLf & "TROUBLESHOOTING/ACTIONS:" & vbCrLf & Text6.Text
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox4 & Textbox5 & Textbox6)
If ComboBox = "" Then
My.Computer.Clipboard.SetText(Text1.Text & Textbox2 & Textbox3 & Textbox4 & Textbox5 & Textbox6)
End If
If Text1.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox3 & Textbox4 & Textbox5 & Textbox6)
End If
If Text2.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox3 & Textbox4 & Textbox5 & Textbox6)
End If
If Text3.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox4 & Textbox5 & Textbox6)
End If
If Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox5 & Textbox6)
End If
If Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox4 & Textbox6)
End If
If Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox4 & Textbox5)
End If
If Text1.Text & Text2.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox3 & Textbox4 & Textbox5 & Textbox6)
End If
If Text1.Text & Text3.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox4 & Textbox5 & Textbox6)
End If
If Text1.Text & Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox3 & Textbox5 & Textbox6)
End If
If Text1.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox3 & Textbox4 & Textbox6)
End If
If Text1.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox3 & Textbox4 & Textbox5)
End If
If Text2.Text & Text3.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox4 & Textbox5 & Textbox6)
End If
If Text2.Text & Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox3 & Textbox5 & Textbox6)
End If
If Text2.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox3 & Textbox4 & Textbox6)
End If
If Text2.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox3 & Textbox4 & Textbox5)
End If
If Text3.Text & Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox5 & Textbox6)
End If
If Text3.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox4 & Textbox6)
End If
If Text3.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox4 & Textbox5)
End If
If Text4.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox6)
End If
If Text4.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox5)
End If
If Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3 & Textbox4)
End If
If Text1.Text & Text2.Text & Text3.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox4 & Textbox5 & Textbox6)
End If
If Text1.Text & Text2.Text & Text3.Text & Text4.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox5 & Textbox6)
End If
If Text1.Text & Text2.Text & Text3.Text & Text4.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox6)
End If
If Text1.Text & Text2.Text & Text3.Text & Text4.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox)
End If
If Text1.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox2 & Textbox3 & Textbox4)
End If
If Text2.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox3 & Textbox4)
End If
If Text3.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox4)
End If
If Text4.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox3)
End If
If Text3.Text & Text4.Text & Text5.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox6)
End If
If Text3.Text & Text4.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2 & Textbox5)
End If
If Text3.Text & Text4.Text & Text5.Text & Text6.Text = "" Then
My.Computer.Clipboard.SetText(ComboBox & Textbox1 & Textbox2)
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
My.Computer.Clipboard.SetText(Text7.Text)
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
ComboBox1.ResetText()
Text1.SelectAll()
Text1.Copy()
Text1.SelectAll()
Text1.Cut()
Text2.SelectAll()
Text2.Copy()
Text2.SelectAll()
Text2.Cut()
Text3.SelectAll()
Text3.Copy()
Text3.SelectAll()
Text3.Cut()
Text4.SelectAll()
Text4.Copy()
Text4.SelectAll()
Text4.Cut()
Text5.SelectAll()
Text5.Copy()
Text5.SelectAll()
Text5.Cut()
Text6.SelectAll()
Text6.Copy()
Text6.SelectAll()
Text6.Cut()
Text7.SelectAll()
Text7.Copy()
Text7.SelectAll()
Text7.Cut()
ComboBox1.Focus()
ComboBox1.SelectedIndex = 0
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Text1.Undo()
Text2.Undo()
Text3.Undo()
Text4.Undo()
Text5.Undo()
Text6.Undo()
Text7.Undo()
End Sub
End Class
Last edited by w4itwh4t?; Feb 24th, 2010 at 02:29 AM.
Reason: Changing wording and removing [/HIGHLIGHT]
-
Feb 8th, 2010, 10:03 AM
#10
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
 Originally Posted by w4itwh4t?
Hmm, well I'm a beginner in VB and I tried the code, but I guess I don't understand what you posted.
As a novice developer you really need to begin reading MSDN documentation so that you do understand the basics so that you can comprehend code provided to you. The code below is very basic LINQ which gives you all empty textboxes to use in your code for logic of empty textboxes as asked in post 6 and the initial question.
Code:
Dim EmptyBoxes = From tbs In TextBoxes.Cast(Of TextBox)() Where tbs.Text = ""
For Each tb In EmptyBoxes
TextBoxList.Add(CType(tb, TextBox))
Next
-
Feb 9th, 2010, 12:33 AM
#11
Thread Starter
New Member
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
Thank you I will try it out, any tips on cleaning up the code or is what you posted how I would clean it up?
-
Feb 9th, 2010, 09:58 AM
#12
Re: Multiple Text Box Copy, Skip if Textbox if Not Populated
 Originally Posted by w4itwh4t?
Thank you I will try it out, any tips on cleaning up the code or is what you posted how I would clean it up?
Take a look at the attached project for some ideas/suggestions.
Last edited by kareninstructor; Nov 21st, 2011 at 10:15 PM.
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
|