I've manual pick problem for those checkbox layout in grid's first columns where there are all created in class object.
I'm able to picked success on first row, but it won't be appear when click on second row.
check box in entire column seem to be failed in random picked and unable to pick in identical for each row.
Coding :
define class chk_sel as checkbox
name = "chk_sel"
procedure init
this.value = 0
this.caption = ""
this.readonly = .f.
this.tabstop = .f.
endproc
enddefine
Define class frmpurc As Form
procedure init
For frm in _screen.Forms
if frm.name == "MyForm"
select "" as pick,supcode,item_desc,inv_no,po_no,line,acc_qty, ;
taxcode,acc_amt,net_tax,gros_amt from purc ;
into cursor tmpcur ;
where alltrim(inv_no) = alltrim(this.txt_search.value)
If NOT USED('tmpcur_')
USE DBF("tmpcur") in 0 AGAIN alias tmpcur_
else
USE IN 'tmpcur_'
USE DBF("tmpcur") in 0 AGAIN alias tmpcur_
endif
sele tmpcur_
frm.grid_list.recordsource = SPACE(0)
frm.grid_list.recordsource = "tmpcur_"
frm.grid_list.deletemark = .f.
frm.grid_list.readonly = .f.
frm.grid_list.column1.width = 25
frm.grid_list.column1.bound = .f.
frm.grid_list.column1.controlsource = "tmpcur_.pick"
frm.grid_list.column1.readonly = .f.
frm.grid_list.column1.text1.visible = .t.
frm.grid_list.column1.removeobject("text1")
frm.grid_list.column1.addobject("pick","chk_sel")
frm.grid_list.column1.currentcontrol = "pick"
frm.grid_list.column1.pick.visible = .t.
frm.grid_list.column1.pick.readonly = .f.
frm.grid_list.column1.pick.tabstop = .t.
frm.grid_list.column1.sparse = .f.
endif
endfor
endpro
enddefine
Thanks anyone could help me to solve this.
Few adjustments for you... Your for loop, should be a FOR EACH, otherwise, I had a compile error.
For EACH frm in _screen.Forms
Another shortcut for you on opening the table as editable is the READWRITE clause... and you can ensure the cursor is closed before querying with shortcut syntax
*/ Since SELECT( "someAlias" ) will return either the work area it is opened in
*/ or zero if the alias is not used, the USE IN states to CLOSE the table/alias
*/ in the given work area.
use in select( "tmpcur" ) && pre-close your read-only cursor result
use in select( "tmpcur_" ) && pre-close your read-write version of cursor
*/ Now, the query... FIRST, change the "PICK" column to a LOGICAL as that is
*/ the basis of binding to a checkbox control, not a space character...
*/ Then change the INTO clause...
select ;
.f. as pick,;
AllOtherFields ;
from ;
purc ;
where ;
alltrim(inv_no) = alltrim(this.txt_search.value) ;
into ;
cursor tmpcur
*/ Now, just open the result again as it was pre-closed
*/ if already open before the query
USE DBF("tmpcur") in 0 AGAIN alias tmpcur_
Now, all you are missing is the binding of your checkbox control. Change your
frm.grid_list.column1.bound = .T.
By setting to TRUE, you are stating you want it bound to each individual record.
There is so much thanks to your helps and I'm able to fix it. The check is finally bound to individual row.
There is only 2 modification done in my final code :
If NOT USED('tmpcur_')
USE DBF("tmpcur") in 0 AGAIN alias tmpcur_
else
USE IN select('tmpcur_') /*Change*/
USE DBF("tmpcur") in 0 AGAIN alias tmpcur_
endif
frm.grid_list.column1.bound = .t. /*It is bound to .f. in before */
For last mentioned things, I'm unable to put readwrite clause at behind of my cursor since I'm using Visual foxpro 6.0 which so far do not support it.
Related
I wasn't sure what my title should be, feel free to edit my post and change it if you can come up with something better.
There aren't many resources available on the use of Foxpro and what I'm trying to do is understand what is going on.
lldisdead=.t.
Select .f. as chkbox, * from a_counties ;
order by cn_area, cn_desc ;
into dbf (StrTmpFile1)
scan while !EOF()
IF ChkBox
selected_some_cnty = .t
endif
endscan
Here is my understanding:
Do the following as long as you are not in the last record of the
table:
IF ChkBox
Set selected_some_cnty equal to .t
Stop Check next record
Keep doing this until you are out of records.
What does IF CHKBOX mean?
Is it saying if the column CHKBOX is not null, do the following,
otherwise, do nothing.
Edit: Added additional code
If chkBox
in VFP, means:
if (chkBox)
also in all other well known languages, like C, C++, C#, Java, Go, Dart, Ruby, ... you name it - some languages parentheses are mandatory and some not. It simply mean "if chkBox is true". Sometimes you would see it written as:
If chkBox = .T.
like:
If chkBox == true
as in other languages, but it is more verbose than needed, and seasoned developers do not write it like that (after all writing like "if true is true" is awkward, simply "if true" is fine).
This is explained with comments placed in code:
* Initialize a memory variable named lldisdead as .t. (true)
lldisdead=.t.
* Select some fields into a table named m.StrTmpFile1
* StrTmpFile1 is a variable holding a string name of the table
* selecting all fields of a_counties table
* plus a boolean field named "chkBox" which is initially
* filled with .F. (false) value
Select .f. as chkbox, * from a_counties ;
order by cn_area, cn_desc ;
into dbf (StrTmpFile1)
* select's result table is table open in the current
* work area and by default located on first record.
* scanning the whole table
* with an unnecessary "while !EOF()" addition
* Default scope of scan is until EOF
scan while !EOF()
* Checking if chkBox field has a value of true
IF ChkBox
* if it has, than set "selected_some_cnty" memory variable to true
selected_some_cnty = .t
endif
endscan
Having said that, this part:
scan while !EOF()
IF ChkBox
selected_some_cnty = .t.
endif
endscan
could be written as:
scan
IF ChkBox
selected_some_cnty = .t
endif
endscan
further:
LOCATE FOR ChkBox
selected_some_cnty = !EOF()
However, since we know all chkBox values are .F., that piece of code is totally useless and could be deleted all together.
From the SQL query, the data is going into a physical table based on whatever the name "StrTmpFile1" variable is pointing to. Also note, the first column in this select statement is ".f. as ChkBox". So this is prepping EVERY RECORD in the query with a leading column that is ALWAYS False (hence .f.)
Select .f. as chkbox, * from a_counties ;
order by cn_area, cn_desc ;
into dbf (StrTmpFile1)
Now, I would suspect there is some other user interface action that is using this result table such as presenting in a grid in a form and allowing a checkbox on a column to let a user pick one or more entries to do something further.
After said selection (again, speculating intent), it is going through the loop to only find those records where the "ChkBox" COLUMN IN THE TABLE has been set to true and setting a flag as .t. that something WAS selected.
Overall, a very novice approach, but that is a different issue. A shortcut to getting the answer if a record as marked would be
select (the table)
Locate for ChkBox
selected_some_cnty = found()
Hope this helps, and if you need additional clarification, shoot a comment.
I have a dynamic webtable on a page in which i have to set values one by one. There is button to add webedit to that table.When i click on that button a webedit is get added, then i have to set a value in that. Same process i have to repeat for different values.
All the webedits have same properties only the name is different like
"name:=\$ABC_1\$ABCList\$l1\$ABCName" "name:=\$ABC_1\$ABCList\$l2\$ABCName"
"name:=\$ABC_1\$ABCList\$l3\$ABCName" . . .
"name:=\$ABC_1\$ABCList\$l200\$ABCName"
I am not able to identify the newly added webedit.
If there is a consistency in the name property you can identify the object using that. For example if it contains a counter you can do something like.
counter = 1
Browser("B").Page("P").WebButton("B").Click
Browser("B").Page("P").WebEdit("name:=\$ABC_1\$ABCList\$l" & counter & "\$ABCName").Set theValue
counter = counter + 1 ' repeat
The next best option is if the new WebEdit is the added after the previous values, in this case you can use the index property
counter = 1
Browser("B").Page("P").WebButton("B").Click
Browser("B").Page("P").WebEdit("name:=\$ABC_1\$ABCList\$l.*", "index:=" & counter).Set theValue
counter = counter + 1 ' repeat
Worst case (the name isn't consistent and nor is its index), you can store the names existing WebEdits and see what is new.
Set seenEdits = CreateObject("Scripting.Dictionary")
Function GetNewEdit()
Set desc = Description.Create()
desc("name").Value = "\$ABC_1\$ABCList\$l.*"
Set edits = Browser("B").Page("P").ChildObjects(desc)
For i = 0 to edits.Count() - 1
name = edits(i).GetROProperty("name")
If Not seenEdits.Exists(name) Then
seenEdits.Add name, True
Set GetNewEdit edits(i)
Exit Function
End If
Next
End Function
Browser("B").Page("P").WebButton("B").Click
GetNewEdit().Set theValue
Warning: All code not tested.
I would like to know if i can able to identify activeitem(below code) is available in SapGuiTree in SAP.
code:
SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree").ActivateItem "Inbound Monitor;11.05.2016;1111;Sales Movement","Sales Movement"
i tried below method but not worked
if isNull 'code' then
else
statement
end if
Can anyone suggest any method to identy this issue
Thanks in advance.
You can achieve this by checking all the node values under a SAPGuiTree object.
'Set Object
Set TreeObj = SAPGuiSession("a").SAPGuiWindow("b").SAPGuiTree("c").Object
'First you need to get all values under this tree
Set AllValues = TreeObj.GetAllNodeKeys
'Get count
Count = AllValues.Count
'Begin search the value you want
Found = 0
For i = 0 to Count-1
NodeText = TreeObj.GetNodeTextByKey(AllValues(i))
If NodeText = "SearchValue" Then
Found = 1
Exit For
End if
Next
If Found = 1 Then
'Do something
End if
Update1:
You can also use Regular Expression to do a pattern match when searching your desired value under a tree object.
I'm new to VBScript and I am running into some trouble. The script is making an API call and pulling account information, placing the data into a CSV file. I'm pulling the data into an array, looping through each account and, if certain properties qualify, assigning them to a variable to be written to the CSV. The problem I am having is if one account qualifies for a property, it sets the variable and if the next account doesn't qualify, the variable is still retaining the value, giving false results in the CSV.
Set SFTPServer = WScript.CreateObject("SFTPCOMInterface.CIServer")
accounts = SFTPServer.AdminAccounts
For each admin in accounts
adminName = admin.Login
Dim count : count = admin.GetPermissionsCount()
For i = 0 To CInt(count )- 1
Set permission = admin.GetPermission(i)
' AdminPermissionsPolicy:
' ServerManagement = 0,
' SiteManagement = 1,
' STManagement = 2,
' UserCreation = 3,
' ChangePassword = 4,
' COMManagement = 5,
' ReportManagement = 6,
Select case permission.Permission
case 0:
serverAdmin = "Server Admin"
case 1:
site = permission.SiteName
case 2:
stMan = "2"
case 3:
userCreate = "3"
case 4:
chPassword = "4"
case 5:
comMan = "5"
case 6:
report = "6"
End Select
Next
WriteStuff.WriteLine""+adminName+"|"+site+"|"+stMan+"|"+userCreate+"|"+chPassword+"|"+comMan+"|"+report+"")
Next
Unfortunately variables in VBScript are either at global, or function scope.
So you'll need to reset each of the variables on each iteration of the for loop.
One way would be to write Dim dummy at the top of your script, and just before the Select Case, write serverAdmin = dummy, site = dummy etc.
It's good practice to Dim explicitly all your variables, and to use Option Explicit at the top of the module to enforce that.
Here's an alternate way to do what you need without having to empty each variable on each iteration. You've already documented what each value means in your code. Instead of using comments for that purpose, define them as constants at the top of your scope block:
' AdminPermissionsPolicy:
Const ServerManagement = 0
Const SiteManagement = 1
Const STManagement = 2
Const UserCreation = 3
Const ChangePassword = 4
Const COMManagement = 5
Const ReportManagement = 6
Then you can declare an array to hold the values:
Dim a(6)
And then in your loop you can empty the array on each iteration using the Erase function. You can use the constant names instead of 0/1/2/etc and, when it comes time to write the values, you can use Join() to combine your array values into a string instead of having to concatenate 7 variables.
For each admin in accounts
adminName = admin.Login
Erase a ' Empty the Permissions array for each new account
Dim count : count = admin.GetPermissionsCount()
For i = 0 To CInt(count )- 1
Set permission = admin.GetPermission(i)
Select case permission.Permission
case ServerManagement: ' Now you can use the constant instead of "0"
a(ServerManagement) = "Server Admin"
case SiteManagement:
a(SiteManagement) = permission.SiteName
...
End Select
Next
WriteStuff.WriteLine Join(a, "|") ' Use Join() to combine array values
Next
Let's start with the output. You want to print a list of items (some of them possibly Empty) separated by "|". That should be done like this:
WriteStuff.WriteLine Join(aOut, "|")
Advantages:
You don't need to know that VBScript's concatenation operator is &, not +, because you can't even use the wrong one with Join.
You don't need to repeat the separator.
No useless pre/ap-pending of the empty string "".
Works with any number of items.
aOut needs to be initalized in the loop. That is easy with ReDim - without Preserve.
Advantages:
You don't need to know that Empty is the literal for empty/uninitialzed in VBScript.
You don't need to repeat an assignment for each variable.
Works with any number of items.
Demo code:
Option Explicit
Const cnUB = 3
Dim nTest
For nTest = 0 To cnUB
ReDim aOut(cnUB)
Select Case nTest
Case 0
aOut(0) = "A"
Case 1
aOut(1) = "B"
Case 2
aOut(2) = "C"
Case 3
aOut(3) = "D"
End Select
WScript.Echo Join(aOut, "|")
Next
output:
cscript 31565794.vbs
A|||
|B||
||C|
|||D
Disadvantage:
Putting the data into the array anonymously (just known by number/index) may be more errorprone than using distinct variable( name)s. If you need the elements for further computations it may be a good idea to define constants
wtf
Const ciReport = 1
...
aOut(ciReport) = "B"
He there, I'm new to VB script and I am trying to make a select case to change an emailadress to a combobox choice. I know i'm thinking to easy but i need help with the direction. the combobox works but i cannot get the value chosen in the combobox to trigger the select case.
Sub Item_Open()
Set FormPage = Item.GetInspector.ModifiedFormPages("Message")
Set Control = FormPage.Controls("Subject")
Control.PossibleValues = "SPOED;STATUS;MANCO;KLACHT;TRANSPORT;TRACKING;INKOMEND;REPARATIE;RETOUREN;LADEN;MILKRUN"
Set MyPage = Item.GetInspector.ModifiedFormPages("Message")
Set Mail = MyPage.Item("Subject").Value
Select Case Mail
Case SPOED
Item.To = "hihi#blabla.com"
Case STATUS
Item.To = "haha#blabla.com"
Case else
Item.To = ""
End Select
End Sub
Assuming MyPage.Item("Subject").Value returns a string value like "STATUS". Then you must pick it up in a string variable:
strMail = MyPage.Item("Subject").Value ' look ma, no Set!
The Select Case X statement evaluates the X expression and compares it to the values Y, ... in the Case Y parts and executes the first block for which (the values of) X and Y are equal. To apply this to strMail containing strings like "SPOED", the Case Y expressions should be string literals:
Select Case strMail
Case "SPOED"
...
Case "STATUS"
...
If you would have used Option Explicit, VBScript would have told, that SPOED (etc) is (understood as) an unitialized variable that can't be equal to a (decent) strMail.