|
-
Mar 22nd, 2006, 01:42 AM
#1
Thread Starter
Addicted Member
[RESOLVED] two questions
ok yet another listbox question lol well i want to know how i can remove text before and after a certain letter number or word let me try to make it more clear i have a txt and in the txt theres a words and they have test$test i basically want to put in one text box to remove anything before $ and in another text box to remove anything after $ I would appreciate the help =)
-
Mar 22nd, 2006, 01:46 AM
#2
Re: two questions
You would use the Instr, Mid$, and/or Replace string functions.
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 
-
Mar 22nd, 2006, 01:47 AM
#3
Thread Starter
Addicted Member
Re: two questions
roddog you just got me confused lol
-
Mar 22nd, 2006, 01:48 AM
#4
Fanatic Member
Re: two questions
use the code, dee-u gave you in the other thread... just play around with it, i think it's the same thing u r asking
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 01:49 AM
#5
Re: two questions
If I understand what you're saying correctly, you could do something like this:
VB Code:
Dim words() As String
words = Split(Text1.Text, "$")
List1.AddItem words(0)
List2.AddItem words(1)
So if Text1.Text = "test$text", the end result of this code would be that test is added to List1 and text is added to List2.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 01:49 AM
#6
Thread Starter
Addicted Member
Re: two questions
no the one he gave me removes something specifc like "@" what i want to do is remove everything before or after "@"
-
Mar 22nd, 2006, 01:53 AM
#7
Thread Starter
Addicted Member
Re: two questions
 Originally Posted by pnish
