Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

unexpected loose of string value

kooka
Beginner
641 Views

Hi everybody,i have a wired problem, i am trying to retrieve some strings from an edit box,i can store the string in a variable, but when i later do anotheroperations i lose the string stored in my variable, i dont know the reason specially because this disn't happen before, but now isdriving me crazy. Im sure someone can help me.

IRET=GETDLGITEMTEXT(HDLG,IDC_NAME,str10,20)
IRET=GetwindowTextLength(hname)
IF(iret==0) THEN
IRET=MESSAGEBOX(HDLG,'Must Input Tendon Name','Input missing',ior(ior(mb_ok,mb_iconexclamation),mb_applmodal))
goto 10000
END IF

temp1(1)%name= str10 !---> i can store the string in temp1(1)%name

!get the material
iret = SendMessage(hipstyp1, CB_GETCURSEL, 0, &
0 )
iret = SendMessage(hipstyp1,CB_GETLBTEXT, iret, &
loc(str) ) ! afterthis command i loose the temp1(1)%name value and becomes = ' '

Thanks friends!

0 Kudos
6 Replies
Jugoslav_Dujic
Valued Contributor II
641 Views
How long is the str variable? Is it sufficient to hold the text selected in the combo? It seems as if it overwrote the adjacent memory.
0 Kudos
kooka
Beginner
641 Views

str10 is 23 chars long, temp1(1)%name is 20 long.

I already solve the problem by changing the position of this line ->temp1(1)%name= str10, to the end of the code I posted, so it finally comes this way. I don't know the reason but it works if you know please tell me.

IRET=GETDLGITEMTEXT(HDLG,IDC_NAME,str10,20)
IRET=GetwindowTextLength(hname)
IF(iret==0) THEN
IRET=MESSAGEBOX(HDLG,'Must Input Tendon Name','Input missing',ior(ior(mb_ok,mb_iconexclamation),mb_applmodal))
goto 10000
END IF

!get the material
iret = SendMessage(hipstyp1, CB_GETCURSEL, 0, &
0 )
iret = SendMessage(hipstyp1,CB_GETLBTEXT, iret, &
loc(str) )

temp1(1)%name= str10 !---> now it works

THANKS

0 Kudos
Jugoslav_Dujic
Valued Contributor II
641 Views
kooka:
str10 is 23 chars long, temp1(1)%name is 20 long.

I already solve the problem by changing the position of this line ->temp1(1)%name= str10, to the end of the code I posted, so it finally comes this way. I don't know the reason but it works if you know please tell me.

You didn't say how long is str (not str10!). Is it a character variable at all?

I wouldn't leave it this way if I were you. You have a serious memory corruption somewhere; by moving that line, you probably just moved the problem elsewhere, and it may easily show up again, on another place.

Try this:
  • Revert the code to the previous, "erroneous" state
  • Set a breakpoint (F9) at the CB_GETLBTEXT line
  • Run the program through the debugger (F5)
  • Open the Debug/Windows/Memory 1 window. Type "Temp1(1)%name" there. You should see a stream of bytes with the variable contents in that window.
  • Step over the CB_GETLBTEXT line (F10). You will see new memory contents in red. Try to figure out how it got overwritten.
  • If necessary, also open another Memory window (Memory 2) and watch the contents of str there.
The bottom line is that writing into temp1(1)%name and str shouldn't overlap. But somehow they do, and the problem is still in your code.
0 Kudos
onkelhotte
New Contributor II
641 Views

I agree with Jugoslav, moving the line only moves the problem to another place, it doesnt solve it. I know that, made my experience in memory corruption too :-) Cause and effect are not related in that case, so bad code doesnt produce an error at once, but later on. When you copy a variable for example.

Try these compiler settings: In Fortran -> Diagnostics set Generate Interface Blocks Yes and Check Routine Interfaces Yes. Get rid of all new reported warnings, move your line back to where it was and look if the error still occurs.

Markus

0 Kudos
kooka
Beginner
641 Views

tanks friends, i discovered the problem.

the problemis been caused by the str value -> 'pres ', it is overwritting part of the memory of temp1(1)%name, the problem is that, that value is been retrieved from a combobox, and the value is corrupted. When i want to put a string in the combo it has the value 'pres ', but when i send this message:

iret = SendMessage(hipstyp1, CB_INSERTSTRING, -1, &
loc(ACEROS(I)%NAME) )

the string is corrupted with a strange value comming-> 'pres ', I already probe this way:

iret = SendMessage(hipstyp1, CB_INSERTSTRING, -1, &
loc(trim(ACEROS(I)%NAME)) )

but gets this way -> 'pres~qJ '., now i can retrieve the value of temp1(1)%name adding a trim funtion to str

character(23) str, STR10

temp1(1)%name= trim(str10)

!get the material
iret = SendMessage(hipstyp1, CB_gETCURSEL, 0, &
0 )
iret = SendMessage(hipstyp1,CB_GETLBTEXT, iret, &
loc(trim(str)) )

but now i cant get the value of str because it becomes ' ' .

I am lost now

0 Kudos
kooka
Beginner
641 Views

finally i solved.

the code is

character(23) str, STR10

.....!omited code

!set the string in the combo box

iret = SendMessage(hipstyp1, CB_INSERTSTRING, -1, &
loc(trim(adjustl(ACEROS(I)%NAME))//' 'C) )

.....!omited code

temp1(1)%name= trim(str10)

!get the material
iret = SendMessage(hipstyp1, CB_gETCURSEL, 0, &
0 )
iret = SendMessage(hipstyp1,CB_GETLBTEXT, iret, &
loc(str) )

! all work fine, tanks

0 Kudos
Reply