Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex string to Decimal
#11
Funny, I have never used LTRIM$
I have always used a routine from Probas called StripBlanks
Either way will get rid of the spaces.
But if the spec says that it will ignore spaces, I rather do it without LTRIM$.

Unless, most of the guys use QB4.5 and I use BC 7.1 and the error is actually in BC. 7.1 ??
t is the End result that matters, not the Tools used to get there.
Reply
#12
I've never seen it happening, I always had to strip the spaces myself to get a meaningful answer from Val. I don't know if this is just me or not, I just cite my own experience with the matter (although my complete QB got erased during the last format a few weeks back).
I would still plug in a custom space remover, or use LTRIM, just for safety.
It would be something like this then:
[syntax="QBasic"]FUNCTION StripBlanks$ (Series$)

Response$ = "": char$ = ""
STATIC Tokenset$
IF LEN(Tokenset$) = 0 THEN Tokenset$ = CHR$(32) + CHR$(13) + CHR$(10) + CHR$(9)
'Initializing static strings wasn't possible I believe, so this may even
'be slower than just an assignment every loop

FOR i = 1 TO LEN(Series$)
char$ = MID$(Series$, i, 1)
IF INSTR(Tokenset$, char$) = 0 THEN Response$ = Response$ + char$
NEXT i

StripBlanks$ = Response$

END FUNCTION[/syntax]
I haven't tested it thoroughly, but assume it to work a little bit.

Reading through the thread, I dont see a concrete question anymore, could you repeat it please?

I hope it helps a bit,

- Neo
Reply
#13
Neo

The original question was answered with the val("&H" + A$)

But since trying that, I discovered that the spaces were not being ignored as per the help file.

Quote:The VAL function also strips
blanks, tabs, and line feeds from the argument string.
t is the End result that matters, not the Tools used to get there.
Reply
#14
I think the VAL function works as intended:

QB (O) Help: The stringexpression is a sequence of characters that can be interpreted as a numeric value. The VAL function stops reading the string at the first character that it cannot recognize as part of a number. The VAL function also strips leading blanks, tabs, and line feeds from the argument string.

Since you're inputting a string with a space in the middle, Val will not recognise such as a numerical unit. Therefore I stand corrected to myself.

Considering this, you might have an outdated help file, or misread (-quoted) the help.

I hope it clears up a bit,

- Neo
Reply
#15
Did you insert the word "Leading" ?
Quote:Usage Notes
þ The VAL function stops reading the string at the first character that
it cannot recognize as part of a number. The VAL function also strips
blanks, tabs, and line feeds from the argument string. For example,
the code below returns the value 1615198

VAL(" 1615 198th Street")

This clearly shows that VAL will strip the blanks before and between 1615 and 198th.
t is the End result that matters, not the Tools used to get there.
Reply
#16
Quote:Did you insert the word "Leading" ?
No I didn't. I dont like it when people look at me that way, I could take it the wrong way. ("Who do you think you're talking to?")

Quote:VAL Function Details
Syntax
VAL(stringexpression)

The stringexpression is a sequence of characters that can be interpreted as
a numeric value. The VAL function stops reading the string at the first
character that it cannot recognize as part of a number. The VAL function
also strips leading blanks, tabs, and line feeds from the argument string.
For example,

VAL(" -33/LP")

returns the value -33.

This clearly shows VAL will not strip blanks from in-between a string. As I said before, you might have an outdated helpfile (the one from QB1 or QB4?).

- Neo
Reply
#17
The reason I suggested that, is thet the "Leading" was bold.
But I guess you highlighted it to point it out.

My help files are 1990 and came with QB4.5
I tested a leading blank as per
Code:
    print val(" &H" + A$)       'blank before &H
and that worked correctly.

So, are we to conclude that the qb4.5 compiler and help file was correct for that era, and then Microsoft changed it's mind with later compilers.?
or is anybody running the QB4.5 compiler and getting the same result as me.?
Edit
or is anybody running the QB4.5 compiler and getting the result as per the help file. ie: stripping blanks within the string.
t is the End result that matters, not the Tools used to get there.
Reply
#18
Dinaosaur:

I tried this:
Code:
PRINT "-";VAL(" 1616 198th Street")
ans got
- 1616198
Notice the leading blank i the string got printed!

Anytime I want to see if there is a leading blank or a trailing blank, I use the "-" to lead or to lag the string.

Yes, I use QuickBASIC 4.5
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#19
Ralph

Now all we need to get closure on this subject is for someone else to test it with BC 7.1

Regards
t is the End result that matters, not the Tools used to get there.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)