If I understand what you're saying correctly, you could do something like this:
VB Code:
Dim words() As String
words = Split(Text1.Text, "$")
List1.AddItem words(0)
List2.AddItem words(1)
So if Text1.Text = "test$text", the end result of this code would be that test is added to List1 and text is added to List2.
no i have a txt file and when i run the programm its automatically added to the listbox and i have two text boxes one to remove anything before and one to remove anything after
-
Mar 22nd, 2006, 01:55 AM
#8
Fanatic Member
Re: two questions
VB Code:
Private Sub Command1_Click()
Dim remove() As String
remove = Split(Text1.Text, "$")
'to remove after
Text2.Text = remove(0)
'to remove before
Text3.Text = remove(1)
End Sub
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 01:55 AM
#9
Re: two questions
VB Code:
Dim str As String
Dim str1 As String
Dim str2 As String
str = "test$test"
str1 = Mid$(str, 1, InStr(1, str, "$") - 1)
str2 = Mid$(str, InStr(1, str, "$") + 1)
MsgBox str1
MsgBox str2
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 
-
Mar 22nd, 2006, 01:56 AM
#10
Re: two questions
Posting a small sample of your text file would help. What do you mean 1 text box removes everything before the $ and the other text box removes everything after??
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 01:59 AM
#11
Fanatic Member
Re: two questions
for you to understand better:
VB Code:
Dim remove() As String
Private Sub Command1_Click()
removebefore
End Sub
Public Sub removebefore()
remove = Split(Text1.Text, "$")
Text3.Text = remove(1)
End Sub
Public Sub removeafter()
remove = Split(Text1.Text, "$")
Text3.Text = remove(0)
End Sub
Private Sub Command2_Click()
removeafter
End Sub
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:00 AM
#12
Thread Starter
Addicted Member
Re: two questions
Ok i have 1 listbox and my text gets loaded there on form_load in one text box anything that i put could be "$" could be "C" it removes anything before that and in another text box it removes anything after whatever i put in the text box please tell me if you need me to clarify anything.
-
Mar 22nd, 2006, 02:03 AM
#13
Fanatic Member
Re: two questions
hi, i still dont understad your post... could you post some of your code? but anyways samples above wll help you...
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:05 AM
#14
Thread Starter
Addicted Member
Re: two questions
pretty much what i got is the text loads to the listbox
VB Code:
Private Sub Form_Load()
Dim strFile As String
Dim strLine As String
Dim varData As Variant
Dim i As Integer
strFile = App.Path & "\Text.txt"
Open strFile For Input As #1
strLine = Input(LOF(1), #1)
varData = Split(strLine, vbNewLine, , vbTextCompare)
Close #1
For i = 0 To UBound(varData)
List1.AddItem varData(i)
Next i
Label1.Caption = "Loaded list!"
Label2.Caption = List1.ListCount
End Sub
-
Mar 22nd, 2006, 02:08 AM
#15
Re: two questions
Is the $ and C characters in this data being loaded into the listbox? How are you wanting to display the split data for each record?
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 
-
Mar 22nd, 2006, 02:09 AM
#16
Fanatic Member
Re: two questions
then you want to load list1's contents to two text boxes?
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:09 AM
#17
Re: two questions
OK. That's the easy part, it's your two text boxes that are confusing me.
What exactly do you want to happen next? So you enter a $ (or whatever) into Text1, what happens then?
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 02:10 AM
#18
Thread Starter
Addicted Member
Re: two questions
i want two text boxes each with there own seperate function one removes everything before a certain text and one removes everything after a certain text but i want it to remove it from the listbox
-
Mar 22nd, 2006, 02:11 AM
#19
Re: two questions
Remove from the Selected listbox item or all items?
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 
-
Mar 22nd, 2006, 02:11 AM
#20
Thread Starter
Addicted Member
Re: two questions
 Originally Posted by pnish
OK. That's the easy part, it's your two text boxes that are confusing me.
What exactly do you want to happen next? So you enter a $ (or whatever) into Text1, what happens then?
then anything before $ gets deleted and in text2 anything after $ gets deteled
-
Mar 22nd, 2006, 02:16 AM
#21
Re: two questions
 Originally Posted by DeCo
then anything before $ gets deleted and in text2 anything after $ gets deteled
Does the data in the list box get changed?
For example if the data in List1 was cat$dog would the end result be Text1.Text = 'cat' and Text2.Text = 'dog'??
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 02:21 AM
#22
Thread Starter
Addicted Member
Re: two questions
no the end result would be text1.text = $dog and for text2 it would be cat$
-
Mar 22nd, 2006, 02:22 AM
#23
Fanatic Member
Re: two questions
if i understand you better, i think here's what you might need:
VB Code:
Dim remove() As String
Dim var, ctr
Private Sub Command1_Click()
For ctr = 0 To List1.ListCount
var = var & List1.List(ctr)
Next
remove = Split(var, "$")
Text3.Text = remove(0)
Text2.Text = remove(1)
End Sub
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:28 AM
#24
Re: two questions
 Originally Posted by DeCo
no the end result would be text1.text = $dog and for text2 it would be cat$
Then something like this should work
VB Code:
Dim words() As String
Dim SearchFor As String
SearchFor = "$"
words = Split(List1.Text, SearchFor)
Text2.Text = words(0) & SearchFor
Text1.Text = SearchFor & words(1)
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 02:30 AM
#25
Fanatic Member
Re: two questions
oh... yeah, i forgot about displaying the $ my bad... lol
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:31 AM
#26
Thread Starter
Addicted Member
Re: two questions
ok i got myself confused... theres two text boxes one removes things before what ever you put in text2 and one removes anything after what you put in text3 when you do this it will take affect in list1 because thats where the words are loaded.
-
Mar 22nd, 2006, 02:34 AM
#27
Re: two questions
 Originally Posted by DeCo
ok i got myself confused...
You're not the only one LOL. Gotta go to work now, I'll check back later... good luck.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Mar 22nd, 2006, 02:36 AM
#28
Thread Starter
Addicted Member
Re: two questions
Lol sorry im head is just out there today
-
Mar 22nd, 2006, 02:37 AM
#29
Fanatic Member
Re: two questions
 Originally Posted by pnish
You're not the only one LOL.
same here... could you explain further please?
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Mar 22nd, 2006, 02:59 AM
#30
Thread Starter
Addicted Member
Re: two questions
Sure i have a txt file named text.txt when i load the programm all the text is loaded to a listbox i just want to be able to remove things before and after a letter symbol or word example in my txt file name theres these folllowing words
123$124
abc$dfg i decide i dont want the text before $ so i go to text box1 and put $ text1 removes anythingbefore $ if i want to remove after $ i go to text2 and type in $ and it removes everything after of course "$" could be "C" or it could be "Cell"
-
Mar 22nd, 2006, 05:04 AM
#31
Hyperactive Member
Re: two questions
Welcom
Or these contained words in ListBox they have the same amount the characters or not?
This is important to define the criterion of choice, it will be very hard if words will be different length.
I think, that then you will need additionally several the Optionbuttons to specifying your requirements. Your programme will not know how much the characters you want a cut from left and from right side and what you want to choose with centre.
so it seems for me i only loudly i think
i greet
Last edited by Tamgovb; Mar 22nd, 2006 at 05:10 AM.
I know, I know, my English is bad, sorry .....
-
Mar 22nd, 2006, 05:53 AM
#32
Addicted Member
Re: two questions
This is your requirement as I understand.
1 - All the lines of your textfile are loaded into your listbox.
2 - If you enter a character in Textbox1 : All the items in the listbox should be changed so that characters before the character you typed in are removed.
3 - If you enter a character in Textbox2 : All the items in the listbox should be changed so that after before the character you typed in are removed.
Here is the code based on above assumptions :
After you type in a character in textbox1 call this sub
VB Code:
dim ipos as integer
dim stemp as string
dim lcount as long
for lcount = 0 to listbox.listcount - 1
stemp=listbox.list(lcount)
ipos=instr(stemp,textbox1.text)
stemp=mid$(stemp,ipos)
listbox.list(lcount)=stemp
next lcount
This is the code for textbox2 :
VB Code:
dim ipos as integer
dim stemp as string
dim lcount as long
for lcount = 0 to listbox.listcount - 1
stemp=listbox.list(lcount)
ipos=instr(stemp,textbox2.text)
stemp=left$(stemp,1,ipos+len(textbox2.text) - 1 )
listbox.list(lcount)=stemp
next lcount
I assume you want the changes to be made to your textfile. For this in the form_unload event : Open your textfile for output and write all the contents of the listbox into it.
Last edited by srisa; Mar 22nd, 2006 at 05:59 AM.
Reason: overlooked that textbox can contain more than 1 character
-
Mar 22nd, 2006, 07:23 AM
#33
Hyperactive Member
Re: two questions
Sorry...so with curiosity, those codes for what event are?
For Change nothing does and code for TextBox2 displaying a mistake in line:
VB Code:
stemp = Left$(stemp, 1, ipos + Len(Textbox2.Text) - 1)
>> Type-declaration character does not match declared data type <<
I do something wrong maybe
Last edited by Tamgovb; Mar 22nd, 2006 at 07:26 AM.
I know, I know, my English is bad, sorry .....
-
Mar 22nd, 2006, 07:37 AM
#34
Addicted Member
Re: two questions
Change
stemp=left$(stemp,1,ipos+len(textbox2.text)-1)
to
stemp=left$(stemp,ipos+len(textbox2.text)-1)
After typing the character in the textbox , what are you doing to run the code? I mean clicking a command button or something like that?
Add the code to the lostfocus events of the textboxes and press tab after entering the data in the textbox.
-
Mar 22nd, 2006, 12:51 PM
#35
Thread Starter
Addicted Member
Re: two questions
thank you all for your great help!
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
|