|
-
Feb 10th, 2005, 04:59 PM
#1
Thread Starter
Addicted Member
Delete everything after a "-"[RESOLVED]
I would like to delete everything after a "-" in a textbox. How would I do this? Please help if you can. Thank You.
Last edited by andy345; Feb 10th, 2005 at 09:04 PM.
-
Feb 10th, 2005, 05:02 PM
#2
Re: Delete everything after a "-"
Depending on the event you want this to occur in, you would use something like this.
VB Code:
Text1.Text = Mid$(Text1.Text, 1, InStr(1, tText1.Text, "-") - 1)
Also, you would want to place some error trapping in there too in case there is no "-" found.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 10th, 2005, 05:02 PM
#3
Re: Delete everything after a "-"
VB Code:
text1.text = Left(text1.text,instr(text1.text,"-")-1)
Will work as long as there is a - in the text. it will fail otherwise, so you should maybe use an error trap.
-
Feb 10th, 2005, 05:07 PM
#4
Re: Delete everything after a "-"
You need to do a -1 if you dont want the dash.
 Originally Posted by dglienna
text1.text = Left(text1.text,instr(text1.text,"-"))
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 10th, 2005, 05:53 PM
#5
Thread Starter
Addicted Member
Re: Delete everything after a "-"
Ok I think I messed up what I wanted to say I want to take everything before the "-" and put it in text2 and leave text1 the way it is. so if text1 is yay - text
text2 will become yay and text1 will stay the same
-
Feb 10th, 2005, 06:19 PM
#6
Addicted Member
Re: Delete everything after a "-"
IT's even simpler then.
VB Code:
Text2.Text = Mid$(Text1.Text, 1, InStr(1, tText1.Text, "-") - 1)
-
Feb 10th, 2005, 06:56 PM
#7
Re: Delete everything after a "-"
ROB - I realizzed that when we both posted at the same time. Instead of blindly following, I pasted it into the IDE to see that I had made an error, and I changed it. We posted at the same time.
Andy, this will do it.
VB Code:
text2.text = Left(text1.text,instr(text1.text,"-")-1)
-
Feb 10th, 2005, 06:58 PM
#8
Re: Delete everything after a "-"
Oh, you must of edited it quite quick. It doesnt show "Last edited by dglienna at xx:xx:xx" 
Down to the same minute
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 10th, 2005, 07:20 PM
#9
Re: Delete everything after a "-"
I've noticed that it doesn't show up if you edit the post right away. I tend to do that a lot. I thought the difference may have been using MID as opposed to left, and had the IDE open anyways. Just created a textbox and a button, pasted in the code, added "- asfhhl" to the word "Text" and hit the button. Should have tested first, once again.
-
Feb 10th, 2005, 09:07 PM
#10
Thread Starter
Addicted Member
Re: Delete everything after a "-"[RESOLVED]
Thank You all I got it to work with dglienna's post of
VB Code:
text2.text = Left(text1.text,instr(text1.text,"-")-1)
-
Feb 10th, 2005, 09:22 PM
#11
Re: Delete everything after a "-"[RESOLVED]
Glad to hear it. Keep coming back!
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
|