String Must Be Literal. Not A Constant Or A Variable?
Jun 12, 2011Public Class Form1
Private
[code].....
Public Class Form1
Private
[code].....
I would like to add a variable data to a string literal WITHIN the HTML tag[code]....
View 1 RepliesI'm making a call to my DLL file (prototyping 30+ functions), and want to be able to switch between different versions of the DLL quickly while in development. Thus, i want to replace the literal string constant that follows the "Lib" key word, with a variable string constant. In case there's any confusion in my use of the jargon. I am currently able to do this:
[Code]...
I am developing an application which initially allows the user to browse and select a save location. The selected path is assigned to a public variable which is used with concatenation to crate folder for saving user input data. How can I change the path string to a constant so the user can run the program again without having to run setup routine unless they want to change the save location?
View 1 Repliessuppose I have variables named A1, A2, A3 ... B1, B2, B3 ... Z97, Z98, Z99. I have a certain operation I want to do using each one in turn. I CAN write a line of code for every single variable, but this will get pretty tedious. I'd prefer it if I can make a function that takes the letter and the number as arguments. So, if it gets the arguments "E" and "10" it will perform the operation on variable E10. What is the syntax for this? say a simple operation such as: result = E10 * 3 Is the syntax any different if I use constants instead of variables?
View 3 RepliesHow would I go about dynamically declaring a constant? (It's value is dynamic, not the variable name)
View 5 RepliesPossible Duplicate: Multiline strings in VB.NET
How do you specify a multiple line string literal in Visual Basic .NET?
You can do it in C#: Multiline String Literal in C#
If I needed to escape a double quote character within a string literal I'd use two consecutive double quotes as follows:
Dim name = "Chuck ""Iceman"" Liddell"
However, it doesn't seem like consecutive # works the same way. The compiler is expecting a compiler directive to follow the # character, even when its enclosed in double quotes. How can tell the compiler that I want a # character in my string?
EDIT: as a few of the answers below point out, # is not a reserved character. I closed my solution in Visual Studio and re-opened it and no longer got the compiler squiggles warning me.
This might just be a matter of taste, but I'm wondering if there's a "recommended" way to compare a variable of type Object (which might be Nothing or have a different dynamic type than String) to a string literal in VB.NET. The following options obviously won't work:
If myObject = "Hello World" Then ... -- won't compile
If myObject Is "Hello World" Then ... -- tests for reference equality, which is just wrong
If myObject.Equals("Hello World") Then ... -- throws an exception if myObject is Nothing
If DirectCast(myObject, String) = "Hello World" Then ... -- throws an exception if myObject is not a string
Thus, the only (simple, single-expression) solution I could find is to use
If "Hello World".Equals(myObject) Then ...
which looks a bit clumsy to me. Did I miss any obvious alternative, other than doing type checks or explicit checks for Nothing?(Of course, we're talking about Option Strict On.)
Any way to assign a binary value to a vb variable? All of the obvious choices don't work. I've tried prefixing with &B, appending with b but nothing seems to work.For clarification, what I was looking for (which does not appear to be possible) was how to assign a literal binary number to a variable, in a similar manner in which you can assign a hex or octal number. I was just looking for a more visually engaging way to assign values to a flag enum.
Dim num as Integer = &H100ABC 'Hex'
Dim num2 as Integer = &O123765 'Octal'
Dim myFantasy as Integer = &B1000 'What I would like to be able to do'
Dim myReality as Integer = 2 ^ 3 'What I ended up doing'
I'm programming in VB.NET using Visual Studio 2008. I need to define a string literal containing the character "÷" equivalent to Chr(247). I understand that internally VS uses UTF-16 encoding, but when the source file is written to disk it contains the single byte value F7 for this character.
This source file is processed by another program that uses UTF-8 encoding by default, so it fails to interpret this character correctly, attempting to combine it with the following single-byte character. What encoding would correctly interpret the single byte F7 as the single character ÷?
Alternatively, is there a way of expressing a non-ASCII literal that uses only ASCII characters - like using some kind of escape sequence?
We are using a custom API in our project which provide an attribute for class fields/members which lets the interface to present a popup of some range values like "On/OFF" and pass the corresponding values of the choice to our code. The attribute requires a string array to know that values.We have many enumerations defined for these ranges,We are thinking to use Enum.GetValues() kind method to get a string array for this method.However, As we know the field declaration do not allow dynamic values in the declaration? so is there any other of doing same thing in efficient way.To clerify the problem i will write the examples below;
Current Working
<RangeLookUp("On:1","Off:2")> Public ASimpleRangeVariable As Integer
While I wanted to do like this or kind of
<RangeLookUp(SomeMethod())> Public ASimpleRangeVariable As Integer
Public Shared Function SomeMethod() as String()
'use Enum to get all the items as string values forexample Enum.GetValues & enu,.GetValues [code]....
Where SomeMethod suppose to return string array to be passed in the RangeLookup constructor.Which means if we change enumeration then we don't have to update the declaration.i know there are better ways to do it but due to some custom API, the ground is limited.
I am trying to update an Oracle Database record and i keep getting this error:
ORA-01704: string literal too long 5
I looked up that error and it seems that i have a limit of 4000 charters since i am using Oracle 10g. However, the prgblem is that its the same exact data i am putting back into that record so that is why i am unsure as to why its giving me that error for the same amount of data i took out of it.
Here is my update code:
Dim myCommand As New OracleCommand()
Dim ra As Integer
Try
[code]....
I use the followoing code to import an xlsx file into an Access 2007 table. It works fine when I enter the exact file name.However, part of the file name is a date which will change every week.The file location does not change,just the date in the file name.[code]I've tried using a wildcard but I get a Run-time error 3011.Db engine could not find the object. Make sure the object exists.
View 1 RepliesMy app has text boxes to accept input from user to questions shown on labels. When the user input is valid, a literal is added to a string incorporating the user input. If the user doesn't input anything or if user inputs "no" or "None" I want the literal and the user input to not add to my string. Make any sense? See my code below:
[Code]...
I have strMyColor = "Red".I would like to make lblMyLabel.BackColor to be red.Without using a variable the code would be this:
lblMyLabel.BackColor=Color.Red
I tried using the variable like this: lblMyLabel.backcolor="Color." & strMyColor
But the error is that a string can't be converted to System.Draw.Color. I understand that, as the string "Color.Red" is not the same as the VB constant Color.Red.Is there a way I can construct a valid vbConstant from a string?
I'm looking for a way to search a string variable for two words and copy the text in between them into another variable. This needs to be done as many times as the match occurs.
View 3 RepliesI have the following code...
Const ToAddress As String = username.Text & "url..."
which sets to ToAddress to be used in on my Net.Mail.MailMessage that is to be created with the following constructor
Dim mm As New Net.Mail.MailMessage(username.Text, ToAddress)
which takes in a string and a constant string. But I get an error here[url]...
When building a class library which contains many classes, all classes uses a lot of common constants and functions, what is the best to do:
1- Declare these constants and functions as public in a module.
2- In each class declare constants and functions used by individual class as private.
The first choice is good for easy and fast implementation, but re-using a class in a different project will require importing the module to the other project.The second choice require a lot of copy/paste for code snippet but a class can be re-used in different project easily.
I'd like to understand why one type can't be converted to another type inside a constant expression.
View 13 RepliesI have declared some constants as double in a Class
[Code]....
I'm tryingto figure out how I can get the text box to display the value of the constant with the same name? i.e 1.54186 in the example given
I have the following line of code
Dim a As String = ""
And the Refactor suggests replacing the "" with String.Empty
It is a kind of Refactoring but why? Since I am a newbie in the future declarations of mine should I better use the String.Empty ?
I am working in .Net 2010 framework 2.0 I want to place the constant string for a color property in form designer like GradientBeginColor = MyColor in form designer.
View 1 RepliesWhen developing ASP.NET websites (using VB.NET web forms) - a lot of my time is spend writing CSS files and they always seem to get messy (code duplication) and very long.
All I want to achieve is to be able to manipulate the CSS using VB.NET code in the following ways:
Use an integer variable to store my "golden" number 7 and use that for width, padding, margin etc where needed
Use string variables to store my "golden" hex color codes e.g. "#44C5F2" and use them for color, background-color, border-color etc. where needed Use an integer variable to set the height of an element and have four child elements each with height: mynum / 4
I just want to use basic VB.net number and string manipulation in order to create a CSS file on the fly.
I understand that the end product - the CSS file shouldn't change much - it should at most change on a daily basis otherwise caching couldn't be used.[code]...
I noticed that if I leave off the terminating double quote for a string constant in Visual Studio 2010, there is no error or even a warning, i.e.
Dim foo as String = "hi
However, the continuous integration tool we are using flags an error:
error BC30648: String constants must end with a double quote.
Is there some language rule in VB.Net that makes a terminating double quote optional "sometimes"? Is there some setting in Visual Studio that will make it flag this as an error, so I can avoid "breaking the build" in this way?
I have a multi-lined string message that needs to be added to the Resources.resx file of the project. Currently I'm achieving this some thing like this MessageBox(My.Resources.MyMsg1 & vbNewLine & My.Resources.MyMsg2 ). This works.However I'd like to have the entire message in one resource string rather than adding two resources strings to the Resources.resx file.I've tried using' but no luck..message displays as "My message.Rest of the message".I've also tried manually adding a new line in the Resources.resx file. ( by doing "My message.<Shift+Enter>Rest of the message" But message is adding an additional space before the message in the second line.
View 8 RepliesSay I have something like this
Dim Level1 as Integer = 83
Dim Goal as String
Goal = InputBox(" What level is your goal?")
[code].....
I have this code:
Public Class Beryllium
Public Const AtomicNumber As Byte = 4
Public Const Symbol As String = "Be"
[Code]....
I want to make a list out of all the constants (AtomicNumber, Symbol, Name and AtomicMass). I want to make the list also a constant. When I run the code above, I get an error highlighting AtomicNumber (on line on which I commented on "This line"). I tried .ToString() and CStr() but I get errors on both. Maybe there is a different way to make these constants one string or list (must be public and have new lines)?
I am trying to insert a string variable inside of two strings, and make a combined string. Public Sub Page_Load() Dim Id As String Id = Trim (Request.QueryString("Id")) End Sub Dim mp3text as string url... & Id & ".mp3" My goal is to make the mp3text variable have a string that is: url...(If Id is 7) It is for some reason not connecting up correctly. I checked what string it is outputting and this is what it is giving: url...It is missing the Id content.
View 12 RepliesThe code below works for the class that I hard coded "XCCustomers" in my RetrieveIDandName method where I use CType. However, I would like to be able to pass in various classes and property names to get the integer and string LIST returned. For example, in my code below, I would like to also pass in "XCEmployees" to my RetrieveIDandName method. I feel so close... I was hoping someone knew how to use CType where I can pass in the class name as a string variable.
Note, all the other examples I have seen and tried fail because we are using Option Strict On which disallows late binding. That is why I need to use CType.I also studied the "Activator.CreateInstance" code examples to try to get the class reference instance by string name but I was unable to get CType to work with that.When I use obj.GetType.Name or obj.GetType.FullName in place of the "XCCustomers" in CType(obj, XCCustomers)(i)I get the error "Type 'obj.GetType.Name' is not defined" or "Type 'obj.GetType.FullName' is not defined"
'+++++++++++++++++++++++++++++++
Imports DataLaasXC.Business
Imports DataLaasXC.Utilities
[code]....