-
[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. :)
-
Re: Error:Comma,),Valid... Cant get to work
That would be the .NET section right above this one.
-
Re: Error:Comma,),Valid... Cant get to work
But maybe it's from this line?
items.Add("Set oWMP = CreateObject("WMPlayer.OCX.7"")
-
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?
-
Re: Error:Comma,),Valid... Cant get to work
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
-
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!
-
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:
items.Add("Set oWMP = CreateObject(""WMPlayer.OCX.7"")")
-
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
-
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.
-
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.
-
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.
-
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""")
-
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.:thumb:
-
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
To each line that I want to be added.
Thanks everybody.
-
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.
-
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.
-
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.
-
Re: Adding list in textbox without items.Add("")
-
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.
-
Re: [RESOLVED] Error:Comma,),Valid... Cant get to work
-
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.
-
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.
-
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!