Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble editing a Listbox entry

Status
Not open for further replies.

dantheinfoman

Programmer
May 5, 2015
131
US
Hi All!

Thanks to all my tek-tips homies for all the beautiful tips and assistance lately! I have another error I keep running into. Everytime I'm looping through this ListBox and I find something I want to change, it won't let me and gives an error:

I have 2 listboxes if that makes a difference. When I click on the 2nd listbox this code runs to find the variable myField in order to loop through listbox 1 and find a match. If found, I want it to be able to edit a part of the 1st listbox but it gives me this error:
Screen_Shot_05-08-15_at_05.14_PM_k0bkng.png


Here's the code in full:
Code:
myLI = thisform.ntest.ListIndex &&selected row num
*WAIT WINDOW myLI
&& Field array element columns.
PRIVATE nDescE, nNameE, nTypeE, nLenE, nDecE, nNotE, nOperatorE, nCriteriaE
PRIVATE nEqualTo, nGreaterThan, nLessThan, nContaining, nBetween, nInlist
&& Misc. variables.
 
*!*	   nRptSel = Reports.lstReport.listindex
*!*	   cDatabase = aRpt[nRptSel,3]
*!*	   cDatabase = UPPER(ALLTRIM(cDatabase)+".DBF")
*!*	   cSortOrder = IIF(TYPE("cSortOrder")=="C",UPPER(ALLTRIM(cSortOrder)),"")

   nField = 1
   nRptDlgBttn = 1
   nClearBttn = 1
   nRptExprBttn = 1
   lNot = .F.
   nOperator = 0
   cCriteria = SPACE(0)


   nEqualTo     = 1
   nGreaterThan = 2
   nLessThan    = 3
   nContaining  = 4
   nBetween     = 5
   nInlist      = 6   

   DIMENSION aOperator[6,2]
   aOperator[nEqualTo,1]     = "Equal To    "
   aOperator[nGreaterThan,1] = "Greater Than"
   aOperator[nLessThan,1]    = "Less Than   "
   aOperator[nContaining,1]  = "Containing  "
   aOperator[nBetween,1]     = "Between     "
   aOperator[nInList,1]     = "In List     "
   aOperator[nEqualTo,2]     = " = "
   aOperator[nGreaterThan,2] = " > "
   aOperator[nLessThan,2]    = " < "
   aOperator[nContaining,2]  = " CONTAINS "
   aOperator[nBetween,2]     = " BETWEEN "
   aOperator[nInList,2]     = " IN LIST "
   
   nExprE     = 1 && char representation of expression
   nDescE     = 2 && short name of db field (descript_s) 
   nFieldE    = 3 && actual field name
   nTypeE     = 4 && field type
   nLenE      = 5 && field lenght
   nDecE      = 6 && field decimal if any
   nNotE      = 7 && do you want not: .T. (NOT) or .F.
   nOperatorE = 8 && operator in expression <, >, =, etc.
   nCriteriaE = 9 && example of criteria
*!*	WITH thisform.ntest
	*WAIT WINDOW .list(myLI,1)
	*WAIT WINDOW ALLTRIM(.list(myLI,2))
	

	
	
	
	x=2 &&starting column 3 is field Cri1, column 4 is Cri2
	
	FOR x = 2 TO 2
		
		IF	!EMPTY( thisform.ntest.List(myLI,x) )
			
			*GET ACTUAL FIELD NAME
			lcX = ALLTRIM( thisform.ntest.List(myLI,x) )
			
			ALINES(myArray, lcX, 0, ";")
			
			myField = ALLTRIM(myArray(1))
			
			
			**search for this field within nField listbox
			PRIVATE i
			
			FOR i = 1 TO ALEN(aFieldList,1)
				
				IF ALLTRIM(aFieldList[i,nFieldE]) = myField THEN						
					WAIT WINDOW aFieldList(i,nFieldE)

					**************************
                                        *HERE IS THE LINE BELOW THAT THROWS AN ERROR*                                         
					[b]aFieldList(i,nExprE) = PADR("Sally",25,"")&&aFieldList[i,nExprE][/b]
                                        **************************

					WAIT WINDOW 8
					aFieldList[i,nFieldE] = myArray(1)
				    aFieldList[i,nNotE] = myArray(2)
				    aFieldList[i,nOperatorE] = myArray(3)
				    aFieldList[i,nCriteriaE] = myArray(4)
				    
			*!*		    aFieldList[i,nNotE] = .F.
			*!*		    aFieldList[i,nOperatorE] = 0
			*!*		    aFieldList[i,nCriteriaE] = SPACE(0)
			*!*		    aFieldList[i, nExprE] = LEFT(aFieldList[i, nDescE],25)
				ENDIF
			ENDFOR
		ENDIF
	ENDFOR
	
	
	ThisForm.nField.refresh()
*!*	ENDWITH

Thanks, you guys are all geniuses!!
Dan
 
nExprE?

Look up what the error means, notice you don't initialize any variable nExprE, which means it will be .f., but must be numeric.

Bye, Olaf.
 
nExprE = 1 && char representation of expression

You're initializing it numeric. How is that a char representation?

You have a data type mismatch within your comments as well as your code. [dazed]
 
I see, means I was wrong, I overlooked that initialisation with 1 even though I swear I did a STRG+F search.

Adressing a list array element is the only thing you do in that line erroring.
Hm, so how about PADR("Sally",25,"")?
This errors, if you don't give a pad char. You can't specify an empty string as a pad char. That "" value is wrong. You can't pad with nothing, that would mean no padding.
If you want to pad with space, that's the default char anyway, just PADR("Sally",25).

Bye, Olaf.
 
Thanks guys. I have tried lots of other things to make aFieldList(i,nExprE) equal to, such as
aFieldList(i,nExprE) = "Sally"
and it still bears the error.

I can make it work prior to loading the 2nd listbox. To load it, I'm using a button temporarily that says to use a table and additem a bunch of stuff to the 2nd listbox. My thinking is when I use or select this dbf file it somehow releases or takes focus off the array aFieldList and I don't know how to get it back.
 
You need to use the debugger to step through the code and examine each variable involved here. One (or more) of them contains a value that is different from what you think. The debugger will tell you.

 
Using an array aFieldList is weird anyway. Using Additem you'll add items to listbox.list(). Variables typically are local or private scoped and release after code ran, you can't refer to it later. You edit the listbox list.

Bye, Olaf.
 
Hi Everybody! Quick update. I finally got it working. For some reason I had to tell it to drop that table after I'd loaded the second listbox (Select C USE ) and then it stopped freaking out about the array!

Then I had to tweak some of the fields going into the first listbox from Character to numeric using VAL() and logical using an if then statement because I couldn't convert ".T." to .T. without an if then.

Thanks to everybody for your amazing tips. I'm learning so much. Thanks for the PADR help as well!

Unfortunately, my predecessors buried these apps within an exe and it's darn near impossible to debug. That's why I use a lot of wait windows to see what the heck is going on.

You guys are marvelous. Thanks!!!

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top