Wilson WindowWare Tech Support

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


Varytext and Strings Greater than 255 Characters

Keywords: 	  Varytext and Strings Greater than 255 Characters

Question:

I am creating a dialog box that will display a message passed to the script. If the message is >255 characters it crashes, as expected, when I define the variable text field. I have tried using the strcat trick to get around this, but get the 3951 error when string is >255 characters and I try to bring up the dialog. When I check the value by double clicking as if I were going to edit it, the full correct string is there, but when I look at the debug window the last section of the string is truncated. Any ideas?

Answer:

The problem is that you are not passing the varytext text field in as a variable, but rather as the "default" value. And with long strings it went past the 255 character limit on WinBatch statements. In converting from a STATICTEXT to a VARYTEXT you also have to take advantage of what varytext had to offer, as in accepting variable names.

Also @CRLF is not a valid delimiter. In the example below, I changed them to @CR which, in this case, works the same. Newer versions of WinBatch enforce the single character delimiter limit.

ayniMxLen = 0

;uncomment one of the following three lines to see the end result.
aynQstn = '"That short string works, however, this longer string will not work.  This%@CRLF%may not be because when the other options to define the field are added it%@CRLF%exceeds 255 characters"'
aynQstn = '"That short string works, however, this longer string will not work.  This%@CRLF%may not be because when the other options to define the field are added it%@CRLF%exceeds 255 characters."'
aynQstn = '"That short string works, however, this longer string will not work.  This%@CRLF%may not be because when the other options to define the field are added it%@CRLF%exceeds 255 characters.  Even"'

;let's find the longest line in the text so we can size the windows properly later
For ayni = 1 To ItemCount(aynQstn, @CR)
   aynStrCrnt = ItemExtract(ayni, aynQstn, @CR)
   If StrLen(aynStrCrnt) > ayniMxLen
      ayniMxLen = StrLen(aynStrCrnt)
   EndIf
Next

aynFormat = "WWWDLGED, 6.1"

aynCaption = "Test Example"

;make sure that we're sizing large enough to handle the longest line in the text
If ((ayniMxLen * 2.5) + 8) >= 120
   aynWidth = (ayniMxLen * 2.5) + 8
Else
   aynWidth = 120
EndIf

;make sure that we're sizing large enough to handle number of lines in the text
If ((ItemCount(aynQstn, @CR) * 9) + 20) >= 30
   aynHeight = ((ItemCount(aynQstn, @CR) * 9) + 20)
Else
   aynHeight = 30
EndIf

aynNumControls = 003
aynProcedure='DEFAULT'
aynFont='DEFAULT'
aynTextColor='DEFAULT'
aynBackground='DEFAULT,DEFAULT'

aynYesbtnx = (aynWidth / 2) - 40
aynNobtnx =  aynYesbtnx + 45
aynbtnsyaxis = (aynHeight - 20)

aynTemp = StrCat('4,0,%aynWidth%,DEFAULT,VARYTEXT,aynQstn,DEFAULT')
aynTemp = StrCat(aynTemp, ',DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT')

ayn001 = '%aynYesbtnx%,%aynbtnsyaxis%,036,012,PUSHBUTTON,DEFAULT,"Yes",1,1,32,DEFAULT,DEFAULT,DEFAULT'
ayn002 = '%aynNobtnx%,%aynbtnsyaxis%,036,012,PUSHBUTTON,DEFAULT,"No",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT'
ayn003 = aynTemp

answer = Dialog("ayn")

Exit