How to parse AskTextBox input?

Started by deming, August 10, 2023, 09:22:34 AM

Previous topic - Next topic

deming

I want to ask user for a list of numbers. Each row has 5 numbers, comma separated with @CR at end of each line. There are 100 or more lines. I can successfully parse the input into an array of 100 elements.  The problem is how to I now parse each line of the array into the 5 numbers?

; Prompt the user to enter a list of numbers n,n,n,n,n
; List will be 100 lines long
strInput = AskTextBox("Enter a list of numbers:", "Number List Input", "",0,0)

; Split the input string based on newlines to get each row
array = Arrayize(strInput,@LF)
arrRows = ArrInfo( array, 1)

; This DOESN'T work
; Loop through each row in the list of numbers
for j = 0 to arrRows
    ; Split each row based on the '-' delimiter to get individual values
    mystr = ""
    mystr = array(1)   ; ERROR HERE
    ParseData(mystr)
next

td

Perhaps it would help to spend a little more time with the Consolidated Help File?

A few of the easily identifiable problems:

  • Array indices are zero-based so the for-loop terminating value needs to be the number of rows in the array minus one. In your case "arrRows - 1"
  • The syntax for accessing an array element is array[integer] and not array(integer)
  • The point of iteratively extracting array elements in a for-loop is that the loop control variable is a ready array index value. For example, array[j].
  • ParseData works with space-delimited values in a string, not comma-separated values. See either Arrayize or ItemExtract. In the helpt file.

While there is nothing wrong with "Arrayizing" lists (I prefer arrays to item lists myself), you can also use the ItemList functions to accomplish the same tasks.


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade