Neil wrote:
1. What is the best way to check for negative integer values, i.e. if string = "-2", return #true.
Don't know about the best, since the definition of best depends on the requirements, yourself, etc.
One way is to simply modify IsStringDigits() to check if the first char is a sign and accept it as valid.
Neil wrote:
2. What is happening in the code lines marked with "???". I know that you are using pointers and I can read descriptions of them in the manual, but I still don't really understand the reasons for using them. Understanding what you have done in this snippet should help a lot.
Instead of using Mid(), Left(), Right() and so on you can use pointers (to chars in this case) to scan the string.
To do so you need a pointer to char initialized to the start of the string buffer and you need to move through the buffer incrementing that pointer.
The increment is done using the Sizeof operator instead of a simpler +1 because Char is defined to be 1 byte big in ascii and 2 bytes big in unicode (see help about data types).
This way the code works in both environments.
Why use pointers instead of the mentioned Mid() etc ? Essentially because incrementing a pointer with a linear access in memory is faster the calling a function like Mid(), and more importantly any string function like Mid() create a new string to return the result. Using pointers you just look at the already existing source string. Much more efficient.
In the code above I have a call to an helper function anyway (IsCharDigit), but this way is more modular, you can move its code inside the main proc to speed it up. Anyway, this was not made with speed in mind (very rarely I code looking for the faster code) , but using pointers came to no cost so why don't do it.
Nothing wrong in using mid() anyway, depends on the buffer size, how many times you call it, etc.
For checking a user input for example, all this makes no difference. It's just a good habit that can help you in writing better code later on.
Oh, forgot. The while terminates ad the end of the string because PB string are null terminated (the last char is a binary 0).
So when the pointer reaches it, the expression in the while becomes false.
Hope this helps, I'm going to sleep so if you have other question I'll read them tomorrow, or someone else will help you for sure.
Goodnight.... ronf....