Results 1 to 35 of 35

Thread: [RESOLVED] two questions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Resolved [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 =)

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    roddog you just got me confused lol

  4. #4
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: two questions

    If I understand what you're saying correctly, you could do something like this:
    VB Code:
    1. Dim words() As String
    2.    
    3.     words = Split(Text1.Text, "$")
    4.     List1.AddItem words(0)
    5.     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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    no the one he gave me removes something specifc like "@" what i want to do is remove everything before or after "@"

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    Quote Originally Posted by pnish
    If I understand what you're saying correctly, you could do something like this:
    VB Code:
    1. Dim words() As String
    2.    
    3.     words = Split(Text1.Text, "$")
    4.     List1.AddItem words(0)
    5.     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

  8. #8
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: two questions

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim remove() As String
    3.    
    4.     remove = Split(Text1.Text, "$")
    5. 'to remove after    
    6. Text2.Text = remove(0)
    7. 'to remove before
    8. Text3.Text = remove(1)
    9. End Sub
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: two questions

    VB Code:
    1. Dim str As String
    2. Dim str1 As String
    3. Dim str2 As String
    4.  
    5. str = "test$test"
    6. str1 = Mid$(str, 1, InStr(1, str, "$") - 1)
    7. str2 = Mid$(str, InStr(1, str, "$") + 1)
    8.  
    9. MsgBox str1
    10. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    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.

  11. #11
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: two questions

    for you to understand better:

    VB Code:
    1. Dim remove() As String
    2. Private Sub Command1_Click()
    3.  removebefore
    4. End Sub
    5. Public Sub removebefore()
    6.     remove = Split(Text1.Text, "$")
    7.     Text3.Text = remove(1)
    8. End Sub
    9. Public Sub removeafter()
    10.     remove = Split(Text1.Text, "$")
    11.     Text3.Text = remove(0)
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15. removeafter
    16. End Sub
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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.

  13. #13
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    pretty much what i got is the text loads to the listbox
    VB Code:
    1. Private Sub Form_Load()
    2. Dim strFile As String
    3. Dim strLine As String
    4. Dim varData As Variant
    5. Dim i As Integer
    6.  
    7.     strFile = App.Path & "\Text.txt"
    8.     Open strFile For Input As #1
    9.         strLine = Input(LOF(1), #1)
    10.         varData = Split(strLine, vbNewLine, , vbTextCompare)
    11.     Close #1
    12.    
    13.     For i = 0 To UBound(varData)
    14.         List1.AddItem varData(i)
    15.     Next i
    16.  
    17.     Label1.Caption = "Loaded list!"
    18.     Label2.Caption = List1.ListCount
    19. End Sub

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  16. #16
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  17. #17
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    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.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    Quote 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

  21. #21
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: two questions

    Quote 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.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    no the end result would be text1.text = $dog and for text2 it would be cat$

  23. #23
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: two questions

    if i understand you better, i think here's what you might need:

    VB Code:
    1. Dim remove() As String
    2. Dim var, ctr
    3. Private Sub Command1_Click()
    4. For ctr = 0 To List1.ListCount
    5.    
    6.     var = var & List1.List(ctr)
    7. Next
    8. remove = Split(var, "$")
    9.  
    10. Text3.Text = remove(0)
    11. Text2.Text = remove(1)
    12. End Sub
    WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...

  24. #24
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: two questions

    Quote 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:
    1. Dim words() As String
    2.     Dim SearchFor As String
    3.  
    4.     SearchFor = "$"
    5.     words = Split(List1.Text, SearchFor)
    6.     Text2.Text = words(0) & SearchFor
    7.     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.

  25. #25
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    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...

  26. #26

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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.

  27. #27
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: two questions

    Quote 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.

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    Re: two questions

    Lol sorry im head is just out there today

  29. #29
    Fanatic Member lerroux's Avatar
    Join Date
    Nov 2005
    Location
    Welcome to the darkside... we have cookies
    Posts
    646

    Re: two questions

    Quote 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...

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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"

  31. #31
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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 .....

  32. #32
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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:
    1. dim ipos as integer
    2. dim stemp as string
    3. dim lcount as long
    4.  
    5. for lcount = 0 to listbox.listcount - 1
    6.   stemp=listbox.list(lcount)
    7.   ipos=instr(stemp,textbox1.text)
    8.   stemp=mid$(stemp,ipos)
    9.   listbox.list(lcount)=stemp
    10. next lcount

    This is the code for textbox2 :
    VB Code:
    1. dim ipos as integer
    2. dim stemp as string
    3. dim lcount as long
    4.  
    5. for lcount = 0 to listbox.listcount - 1
    6.   stemp=listbox.list(lcount)
    7.   ipos=instr(stemp,textbox2.text)
    8.   stemp=left$(stemp,1,ipos+len(textbox2.text) - 1 )
    9.   listbox.list(lcount)=stemp
    10. 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

  33. #33
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    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:
    1. 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 .....

  34. #34
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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.

  35. #35

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Posts
    219

    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
  •  



Click Here to Expand Forum to Full Width