Results 1 to 23 of 23

Thread: [RESOLVED] Error:Comma,),Valid... Cant get to work

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Resolved [RESOLVED] Error:Comma,),Valid... Cant get to work

    I am trying to write this code in VB 2008 (Sorry if in wrong section, cant find 2008) the code is made up of a check box and when you click the check box will enter code into a text box which will then be created into a .bat file which can open you CD drive. (the reason for this is my Cd drive gets stuck whenever i put in a CD and this seems to work ) Here is the code.

    Code:
    If Me.CheckBox1.Checked Then
    items.Add("Set oWMP = CreateObject("WMPlayer.OCX.7"")
    items.Add("Set colCDROMs = oWMP.cdromCollection")
    items.Add("do")
    items.Add("if colCDROMs.Count >= 1 then")
    items.Add("For i = 0 to colCDROMs.Count - 1")
    items.Add("colCDROMs.Item(i).Eject")
    items.Add("Next")
    items.Add("For i = 0 to colCDROMs.Count - 1")
    items.Add("colCDROMs.Item(i).Eject")
    items.Add("Next")
    items.Add("End If")
    items.Add("wscript.sleep 5000")
    items.Add("loop")
    End if
    I keep getting the "Error:Comma, ), or valid expression continuation expected."

    I tried to fix it and looked around but couldn't get it working. Any help will be much appreciated.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Error:Comma,),Valid... Cant get to work

    That would be the .NET section right above this one.

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Error:Comma,),Valid... Cant get to work

    But maybe it's from this line?

    items.Add("Set oWMP = CreateObject("WMPlayer.OCX.7"")

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Error:Comma,),Valid... Cant get to work

    But i don't know what to do to change that line in the code. I have tried adding commas and ) in that line but cant seem to get it to work. I am not sure what else to do?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Error:Comma,),Valid... Cant get to work

    Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Error:Comma,),Valid... Cant get to work

    Anyone else have any suggestions for how I could fix this?

    Thanks for the comments so far!

  7. #7
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Adding list in textbox without items.Add("")

    Are you actually trying to add the string:

    Set oWMP = CreateObject("WMPlayer.OCX.7")

    into the items? If so, you have to double up the double quotes like so:

    vb.net Code:
    1. items.Add("Set oWMP = CreateObject(""WMPlayer.OCX.7"")")

  8. #8
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Error:Comma,),Valid... Cant get to work

    I would have to say that the problem is on this line:
    items.Add("Set oWMP = CreateObject("WMPlayer.OCX.7"")

    It's really noticeable
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  9. #9
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Adding list in textbox without items.Add("")

    Didn't see the double post here. In the future please don't post a topic twice.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Error:Comma,),Valid... Cant get to work

    Thanks,

    got this fixed.

    items.Add("Set oWMP = CreateObject(""WMPlayer.OCX.7"")")

    The code is above if anyone else has this problem.

    Thanks to ForumAccount for the help with this code.
    Last edited by VisualBasic2008; Aug 24th, 2009 at 02:39 PM.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Adding list in textbox without items.Add("")

    Oh OK,

    Sorry about the double post.

    Thanks you very much though for the comment and sorry again.

  12. #12
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    You have the string termination in the middle of the string:
    Code:
    items.Add("Set oWMP = CreateObject("WMPlayer.OCX.7"")
    and it should be changed so the quotes in the middle of the string are escaped:
    Code:
    items.Add("Set oWMP = CreateObject(""WMPlayer.OCX.7""")
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    Thanks JuggaloBrotha,

    You helped clear it up for me, I got it working now.

    Thanks again everybody.

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Adding list in textbox without items.Add("")

    About my first question.

    If I made changed it from a text box to a list box to I still need to add

    Code:
    items.Add("")
    To each line that I want to be added.

    Thanks everybody.

  15. #15
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Adding list in textbox without items.Add("")

    I might not be understanding what you're doing, but if you're adding text (or lines) to a textbox then "Items.Add" does not apply, you just append the text (or lines) to the existing text.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Adding list in textbox without items.Add("")

    Hey Bulldog, thanks for the reply,

    What I am making is when someone checks a check box, which would be check box1,2,and3. The check box that is checked will add a certain paragraph to the text box which can then be saved as a .txt document.

    So if had checked checkbox1 a paragraph would be added. The paragraph is too long to post but it is just 40 lines or so of text.

    What i am wondering is if there is a way so that I could add the whole paragraph in the code without having to put items.Add("") before each new line in the paragraph. So i could add the paragraph and it will still make new lines and such just like items.Add but a lot easier and faster.

    Here is a small example of what I have now.

    Code:
    If Me.Checkbox1.Checked then
           items.Add("Line 1 of paragraph")
           items.Add("Line 2 of paragraph")
           items.Add("All the way till Line 40 of paragraph")
    Thanks for any help in advance and thanks Bulldog and ForumAccount for your replies.

  17. #17
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Adding list in textbox without items.Add("")

    If your paragraph is text, then you can do that in one line. By text, I mean a very long string, rather than a collection of individual lines.

    If CheckBox1.Checked Then YourTextBox.Text = YourParagraph

    If your paragraphs are already 'lines', then you could add them together into strings.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  18. #18

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    Thanks Bulldog,

    Just one more question, how would I make a string because the paragraph is separate lines. Not just one string.

    Thanks again.

  20. #20
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    Duplicate Threads Merged

  21. #21
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    Once again, what is "items"?

    What are you trying to do? It looks as though you are trying to put some VB code into your TextBox manually.

    I advice you to use a StringBuilder, where you can do something like:
    Code:
    Dim sb As New StringBuilder
    sb.AppendLine("Line 1 of paragraph")
    sb.AppendLine("Line 2 of paragraph")
    etc...
    
    TextBox1.Text = sb.ToString()
    Of course, you will still have to type "sb.AppendLine" for every line. There's not much you can about that. Maybe you could do this:
    Code:
    Dim nl As String = Environment.NewLine
    
    Dim str As String = "Line 1 of paragraph" & nl & _
       "Line2 of paragraph" & nl & _
       "Line3 of paragraph" & nl & _ 
       ...
    
    TextBox1.Text = str
    But that becomes hard to maintain and doesn't really save that much typing. sb.AppendLine costs only 3 or 4 keystrokes if you use Intellisense.

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    Hello,

    Thanks Nick for the post I think you solved my main problem. But to answer you question about what is "items". I am not exactly sure (just started VB so am not sure exactly what everything means) but I think my items is the line in the paragraph. So items is line 1-50 of paragraph.

    Sorry if that doesn't answer your question, I am a little confused.

    Thanks everyone for your posts, I really appreciate everyones help.

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: [RESOLVED] Error:Comma,),Valid... Cant get to work

    P.S. Sorry, I forgot to add , just wanted to say to Nick that what I was trying to do is have it so that I didn't have to keep typing the same paragraph over and over again for a tutorial. I am writing a tutorial for my friend and I found my self writing the same paragraph a couple of times over. So I thought there must be an easier way. And I made this program to help solve this problem and any future problems similar to this.

    Thanks again!

Tags for this Thread

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