IonicWind Software

IWBasic => General Questions => Topic started by: Andy on August 28, 2018, 07:05:19 am

Title: Data command question
Post by: Andy on August 28, 2018, 07:05:19 am
I've used several sub routines (with different names of course) to read in DATA Unicode strings and return a WSTRING like this:

Code Select

SUB AddRText(INT textLen,string TextName),WSTRING
wstring text = L""
pointer p = &text + 0
INT j,a

   restore at1Text
   restore at2Text
   restore YesText

FOR j = 1 TO textLen

if TextName = "A1" then GETDATA at1Text,a
if TextName = "A2" then GETDATA at2Text,a
if TextName = "Yes" then GETDATA YesText,a

*<char>p = a
p+=1
   NEXT j

   delete p
RETURN text
ENDSUB

DATABEGIN at1Text
data  160,3,193,3,191,3,195,3,184,3,173,3,195,3,196,3,181,3,32,0,188,3,185,3,177,3,32,0,189,3,173,3,177,3,32,0,195,3,197,3,189,3,196,3,177,3,179,3,174,3,0,0
dataend

databegin at2Text
data  179,3,185,3,177,3,32,0,177,3,197,3,196,3,204,3,189,3,32,0,196,3,191,3,189,3,32,0,192,3,181,3,187,3,172,3,196,3,183,3,59,0,0,0
dataend

databegin YesText
data  157,3,177,3,175,3,0,0
dataend


Now I'm using this sort of routine with different names to produce different texts for different screens.

Maybe I have six or seven of them, but when I try to add another sub with DATA the program crashes.

I am using WSTRING variables called:

Conf
Conf2
Conf3
Conf4 etc.

In each screen (OPENWINDOW) routine I'm doing this:

Code Select

sub DeleteCustomer()

DeleteConfirm = 0

openwindow confirm,0,0,600,230,0x80C00080|@NOCAPTION,w1,"",&handler_Confirm

CreateWindowW(L"STATIC",L"",WS_VISIBLE|WS_CHILD|SS_LEFT,20,20,100,25, confirm.hwnd, S_static3, GetModuleHandle(0), 0)
SetWindowTextW(GetDlgItem(confirm.hwnd, S_static3),StaticText(30,"Delete"))

CONTROL confirm,@STATIC,"",20,50,400,25,@CTEDITLEFT|0x200,STATIC_24
setcontroltext (confirm,STATIC_24,(getcontroltext w1,IDE_fName) + " " + (getcontroltext w1,IDE_lName))

conf = L""
conf = conf + DeleteCText(300,"S1")

conf2 = L""
conf2 = conf2 + DeleteCText(400,"S2")

conf3 = L""
conf3 = conf3 + DeleteCText(400,"S3")

CreateWindowW(L"STATIC",L"",WS_VISIBLE|WS_CHILD|SS_LEFT,20,90,630,25, confirm.hwnd, S_static, GetModuleHandle(0), 0)
SetWindowTextW(GetDlgItem(confirm.hwnd, S_static),conf + L" " + conf2 + L" " + conf3)

conf4 = L""
conf4 = conf4 + DeleteCText(300,"S4")

conf5 = L""
conf5 = conf5 + DeleteCText(400,"S5")

CreateWindowW(L"STATIC",L"",WS_VISIBLE|WS_CHILD|SS_LEFT,20,110,630,25, confirm.hwnd, S_static2, GetModuleHandle(0), 0)
SetWindowTextW(GetDlgItem(confirm.hwnd, S_static2),conf4 + L" " + conf5)

CreateWindowW(L"BUTTON",L"",WS_VISIBLE|WS_CHILD|BS_LEFT,20,150,100,25, confirm.hwnd, S_delete, GetModuleHandle(0), 0)
SetWindowTextW(GetDlgItem(confirm.hwnd, S_delete),L"         OK")

CreateWindowW(L"BUTTON",L"",WS_VISIBLE|WS_CHILD|BS_LEFT,480,150,100,25, confirm.hwnd, S_cancel, GetModuleHandle(0), 0)
SetWindowTextW(GetDlgItem(confirm.hwnd, S_cancel),L"    " + StaticText(30,"Cancel"))

SETFONT confirm,"Arial",12,400,0,S_static
SETFONT confirm,"Arial",12,400,0,S_static2
SETFONT confirm,"Arial",12,400,0,S_static3
SETFONT confirm,"Arial",12,400,0,static_24
SETFONT confirm,"Arial",12,400,0,S_cancel
SETFONT confirm,"Arial",12,400,0,S_delete
SETCONTROLCOLOR confirm,static_24,rgb(0,0,0),RGB(255,255,255)

