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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set up string constant like vbcrlf

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
Is it possible to set up a string constant containing a binary or hex value. The code below achieves what I want:
Code:
Private Const FldDelim As String = "ÿ"
but ideally I'd use something like:
Code:
Private Const FldDelim As String = Chr(255) 'This
Private Const FldDelim As String = "&HFF"   'or this
but one is illegal and the other is nonsense. If there is an answer, I imagine it's very simple!

Thanks in advance.
 
The second of your ideal solutions should be fine. Do you get an error?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for reply. I don't get an error but it creates a four character text string "&", "H", "F", "F" when I want a one character binary string - if that makes sense.
 
It does make sense and I think the answer to your initial question would then be no. A constant assignment cannot have any operations on the right hand side of the = sign as far as I know.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
OK I half expected that was the case but was hoping there may be a way of assigning a hex value to a string constant in a similar way that you could for an integer.

As it is, I can just do a print chr(<value>) in the debugger then paste the result into the literal so I can get there though arguably in a less readable fashion.

Thanks again.
 

A constant MUST be supplied an expression.

However,
Help said:
You can't use variables, user-defined functions, or intrinsic Visual Basic functions (such as Chr) in expressions assigned to constants.

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
Thanks Skip - I do understand that. It's just that, in a flavour of BASIC I used when Moses was my boss, you could assign a string to "<255>" but it was interpreted as a single character (equivalent to chr(255)). Something similar in VB might have overcome my problem.
 

Are you affirming that you were there when Moses was given the A Commandments?


Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
Yes - actually he had planned a full F commandments but we ran out of time on the project. The others were just more nonsense to do with neighbours' wives, asses etc.
 

So was the Moses the first to use the Let statement?

And didn't Moses have 10 siblings; Aaron and Miriam?

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
What is wrong with this?:

Private Const FldDelim As String = "ÿ"



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Initially, Thou and Shalt were also keywords.

He didn't talk about his family much - just shouted at me lots when my 'part the waters' program kept crashing when he was only half way across.
 
Sorry DrJavaJoe, back to the subject! Nothing's drastically wrong with it, it's just a bit less meaningful to someone looking at the code. I've added a comment which gets over that I guess.
 
Moses was also the first to [red][&cent;][/red]

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
He want the string to contain ÿ not 255.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 

Code:
    Const W = &HFF
    MsgBox Chr(W)

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
Just for fun, how about:

Const ASCII255 = "ÿ"

which would be pretty descriptive ...

Or, if you insist on requiring a Const called W, then you could do:

Const ASCII255 = "ÿ"
Const W = ASCII255

 
Thanks everyone - for the ideas and the giggles!

Only reason I wouldn't use the name ASCII255 is that this is being used as a delimiter and one day I may decide that a different value is more appropriate. Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top