This question already has an answer here:
How to put data containing double-quotes in string variable? [duplicate]
(1 answer)
Closed 7 years ago.
I'm writing a script generator in Visual Studio and I've run across a problem.
This is my code:
Dim Text As String
Text = "Register.node("Play") {(speed = 0, Evnt=0,)}"
And the string doesn't cover it.. I don't know why it keeps exiting the string?
In all other languages I've used there is no way of exiting a string from inside.
I would suggest either using double quotes...
Text = "Register.node(""Play"") {(speed = 0, Evnt=0,)}"
Or typing it thusly.
Text = 'Register.node("Play") {(speed = 0, Evnt=0,)}'
or maybe even like so.
Text = "Register.node("+"Play"+") {(speed = 0, Evnt=0,)}"
Related
This question already has answers here:
Is there a string math evaluator in .NET?
(18 answers)
Evaluate mathematical expression from a string using VB
(3 answers)
Closed last year.
For example:
Dim operationVar As String = "+"
result = value1 (operationVar) value2
It's only an idea, I don't even know if it's possible.
This question already has answers here:
What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it?
(5 answers)
IndexOutOfRangeException in VB.NET
(2 answers)
What does IndexOutofRangeException mean?
(3 answers)
“IndexOutOfRangeException was unhandled” [duplicate]
(2 answers)
Closed 4 years ago.
I have this code:
Module Module11
Sub Main()
Dim mess As String
Dim out As String
Dim num, p As UInteger
Dim q As Integer = -1
Console.Write("Enter a message: ")
mess = Console.ReadLine()
While p < 9
q += 1
num = Asc(mess(p + q)) + 5
out = Chr(num)
Console.Write(out)
End While
Console.ReadKey()
End Sub
End Module
But on Line num = Asc(mess(p + q)) + 5, it is showing 'index out of the bounds of array'.
I was actually trying to create code that could change every character (even blank space) to the next sixth character (with reference to ASCII codes) of whatever character we input.
It shows error even after giving the correct output (in the black console).
Please help.
I think I have the answer (or at least AN answer). I'm not familiar with visual basic, but I am familiar with Python and this seems to be extremely similar. After doing some quick researching, I learned that the "UInteger" data type cannot be negative. I would recommend changing the while loop to read "While p > 0 And p < 9" and then the rest of the code. It looks to me like your answer is coming out negative. This would make sense considering what your error message says. However, I'm not sure how the output would still come out correctly, but it's worth a shot. I would try that, and let me know how it goes!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Is the usage of literal type characters (https://msdn.microsoft.com/en-us/library/s9cz43ek.aspx) in VB.NET bad, old school style? I have a discussion with a pigheaded co-worker of me about that which ends up in “This is old style, I don’t wanna see it anymore!”.
My background is more technical and hardware related and I always enjoy the advantages of type-strict programming but I really think about the pros and cons in the OOP/VB world. Can some help me out with list of pros/cons?
[Update] Example usage:
Dim i as Integer = 0I
Dim d as Decimal = 2.4D
We have two different features here:
Type Characters are a legacy feature for backwards compatibility. There are lots of people out there (including myself) who believe that they should be avoided, but it's a fully-supported feature of the language (and not marked as deprecated), so it's basically a matter of preference and coding style.
Dim myString$ ' old style
Dim myString As String ' new style
Note that, here, "old style" means "very old style": Even QuickBasic, the DOS predecessor of Visual Basic, already supported the "new style".
Literal Type Characters on the other hand let you specify the type of a literal. This is a useful feature:
' I explicitly want the first parameter to be a decimal, not a double.
' Without the type character, the assertion would fail.
Assert.AreEqual(3.0D, SomeMethodReturningADecimal())
or
myArray = myString.Split(";"c) ' ";"c is a character, not a string.
Without the literal type characters, we'd need to use CDec(3.0) and CChar(";"), i.e., we'd need to convert these values at run-time.
In the example you mentioned in your question (variable initialization), type literals are only required if
you need Char literals or
you want to use type inference.
In other words, the following three statements produce exactly the same IL:
Dim s As Single = 1
Dim s As Single = 1.0F
Dim s = 1.0F
Do note that C# has literal type characters as well:
var myDecimal = 3.0m; // This is a decimal, not a double.
I've never seen "Identifier Type Characters" so personally I would never use it. I've seen "Literal Type Characters" and "Hexadecimal/Oct" often, I don't see any problem using them when needed or if it would help someone else read your code.
This is a bit pointeless
Dim i as Integer = 0I
But this would be needed
Dim d As Decimal
d = 13421773 / 134217728
Console.WriteLine(d) ' Prints 0.100000001490116
d = 13421773D / 134217728D
Console.WriteLine(d) ' Prints 0.100000001490116119384765625
Dim a As Char = "C" ' Compilation error with option strict on
Dim b As Char = "C"c ' No error
It's also important to follow the coding standard of the group.
This question already has answers here:
Escaping quotes in a string in VB6
(7 answers)
Closed 8 years ago.
I am trying to make one of my variables equal to the following:
Dim Quote as string
Quote = "Letter Size 11 x 17""
I need the single quote/inch symbol in the text but i do not know how to make VBA recognize it without giving me and error saying i have to end quote it.
Try one of these. It seems to do what you want (depending on where you want the ":
Sub test()
Dim Quote As String
Quote = "Letter Size 11 x 17"""
Debug.Print Quote
Quote = "Letter Size 11"" x 17"""
Debug.Print Quote
End Sub
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
replace " in vb.net
in vb.net how can i use replace function when the replace from part has double quotes in its value ?
Dim s As String = String.Replace("some string", "some "" string with quotes")