Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the value of a char variable

Status
Not open for further replies.

Bullfrog1870

Technical User
Dec 26, 2005
15
US
I feel foolish for asking but what am I missing? I'm simply trying to set a variable equal to a single character.

Dim myChar As Char
myChar = 'A' 'This gives "Expression Expected" error
myChar = "A" 'Option Strict is on so this won't work

How should I be doing this?
Is it possible to initialize when I Dim it?

Thanks!

 
Tried the code and i don't get an error with MyChar = "A".

You could try:
Code:
MyChar = Char.Parse("A")
 
[tt]Dim MyChar As Char
MyChar = "A"c
[/tt]

will do what you need.

cjelec, note Bullfrog1870's comment after [tt]MyChar = "A"[/tt], i.e. [tt]'Option Strict is on so this won't work[/tt].

Without Option Strict it will work.

With Option Strict you need to identify the literal as a char (as I did) - other options include Char.Parse("A") as you suggested or CChar("A") or CType("A", Char)

Hope this helps.


[vampire][bat]
 
earthandfire, I did think that,
I haven't used Option Strict since vb4,5,6 days.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top