none
Suggestion For 0.9 RRS feed

  • General discussion

  • My Suggestion: When there is an error, highlight that line of text red
    -Phillip Mikesell
    • Edited by phillips101 Thursday, April 15, 2010 3:08 AM
    Wednesday, April 14, 2010 5:06 AM

All replies

  • It is pretty much there for compilation errors (syntax, uninitialised variables etc), apart from the red highlighting - if you double click on the error message at the bottom of the window, the cursor is moved to the error line and the window is scrolled if required to display the error line.

    If you mean run-time errors after compiling (i.e. something that causes a crash like a fractional power of a negative number), then this would also be useful, but I suspect that a debugging mode where you can step through a program, set stop points and view variable values is ultimately the way forward for debugging.

    Wednesday, April 14, 2010 8:26 PM
    Moderator
  • oh, i never noticed that if you double click on an error message, it moves thetext cursor to the invalid line
    -Phillip
    Thursday, April 15, 2010 3:07 AM
  • Hi!

    unsollicited, but nevertheless maybe usefull. My wishes:


    0) warn for additions in writeline/write/drawBoundedtext/...

    It happens quite a few times that a simple addition in a write() is written without extra bracket.
    The problem is of course that the type might be unknown. But still a check for variable+variable would be nice.

    a=3
    b=6
    TextWindow.WriteLine("a+b="+a+b)
    TextWindow.WriteLine("a+b="+(a+b))
    TextWindow.WriteLine("a*b="+a*b)

    not really a big thing though.

    1) readnumber() and read() not allowed without a variable
    It is currently possible to write just

     textwindow.readnumber()

    without a variable. Since there is a PauseWithoutMessage() I suggest that the compiler should always check for a variabel to put the input in.

    2) turtle.circle(radius)
    Just a fun command to make some drawings possible without a need for a for..endfor-loop.

    3) penStyle

     graphicsWindow.PenStyle="dotted, dashed, ?"

    Sometimes it would be nice if there was a penstyle as well.
    another way to make this attractive and useful is with:

     graphicsWindow.SetPenStyle(linelength,spacelength)

    dots wil appear with graphicsWindow.SetPenStyle(1,10), lines with (5,5) etc.

    4) search and replace

    A search and replace Window? (CTRL-R)


    5) width=graphicsWindow.getTextWidth(text), height=graphicsWindow.getTextheight(text)

    depending on the current fonttype and fontsize


    6) graphicswindows.SaveAsBitmap(filename,x,y,width,height)

    save a part of the current graphicsWindow in a bmp file (or a png?)


    7) text.split(text,sep,array)

    splits the text in a string into an array

    example: text.split(s,";",word)

    would split s="bike;horse;wood" to word[1]="bike", word[2]="horse", word[3]="wood"

     

    8) imagelist.deleteImage()

    sometimes an image is no longer needed after a while.

    9) if (a=1) xor (b=2), if not((a=1) and (b=2))

    Introducing xor and not is indeed not Simple anymore, but gives a way to write conditions shorter.
    No idea what would be smarter for a beginner.

    10) graphicsWindow.drawRotatedAndResizedImage(imageName,X,Y,ScaleX,ScaleY,Angle)

    A way to draw images scaled and rotated without using a shape.
    the same goes for drawind Texts

     graphicsWindow.drawRotatedText(text,x,y,angle)


    11) using just a part of an image

     img1=imagelist.addImagePart(url,x,y,width,height)

    or from an existing image:

     img2=imagelist.addImagePart(imgname,x,y,width,height)

    this would give the opportunity to make a sliding puzzle more simple: add one single image and cut the 3x3/4x4 pieces with smallbasic-

    code


    12) image1=imagelist.CreateNew(width, height, backgroundcolor)

    creates a new and fresh bitmap in the imagelist

    of course this is useless without:

    13) drawing-commands for images, not just the graphicswindow itself

     imagelist.drawimage(imageDest, imageSource,x,w,width,height)
     imagelist.fillRectangle(imagename,x,y,w,h)
     imagelist.saveAsBitmap(imagename,filename,x,y,width,height)

    a very important reason for this wish is that it would give the possibility to draw in the background and then put it on the window at

    once.

    14) initialising large arrays fast
    I know i am doing stupid things, sometime. Using large arrays is one of them.

    After adding 500.000 elements, adding the next element becomes slower and slower.

     array.QuickFill(arrayname,1,1000000,"a","z",2,5,Value)

    would fill  arrayname[1]["a][2] upto arrayname[1000000]["z"][5] with Value

    using value="" would clear all these elements.

    15) Buttons and Fields

    If you don't dare, you won't win (Dutch proverb).
    New Group called something like 'Clickables' with

      component1 = Clickables.addButton(x,y,w,h,text)
      component2 = Clickables.addField(x,y,w,h,text)

      component1.ClickDown = HandleButtonClick
      component1.Change = HandleFieldChange

    Or can Shapes get a MouseDown event? And can a Inputbox be a new kind of Shape?
    The advantage of this way is that anything can become a button: rectangle, image, ellips...
    Buttons can be rotated, animated etc easily.

    16) Sound.PlayNote(channel, pitch, duration)

    uses? program a piano, play random sounds, listen to y=x^2, become an musician :-)

     


    thanks for a wonderfull Programming Language!

    kind regards,

    rene

    Thursday, April 15, 2010 9:10 AM
  • Hi!

    ...

    Many features you're requesting are already available through my extension. But I agree with you it would be great to have them included in the native packaging (maybe as optional, by using an 'Imports' syntax).
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Thursday, April 15, 2010 6:40 PM
  • GraphicsWindow

    .Show()

    Controls

    .AddButton(200, 21, "Test")

    G = Drawings.CreateGraphicsFromUI()

    Drawings

    .FillRectangle(G, "Red", 5, 5, 5, 5)

    I = Drawings.GenerateImage(G)

    C = Controls.AddImage(I)

    Controls

    .Move(C,10,10)


    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Saturday, April 17, 2010 8:21 AM
  • If this is the thread wher we can put suggestions, here is my first thoughts after my first project has been completed :

    1. A way to pass arguments to functions, as well as a return command to get back the result. If you don't want to use this, you can and nothing will change. If you want to learn how functions works in the real world, you could use this kind of things :

    TextWindow.WriteLine("5+2 = " + Addition(5,2))

     

    sub Addition(a,b)

    return (a+b)

    endsub

     

    I know that there could be troubles with variables as all the variables in Small Basic are global and this is the way it should be, but I'm sure you'll find something simple and educational way to implement this.

    I also know that you can do this using stacks, but what a pain...

     

    2. A way to play with sprites. I think that to begin, we should be able to create a sprite by adding geometrical forms. Something like grouping objects. Something like this :

    my_sprite = Shapes.AddRectangle(10,10) + Shapes.AddEllipse(20)

    But something is missing here, as we can't guess how the circle will be positioned relative to the rectangle. But I'm sure you got the point.

     

    3. A way to know if you have clicked or put your mouse inside a shape.

     

    4. A tone generator. Or more powerful, a sampler with lot of sounds and a way to easily sequence them.

     

    5. In a 1.0 version, that would be great if we could add a resource folder with all the attachment file we need (graphics, sounds) to be published with the code. 4 would then be less useful.

    Monday, May 10, 2010 7:42 AM
  • Hi! There is my idea:

    Change all Privates from SmallBasicLibrary.dll to public. It helps extending.

    I hope you get my idea.


    Sorry My Bad English
    Monday, May 10, 2010 2:33 PM
  • oh, i never noticed that if you double click on an error message, it moves thetext   cursor to the invalid line
    -Phillip


    Hahaha! That's pretty much in every program like this! For example visual studio! XD

     

    Suggestion 1:

    Please make it possible to split a program into multiple files. This would be so useful! Especially for big programs!

    For example something like this:

    On the right you have a list of Pages or Files. Just click on one of them and it brings them up. If you want a new one, simply click on "New Page/File".

    No "#include" and stuff needed. Everything is included automatically when compiling the program. I mean c'mon! Even scratch has something like this!

     

    Suggestion 2:

    Please make it possible to comment out code in multiple lines. Like the C/C++ "/* */" thing. That would be pretty useful.

     

    Suggestion 3:

    I know, you didn't want to add this because it makes the program more complicated. But that's not true if you do it right!

    Please make it possible to pass values to functions. And let the function return values. like: "return function(bla, bla)" Note, there's no "int" before "bla" or "function" or something like that ("return" means that the function returns a value. Without it, it simply doesn't return anything.)! We don't need this since smallbasic automatically handles variable types.

    "return function(bla, bla)" might be a little complicated for beginners. Thats why you should make the following possible:

    "function()" simply calls the function, like it does now. No values passed, no values returned. I think this would be a good and useful solution!

    Tell me what you think guys!


    Live for nothing, OR CODE FOR SOMETHING!
    Monday, May 10, 2010 3:26 PM
  • I'm playing with a card game and here what is missing for this kind of game : a way to set the level of a shape. When you add a lot of Shapes.AddImage(card), the frontmost will be the last you added, and you can't change the order. So, when you drag the first card you added, it will stay behind all the others.

    Perhaps a Shapes.Level(shape,level) or something like this would be useful.

    Monday, May 10, 2010 9:09 PM

  • Suggestion 1:

    Please make it possible to split a program into multiple files. This would be so useful! Especially for big programs!

    For example something like this:

    On the right you have a list of Pages or Files. Just click on one of them and it brings them up. If you want a new one, simply click on "New Page/File".

    No "#include" and stuff needed. Everything is included automatically when compiling the program. I mean c'mon! Even scratch has something like this!

     

    Suggestion 2:

    Please make it possible to comment out code in multiple lines. Like the C/C++ "/* */" thing. That would be pretty useful.

     

    Suggestion 3:

    I know, you didn't want to add this because it makes the program more complicated. But that's not true if you do it right!

    Please make it possible to pass values to functions. And let the function return values. like: "return function(bla, bla)" Note, there's no "int" before "bla" or "function" or something like that ("return" means that the function returns a value. Without it, it simply doesn't return anything.)! We don't need this since smallbasic automatically handles variable types.

    "return function(bla, bla)" might be a little complicated for beginners. Thats why you should make the following possible:

    "function()" simply calls the function, like it does now. No values passed, no values returned. I think this would be a good and useful solution!

    Tell me what you think guys!


    Live for nothing, OR CODE FOR SOMETHING!
    cool suggestions
    -Phillip Mikesell
    Tuesday, May 11, 2010 2:18 AM
  • The lack of user declarable functions() in SmallBasic is a serious flaw and certainly needs priority given to its implementation.

     

    However, the use of return function(bla bla) is a strange structure - where did that come from?

    The standard format is merely Return <value>  where 'value' can either be explicit or supplied by a variable... Return "DoRayMe", or Return myResultValue

    function() is also a strange suggestion - surely this is just a Sub?  The point of a function is that you can pass it values and return results.


     

    Even if you don't want to go to the bother of creating local/public variable scopes, just tell people to declare all variables related to their function with the pre-text of the function name to prevent clashes. So, say I want to create a function to sum all the numbers between given parameters...

    Function sumAll( sumAll_start, sumAll_end)
       for sumAll_loop = sumAll_start To sumAll_end
          sumAll_result = sumAll_result + sumAll_loop
       endfor

       Return sumAll_result
    endFunction

     

    No need to worry about variable scope in the above example. Just remind coders to put the name of their function as the first part of any variable names they use. Just call it with something like: mytot = sumAll( 1,10 )

     

    Surely it would be rather simple to modify the existing Sub() code to possibly just let Subs accept parameters, then add the additional Return method. 

    I don't see why this is even an issue.

    Tuesday, May 11, 2010 10:24 PM
  • Perhaps a Shapes.Level(shape,level) or something like this would be useful.

    I totally forgot about that! Many people recommended that feature in the other versions already! I would love to see that function.

     

    @Davey-Wavey:

    I don't really understand what you said. But I don't get where the problem is with my solution.

    But I thought of an evern simpler approach!

    You could just simply do it like this:

    "function(bla1, bla2) "

    and if you want the function to return a value, simply use "return morebla " inside the function. If there's no "return" inside the function, no value will be returned.


    Live for nothing, OR CODE FOR SOMETHING!
    Tuesday, May 11, 2010 10:55 PM
  • @Davey-Wavey:

    But I thought of an evern simpler approach!

    You could just simply do it like this: "function(bla1, bla2) "

    and if you want the function to return a value, simply use "return morebla " inside the function.

    Dudeson, that's what I said, so I agree with you completely :-)

    If there's no "return" inside the function, no value will be returned.

    A function that doesn't return a value is a Sub. The very definition of a function is that it returns a value. Indeed, it must return a value or otherwise it would never be useable 'inline' such as...

    if var="something" and myFunction(param)="something else" then...etc...

    or, mypalindrome = "rats live on " + reverse("rats live on")

     

    Do you instead mean that you are asking for existing Subs() to have parameters added to them?  (Which is also something that needs to be added to SmallBasic). I'm all for that.

     

    Wednesday, May 12, 2010 8:55 AM
  • A nice article which explain differences between subroutines and functions :

    http://computerprogramming.suite101.com/article.cfm/procedure__subroutine_or_function_

    As you said Davey, subroutines are just a way to put a part of the code away from the main code, and is very close to the goto statement. Functions have been created to pass and to get variables.

    The simplest way in Small Basic would be to promote subroutines into functions and not keeping both. And a function can be called without variables and can return nothing.

    But should we continue to call them Sub ?

    Wednesday, May 12, 2010 3:35 PM
  • A function that doesn't return a value is a Sub. The very definition of a function is that it returns a value.

     

    ____. I thought a Sub and a Function is the same thing. Just that the Small Basic version doesn't allow any parameters... I guess we were arguing for words..

    Live for nothing, OR CODE FOR SOMETHING!
    Wednesday, May 12, 2010 4:37 PM
  • I just came up with something thats easy to do, and is really needed!

     

    An atan2(v, u) function! That would be so helpful guys!


    Live for nothing, OR CODE FOR SOMETHING!
    Saturday, May 22, 2010 7:14 PM
  • Hi all,

    all the suggestions above (most of them) are very cool, but I still need something like

    Program.Run(path)

    - it will be amazing - for example my GraphicStudio or Wallpaper Convertor will include autoupload from my website and user will do nothing, just watch the progressbar and see new running version in  a minute !

    Next - I had some difficulties with recognizing if a variable contains text/signs or not. So something like

    Text.ContainsText(variable) = true/false

    should help.

    Many thanks for SB and please sorry my horrible english.

     

    Friday, May 28, 2010 8:21 AM
  • Text.ContainsText(variable) = true/false

     

    You can use  If variable<>"" then...  to do this.

    Friday, May 28, 2010 5:02 PM
  • well I dont want to know if it contains a value, but text - I want the program to get information if the variable contains ONLY NUMBERS or not.
    Tuesday, June 1, 2010 4:35 PM
  •  Vitexikora,
        You can use current Small Basic methods to check if a variable contains only numbers or not.

    'an enum of characters to check through
    numbers = "1234567890"
    
    'get some input to check
    TextWindow.Write("Enter some text >> ")
    var = TextWindow.Read()
    
    checkForOnlyNumbers()
    
    'print the results
    TextWindow.WriteLine("")
    If (onlyNumbers = "True") Then 
     TextWindow.WriteLine("The variable contains only numbers")
    Else
     TextWindow.WriteLine("The variable contains characters other than numbers")
    EndIf
    
    '---------------------------------------------------------------------------
    Sub checkForOnlyNumbers
     onlyNumbers = "True"
     For i = 1 To Text.GetLength(var)
     'TextWindow.WriteLine(Text.GetIndexOf(numbers, Text.GetSubText(var, i, 1))) 'for debugging purposes
     If (Text.GetIndexOf(numbers, Text.GetSubText(var, i, 1)) = 0) Then
      onlyNumbers = "False"
     EndIf 
     EndFor 
    EndSub
     

     

    Tuesday, June 1, 2010 5:58 PM
  • 1. FTP functions

    2. Linking multiple scripts

      circleradius = TextWindow.ReadNumber()

      circle = GraphicsWindow.DrawEllipse(Mouse.MouseX - circleradius, Mouse.MouseY - circleradius, circleradius/2, circleradius/2)

      ExternalCode.Start("C:\sbscript.sb", 3)

    THAT WOULD BE:

      ExternalCode.Start(path, line)


    |"| /"/|"""\ /"""\|"| |__ __| /\ |"""\ |"| | |/ / | " / | | || | | | / \ | |\ \ | | | |\ \ | | \ | | || |__ | | / \ | | \ \| | |_| \_\|_|\_\\___/|____| |_| /_/""\_\|_| \___|
    Tuesday, June 1, 2010 10:45 PM
  • Kroltan: FTP functions are included in Fremy's extension.

    Rushworks: Well it should be checked by your method, but it is too long, and I also want there decimal numbers.

    But what about the Program.Run(path) ?

    Can it be done, or can i do it alternatively, too ?

    Wednesday, June 2, 2010 3:48 PM
  • Vitexikora,

    The last one can be done with an existing extension to start external processes (Spawn).

    http://cid-92f7df0e57232aba.skydrive.live.com/self.aspx/.Public/SmallBasic/C%5E3%20Extensions/Spawn%5E_v0.8.zip

    Wednesday, June 2, 2010 5:08 PM
    Moderator
  • My big problem: Small Basic on a netbook (display 1024x600, Win7 Starter) is failed. The program window and the editor window are to high. :-(

     

    Greetings!

    Wednesday, June 2, 2010 5:16 PM
  • gabull,

    You can try the 'Maximize' button on the top right of the SmallBasic editor, just left of the window close cross and auto-hide the taskbar.  You may also have to make sure your GraphicsWindow is a good size, using commands like:

    GraphicsWindow.Top = 0
    GraphicsWindow.Left = 0
    GraphicsWindow.Width = 1024
    GraphicsWindow.Height = 600

    Wednesday, June 2, 2010 5:29 PM
    Moderator
  • and I also want there decimal numbers.

    Just add any character to the string of allowed characters

    'an enum of characters to check through
    numbers = "1234567890."

    Wednesday, June 2, 2010 6:04 PM
  • Hi litdev,

     

    my exacting problem: the editor window (the window with the source code) ist to high and it has not(!) a button left of the window close cross. :-)

    And the Win7 Starter has (apparently) not a auto-hide taskbar.

     

    Can you help me? Thanks!

     

    Wednesday, June 2, 2010 7:08 PM
  • gabull,

    Sorry no further ideas other than to look look at any settings or options there may be, I have no experience with Win7 Starter.  In other windows 7 the keyboard shortcut Windows+Up Arrow maximises a window  If you get no further help from this general thread, then try starting a new question thread with "Win7 Starter" somewhere in the title that may attract the notice of someone with more knowledge of this area.

    Wednesday, June 2, 2010 7:36 PM
    Moderator
  • Hallo litdev,

     

    I found the settings for auto-hide taskbar! I think it is working.

     

    Thank you!!!

    Wednesday, June 2, 2010 8:13 PM
  • When do you expect the new version? :)
    Thursday, June 3, 2010 5:39 AM
  • The coding for v0.9 is done and we're currently localizing the resources.  Expect the new version in about a week or two.

    Thursday, June 3, 2010 3:36 PM
    Moderator
  • Fine! Could you already give (some) clue about major (internal and external) changes ?
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Thursday, June 3, 2010 3:58 PM
  • Sure!

    1. There are a lot of performance improvements in the Primitive (variables) type.  This speeds up Math and tight loops significantly (sometimes by a factor of 3-4).

    2. A new Controls object which allows you to create buttons and textboxes and wireup events.

    3. A surprise inside "Sound" object.

    4. Shapes.AddText - now you can animate, rotate and zoom text.  And keep score updates from flickering or needing to erase background.

    5. Tons of small bug fixes reported by forumers.

    Thursday, June 3, 2010 5:47 PM
    Moderator
  • Seems a good start. I'll have to modify my extension to not conflict with the new objects, but it doesn't seems too complex.

    But I still apologize about the non-availability of true functions in Small Basic (with args and return value).
    Another small thing I didn't like is the that we can't define functions in our API that has a SmallBasicCallback (sorry, didn't remember the true name) as argument. So, many of my functions did in fact have a Primitive argument (the name of the function) and uses refelction to find the right function to call. It's a limiting performance factor and it's not very great from a developper point of view, I think. But this last point seems more complex to handle in SB, so don't worry about that.

    BTW, do you think you could give away a source code of the Small Basic Compiler? (I know you've some obligation from Microsoft about code you build for them, so maybe it's not possible, but who don't try don't get :D). Last time I did a decompilation of the SmallBasicCompiler.exe file, but I remember it wasn't very nice to modify. The fact is that I'm considering (not actually sure of that, but I'm thinking of it) to add a scripting language to one of my project. Originally, I use VB.Net for that kind of use cases, and additionnal APIs and RegExp to make the scripting more user-friendly, but this time I would need something more simple to learn and providing more functionnalities (GUI, ...), since it would be nice if even non-programmers could build add-ons to my project. The problem is that I would have to make a sort of fork of Small Basic, to match my internal API's. The libraries would be more or less the same, the objective is to solve small problems and design small interfaces, so SB and its current APIs is just fine for that.


    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Thursday, June 3, 2010 6:16 PM
  • more suggestions!

    1. Subs with proprieties!

    example:

    name = TextWindow.Read()

    age = TextWindow.Read()

    subroutine001(name, age)

    Sub subroutine001

      param1 = Subroutines.AddParameter(ParameterNumber )

      param2 = Subroutines.AddParameter(ParameterNumber )

      TextWindow.Write("Your name is " + param1 + ", and your age is " + param2)

    EndSub

    But why to have this? so we can call the sub with subroutine001(name ,age ) or subroutine001(anothervar , anothervar )

    2. Integrated Compiler!

    a button to compile the script into an .exe


    |"| /"/|"""\ /"""\|"| |__ __| /\ |"""\ |"| | |/ / | " / | | || | | | / \ | |\ \ | | | |\ \ | | \ | | || |__ | | / \ | | \ \| | |_| \_\|_|\_\\___/|____| |_| /_/""\_\|_| \___|
    Thursday, June 3, 2010 9:06 PM
  • Kroltan

    1] There has been quite a lot of discussion on argument variables - this would require the idea of SCOPE and create the requirement for variables being declared initially as global so they can be used in subroutines, or ALL variables being used in a subroutine being passed as arguments.  This would increase the complexity for simple programs and the concensus so far has been that it would add more difficulty for learning programmers - the idea is that SmallBasic is straightforward for beginners and when they want more there are plenty of more complex full featured languages.

    2] When you save a SmallBasic program somewhere (program.sb) and run it, an executable (program.exe) is created in the same place and can be run without the SmallBasic interface.  The exe can also be copied and used on any windows machine with .Net 3.5 SP1 as long as the SmallBasicLibrary.dll (and any extension dlls) are also copied.

    Thursday, June 3, 2010 9:48 PM
    Moderator
  • do i need to include the .pdb file?
    |"| /"/|"""\ /"""\|"| |__ __| /\ |"""\ |"| | |/ / | " / | | || | | | / \ | |\ \ | | | |\ \ | | \ | | || |__ | | / \ | | \ \| | |_| \_\|_|\_\\___/|____| |_| /_/""\_\|_| \___|
    Friday, June 4, 2010 12:09 AM
  • Sure!

    1. There are a lot of performance improvements in the Primitive (variables) type.  This speeds up Math and tight loops significantly (sometimes by a factor of 3-4).

    2. A new Controls object which allows you to create buttons and textboxes and wireup events.

    3. A surprise inside "Sound" object.

    4. Shapes.AddText - now you can animate, rotate and zoom text.  And keep score updates from flickering or needing to erase background.

    5. Tons of small bug fixes reported by forumers.

    Hi,

     

    If there is anything I can to localise into Dutch, please let me know.

    I suppose the xml file has to be translated fully?

     

    kind regards,

     

    René

    Friday, June 4, 2010 4:59 PM
  • Kroltan, The .pdb is not needed.
    Friday, June 4, 2010 5:17 PM
    Moderator
  • do not make it too difficult !
    Sunday, June 6, 2010 7:07 PM
  • well I dont want to know if it contains a value, but text - I want the program to get information if the variable contains ONLY NUMBERS or not.

    Vitexikora,

    In that case, just do something like the following...

     

    numbers = "0.12345n6789"
    
    If math.Abs( Math.Ceiling(numbers+1) ) > 0 Then
     TextWindow.WriteLine( "'" + numbers + "' is a number" )
    Else
     TextWindow.WriteLine( "'" + numbers + "' is NOT a number" )
    EndIf
    

     

    The only issue to be aware of by using the math.abs/math.ceiling checks are that they will report as valid numericals if 'number' is completely empty, but that's easy to avoid by adding an additional AND numbers<>"" check into the If statement.

    Also be aware that, quite logically, if the 'numbers' value begins with a + or a - then it will report as a valid numerical. eg. '+42' is a number; '-63' is a number. 

    You could change the If check to...

    If -Math.Ceiling(numbers) < 0 Then

    which would give a result for '-63' as NOT a number (to indicate the presence of the minus sign, which is not a number) and would additionally report blank strings as NOT a number, but this would still report '+42' is a number; so if you considered the presence of '+' at the beginning of the string not a number, you would have to check for it specifically.

    A full check (that considered blank strings and a beginning + or - as making the value 'not a number') would be...

    If (-Math.Ceiling(numbers) < 0) AND (text.StartsWith(numbers,"+")<>"True") Then
    

    Monday, June 7, 2010 10:19 PM
  • In my world, we call this an horrible workaround. The size of the code needed is too huge for the purpose.

    You're peforming mathematical operations that are not needed. As a result, the time needed to perform the task is much greater than the time the real operation should take! This is clearly not an acceptable solution. (Don't forget each time you return from a 'managed code' you convert a string to a number, and then a number to a string back.

    BTW, there's a simpler workaround: 

    If (Nbr+0) = Nbr Then
      ' It's a number
    EndIf

    This is still a workaround, but it looks clearer. A String would not pass this assumption because "0A"+0 will become "0A0" and will not be equal to "0A".

    Test application :

    While "True"
     S = TextWindow.Read()
     If S = "" Then
      Program.End()
     ElseIf (S+0) = S Then
      TextWindow.WriteLine("Valid number")
     Else
      TextWindow.WriteLine("Not a number")
     EndIf
    endwhile
    

    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Tuesday, June 8, 2010 6:19 AM
  • Fremy,

    It depends on what Vitexikora is looking for exactly, so this is all swings-and-roundabouts.

    You're on the right track though, although you do lose some time with your extra If checks.

     

    If Vitex wants to check if the value only contains numerical digits (0-9), he could use:

     

    If ("+" +S+ ".") = S Then ... which means "+12.3" and "-12.3" and "12.3" and "" etc. are considered NOT pure numericals.


    Or, if he wanted to check if the value contains a valid numerical expression, he could use: 

    If (S+" ") = S Then ... which means "+12.3" and "-12.3" and "123" and "12.3" are valid, but "" is not valid.


    Or, if he wants to allow only numerical digits (0-9) with or without decimals, he could use:

    If ( "+" +S) = S Then ... which means "+123" and "-123" and "" are considered NOT pure numericals.



    I don't consider any of these a 'horrible workaround' as they use standard conventions and offer proper flexibility without the need for extra methods or functions.

     

     

    Tuesday, June 8, 2010 3:23 PM
  • I don't consider any of these a 'horrible workaround' as they use standard conventions and offer proper flexibility without the need for extra methods or functions.


    Well, they really slow in comparaison of what's needed. We should not teach a beginner to do like that.

     

    Apart from that fact, you're true that based on the meaning of "numerical value", different solutions are possibles, based on the chars we may of may not accept. The fact is that we're using a full parsing of the number here, that's not theorically needed, we could work on the String. It would be times faster. The only problem is that the lack of functions in Small Basic would make this very complex, so, well, we should forget that :D


    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
    Tuesday, June 8, 2010 5:21 PM