Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Itembox use with variable

Keywords:	 Itembox select Item box in dialog Editor use with variable param

Question:

I have a dialog with one or more Itemboxes. The user may select one or more items from the lists. In the same main window, I also have a 'Help' button. This button will display an AskFileText with some information related to the main window. But when the user clicks on OK in the AskFileText window, the ItemBox(es) in the main window will no longer display all its original items, only the items that were selected before Help button was clicked on!

Any ideas? Do I need to refeed the ItemBoxes when they get redrawn?

Also, can I make it so the user can select only one item in the ItemBox? (I may have already asked this long time before)

Answer:

>>Do I need to refeed the ItemBoxes 
>>when they get redrawn?
Yes. The ItemBoxes use the same variable for input and output. When the user hits the HELP button, you exit the dialog, and then restart it later. It will use the value of the listbox variables, which is the items the user selected. So you have to refeed the ItemBoxes variable (and the user looses any items they may have set...
>> Also, can I make it so the user 
>>can select only one item in the ItemBox?
Use IntControl(33,0,0,0,0)

Example of Using Variables with Itembox

You are presumably familiar with the ITEMBOX control, which lets you view a delimited-list variable. It has a vertical scroll bar. Loading a small text file into the ITEMBOX variable is easy (using FileRead, or, even better, BinaryRead). So all that's left is to write a word-wrap routine.

Here's an example of how to create the variable to use in the ITEMBOX control. My word-wrap routine is pretty basic, and could certainly be improved upon.


  ; ----------------------------------------------

  file = "testfile.txt""  ; text file to view
  wrap = 40              ; maximum line length

  ; ----------------------------------------------

  buffer = BinaryAlloc(FileSize(file))      ; allocate binary buffer
  size = BinaryRead(buffer, file)           ; read file into buffer
  items = BinaryPeekStr(buffer, 0, size)    ; get buffer contents into string
  items = StrReplace(items, @CRLF, " ")     ; change all @CRLF to spaces
  size = BinaryPokeStr(buffer, 0, items)    ; and put string back in buffer
  BinaryEodSet(buffer, size)                ; update end-of-data marker
  offset = wrap                             ; starting position for search

  ; Word-wrap routine.  We stripped out all CR-LF terminators above.  The idea
  ; here is to advance our pointer ("offset") the maximum line length (as
  ; specified by the variable "wrap"), and then search backwards for the first
  ; space.  That's where we break the line, by changing the space to a tab
  ; (our new delimiter).  Then set our pointer to that position, and repeat.

  While @TRUE

    ; search backwards for the first space
    space = BinaryIndex(buffer, offset + 1, " ", @BACKSCAN)

    ; If there are no spaces between the beginning of the line and the "wrap"
    ; position, we will use the first available space *after* the wrap
    ; position, which will result in a line longer than requested.  An
    ; alternative would be to try wrapping at a tab or a punctuation mark.

    If space <= offset-wrap Then space=BinaryIndex(buffer,offset," ",@FWDSCAN)

    ; change the space to a tab (ASCII 9)

    BinaryPoke(buffer, space, 9)

    ; advance the pointer

    offset = space + wrap + 1

    ; if the pointer is past the end of the file, then we have a chunk of text
    ; smaller than "wrap" characters left, which means that we're done

    If offset >= size Then Break

  EndWhile

  items = BinaryPeekStr(buffer, 0, size)    ; get buffer contents into string

  BinaryFree(buffer)                        ; free the binary buffer

  ; "items" is a tab-delimited list, suitable for use in an ITEMBOX control

  TextSelect("Select a line", items, @TAB)  ; just to see what we've got


Article ID:   W12846
Filename:   Itembox Use with Variable.txt