waituntil IsWindowClosed(confirm)
closewindow confirm
return
endsub


But now I have added another DATA section - for another OPENWINDOW screen - my program crashes.

Code Select
SUB DeleteRText(INT textLen,string TextName),WSTRING
wstring textola = L""
pointer p = &textola + 0
INT j,a
   restore r1Text
   restore r2Text
   restore r3Text
FOR j = 1 TO textLen
if TextName = "R1" then GETDATA r1Text,a
if TextName = "R2" then GETDATA r2Text,a
if TextName = "R3" then GETDATA r3Text,a
*<char>p = a
p+=1
   NEXT j
   delete p
RETURN textola
ENDSUB

DATABEGIN r1Text
data 149,3,175,3,195,3,196,3,181,3,32,0,178,3,173,3,178,3,177,3,185,3,191,3,185,3,32,0,204,3,196,3,185,3,0,0
dataend

databegin r2Text
data 184,3,173,3,187,3,181,3,196,3,181,3,32,0,189,3,177,3,32,0,180,3,185,3,177,3,179,3,193,3,172,3,200,3,181,3,196,3,181,3,0,0
dataend

databegin r3Text
data 177,3,197,3,196,3,174,3,32,0,196,3,183,3,32,0,195,3,197,3,189,3,196,3,177,3,179,3,174,3,59,0,0,0
dataend


I've checked the length of the DATA strings, they fit the maximum length.

There is no duplication of DATABEGIN names.

If I comment out this new section the program works fine.

Does anyone have an idea why the program is crashing?

Or should I be deleting these DATA blocks? - if so how? the help file doesn't say.

Thanks,
Andy.
Title: Re: Data command question
Post by: LarryMc on August 28, 2018, 11:25:17 am
how big is your whole module?
Is this a single file program or a multi-file project?
If it is big you might try changing the STACK  size and STACK COMMIT size by a significant amount and see if it makes any difference.
Title: Re: Data command question
Post by: Andy on August 29, 2018, 12:01:25 am
Larry,

The program is built as a project.

6,500 lines is the size, I will look at the sizes you mentioned and have a try with that,

Thanks,
Andy.
Title: Re: Data command question
Post by: Andy on August 29, 2018, 06:36:59 am
Found the problem.

It was some sort of data "overflow".

This is how I sorted it.

Each of my DATA entries ends with two zeros i.e. 0, 0

Code Select

data 159,3,185,3,32,0,187,3,181,3,192,3,196,3,191,3,188,3,173,3,193,3,181,3,185,3,181,3,194,3,32,0,177,3,192,3,191,3,184,3,183,3,186,3,181,3,205,3,196,3,183,3,186,3,177,3,189,3,0,0


So I decided to check to see when I had two zeros next to each other - if so, break the For/Next loop and stop.

Code Select
SUB AddCText(INT textLen,string TextName),WSTRING
wstring text=L""
pointer p=&text+0
INT j,a,al
   restore c1Text
FOR j=1 TO textLen
al=a
if TextName="C1" then GETDATA c1Text,a
*<char>p=a
p+=1
if a = 0 and al = 0 then breakfor
NEXT j
   delete p
RETURN text
ENDSUB

DATABEGIN c1Text
data 159,3,185,3,32,0,187,3,181,3,192,3,196,3,191,3,188,3,173,3,193,3,181,3,185,3,181,3,194,3,32,0,177,3,192,3,191,3,184,3,183,3,186,3,181,3,205,3,196,3,183,3,186,3,177,3,189,3,0,0
dataend


Notes the lines:

INT j,a,al

al=a

if a = 0 and al = 0 then breakfor

So now when I call the sub routine I can use a far larger value than I need just to make sure I get all the data.

Code Select
conf = L""
conf = AddCText(300,"C1")


I did the same for all such sub routines that use DATA, and the problem is no more.

So I would suggest that if you are using DATA, it's best to have two bits of data that place at the end of your data - and check for it - then breakout of any loop reading the data.

Just a suggestion.

Andy.
:)

Title: Re: Data command question
Post by: LarryMc on August 29, 2018, 08:03:33 am
that's the recommended way of setting it up in the help file; i.e. testing for the end of the data
Title: Re: Data command question
Post by: Andy on August 29, 2018, 10:53:18 am
Yes it is,

Just a pity it doesn't make it clearer!

Or am I just not getting what I'm reading.

Andy.
:)