none
Multiple variable text window input, like QBasic, i.e. Input A1, A2, A3 RRS feed

  • Question

  • It would be great if the TextWindow object had a multiple variable input operation such that the variables would be separated by commas.  Is there any possibility that feature could be added soon?  I have literally hundreds of programs in QBasic I want to convert to SmallBasic, but the input code to handle multiple variables is huge.

    Thanks,

    Mark

    Wednesday, July 10, 2013 4:35 AM

Answers

  • I'm afraid not! However, you can make your own parser subroutine,

    which would split a user's input by a delimiter character.

    In your case, that delimiter would be a comma.

    And the resultant split substrings would be stored in an Array for example.

    That's my basic idea!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, July 10, 2013 5:01 AM
    Answerer
  • How about making input subroutine such like this:
    TextWindow.WriteLine("Input A1,A2,A3")
    csv = TextWindow.Read()
    CSVtoArray()
    A1 = arry[1]
    A2 = arry[2]
    A3 = arry[3]
    TextWindow.WriteLine("A1=" + A1)
    TextWindow.WriteLine("A2=" + A2)
    TextWindow.WriteLine("A3=" + A3)
    Sub CSVtoArray
      ' param csv - input
      ' return arry[] - output
      ' return n - number of output
      n = 0
      p = 1
      l = Text.GetLength(csv)
      While p <= l
        _p = Text.GetIndexOf(Text.GetSubTextToEnd(csv, p), ",")
        If 0 < _p Then
          n = n + 1
          arry[n] = Text.GetSubText(csv, p, _p - 1)
          p = p + _p
        Else
          n = n + 1
          arry[n] = Text.GetSubTextToEnd(csv, p)
          p = l + 1
        EndIf
      EndWhile
    EndSub


    Nonki Takahashi

    Thursday, July 11, 2013 11:08 AM
    Moderator
  • More simple way.

    TextWindow.WriteLine("Enter any number or words. Add , [comma] to separate them")
    TextWindow.WriteLine("Example ..   12 , 3456 , test , 7890 , today")
    Inp= TextWindow.Read()+","
    len= Text.GetLength(Inp)
    get_data()
    dat=Temp
    TextWindow.WriteLine(dat)

    Sub get_data
      NN=0
      While len>0
        NN=NN+1
        delimP=text.GetIndexOf(inp,",")
        Temp[NN]= Text.GetSubText(inp,1,delimP-1)
        Inp= Text.GetSubTextToEnd(inp,delimP+1)
        len=Text.GetLength(Inp)
      endwhile
    endsub

    Thursday, July 11, 2013 1:51 PM
    Answerer

All replies

  • I'm afraid not! However, you can make your own parser subroutine,

    which would split a user's input by a delimiter character.

    In your case, that delimiter would be a comma.

    And the resultant split substrings would be stored in an Array for example.

    That's my basic idea!


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, July 10, 2013 5:01 AM
    Answerer
  • How about making input subroutine such like this:
    TextWindow.WriteLine("Input A1,A2,A3")
    csv = TextWindow.Read()
    CSVtoArray()
    A1 = arry[1]
    A2 = arry[2]
    A3 = arry[3]
    TextWindow.WriteLine("A1=" + A1)
    TextWindow.WriteLine("A2=" + A2)
    TextWindow.WriteLine("A3=" + A3)
    Sub CSVtoArray
      ' param csv - input
      ' return arry[] - output
      ' return n - number of output
      n = 0
      p = 1
      l = Text.GetLength(csv)
      While p <= l
        _p = Text.GetIndexOf(Text.GetSubTextToEnd(csv, p), ",")
        If 0 < _p Then
          n = n + 1
          arry[n] = Text.GetSubText(csv, p, _p - 1)
          p = p + _p
        Else
          n = n + 1
          arry[n] = Text.GetSubTextToEnd(csv, p)
          p = l + 1
        EndIf
      EndWhile
    EndSub


    Nonki Takahashi

    Thursday, July 11, 2013 11:08 AM
    Moderator
  • Thanks, that makes a lot of sense.  I am trying that now.
    Thursday, July 11, 2013 11:55 AM
  • More simple way.

    TextWindow.WriteLine("Enter any number or words. Add , [comma] to separate them")
    TextWindow.WriteLine("Example ..   12 , 3456 , test , 7890 , today")
    Inp= TextWindow.Read()+","
    len= Text.GetLength(Inp)
    get_data()
    dat=Temp
    TextWindow.WriteLine(dat)

    Sub get_data
      NN=0
      While len>0
        NN=NN+1
        delimP=text.GetIndexOf(inp,",")
        Temp[NN]= Text.GetSubText(inp,1,delimP-1)
        Inp= Text.GetSubTextToEnd(inp,delimP+1)
        len=Text.GetLength(Inp)
      endwhile
    endsub

    Thursday, July 11, 2013 1:51 PM
    Answerer
  • Wow, that works as well.  Thanks!
    Saturday, July 20, 2013 12:37 AM
  • More simple way.

    TextWindow.WriteLine("Enter any number or words. Add , [comma] to separate them")
    TextWindow.WriteLine("Example ..   12 , 3456 , test , 7890 , today")
    Inp= TextWindow.Read()+","
    len= Text.GetLength(Inp)
    get_data()
    dat=Temp
    TextWindow.WriteLine(dat)

    Sub get_data
      NN=0
      While len>0
        NN=NN+1
        delimP=text.GetIndexOf(inp,",")
        Temp[NN]= Text.GetSubText(inp,1,delimP-1)
        Inp= Text.GetSubTextToEnd(inp,delimP+1)
        len=Text.GetLength(Inp)
      endwhile
    endsub


    This solution (and Nonki's) could become a TechNet Wiki article and enter the July Small Basic Guru contest: http://social.technet.microsoft.com/wiki/contents/articles/18211.technet-guru-contributions-july-2013.aspx

    Great job!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Tuesday, July 23, 2013 6:27 AM
    Owner