开发者

Comma, ')',or valid expression continuation expected

I need my VB.net to write a file containing the following lin开发者_JS百科e

objWriter.WriteLine ("TEXTA " (FILEA) " TEXTB")

Unfortunatly the variable (FILEA) is causing problems i now get the error

Comma, ')', or valid expression continuation expected.

Could someone explain this please?


You're not concatenating (joining) the strings proerly...

objWriter.WriteLine ("TEXTA " & FILEA & " TEXTB")

A better style to get into the habit of using is:

objWriter.WriteLine (string.format("TEXTA {0} TEXTB", FILEA))

The FILEA variable replaces the {0} placeholder in the format string. Depending on what the writer you're using is, you may have a formatted overload so you could just do:

objWriter.WriteLine ("TEXTA {0} TEXTB", FILEA)

And since you asked for an explanation;

The compiler is asking you what exactly you want it to do - you've given it 3 variables (String, variable, String) and haven't told it that you want to join them together - It's saying that after the first string "TEXTA", there should either be the closing bracket (to end the method call), a comma (to pass another parameter to the method) OR a "valid continuation expression" - ie something that tells it what to do with the next bit. in this case, you want a continuation expression, specifically an ampersand to signify "concatenate with the next 'thing'".


Presumably you're looking for string concatenation? Try this:

objWriter.WriteLine("TEXTA" & FILEA & "TEXTB");

Note that FILEA isn't exactly a conventional variable name... which leads me to suspect there may be something else you're trying to achieve. Could you give more details?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