Checking out data models in power designer with VBScript - vbscript

Through a VBS code I need to check out some data models from the power designer.
The requirements are: Connect to the power designer repository, check out some data models. can anybody help me?
I found this code in SAP documentation, but when i execute it the following error appears.
Dim rc : Set rc = RepositoryConnection
'Check out model
Dim TargetModel
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
TargetModel.CheckOut()
Output "Checked"
The error messege:
Microsoft VBScript Runtime Error
Required object (0x800A01A8)
on line 5

As mentioned by the first comment, at least, verify the FindChildByPath return value:
Set TargetModel = rc.FindChildByPath("MyFolder/MyPDM", PdRMG.Cls_RepositoryModel)
if targetmodel is nothing then
output "nothing"
else
TargetModel.CheckOut()
Output "Checked out"
end if
Apart from that, the sample works for me, and opens the PDM I have checked in.

Related

Report sometimes returns 0 records in SAP GUI script

So I've recorded a script using the SAP GUI recorder. I'm basically just running 7 reports and saving the contents to an excel file. The code is uninspiring, just some variation of.
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
But sometimes there are no records in the report.
I suspect there is something I can check to either save the report or move on using if/then/else but cannot find a good example. How do I catch and recover from this or other errors?
Is there a way to to sapshcut�or structure the script to avoid this problem?
Also, is there a way to execute the script from the command line, passing in the userid and password as parameters?
Relevant examples welcome. I'd RTFM but I don't have one.
If the report is a grid, then you could try the following.
for example:
...
session.findById("wnd[0]/tbar[1]/btn[8]").press
on error resume next
'This command must be recorded once in your environment. It's a mouseclick in the first line.
session.findById("wnd[0]/usr /subSUB_AREA_ROOT:SAPLREIS_GUI_CONTROLLER:0200/subSUB_AREA:SAPLREIS_GUI_CONTROLLER:1000/cntlCC_LIST/shellcont/shell").currentCellRow = 1
if err.number = 0 then
on error goto 0
...
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "SAP_ALL.TXT"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 11
...
else
on error goto 0
...
end if
...
Please take a look at the following link:
VBA 2010 - Hide all SAP windows using .iconify
Regards,
ScriptMan

VBScript, open Read-only documents in edit mode - Word 2013

I've been struggling to find a way to open a Read-only document in Normal/Edit mode instead of Reading mode with MS Word 2013. Word 2013 by default enables the start up option to "Open e-mail attachments and other uneditable files in reading view".
How would I go about disabling this option or changing the view from Reading to Normal/Edit view when the document is opened. (I need to keep the document as read-only as it might be accessed by multiple people at once)
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(documentPath,,True)
objWord.ActiveWindow.ActivePane.View.Type = wdNormalView
I have tried to set the view mode using the above but received the an error code shown below. I looked at other variations of line 3 but can't get it to work. I'm still working my way around learning VBScript so I'm assuming i'm not doing this the right way.
Error: One of the values passed to this method or property is out of range
Code: 800A16D3
Source: Microsoft Word
Thanks.
You're using VBScript - it doesn't understand what wdNormalView means. This is an internal value for VBA. You need to find the actual value held for this constant and apply that instead. The constant is a WdViewType and the values are as follows:
Name Value Description
wdMasterView 5 A master view.
wdNormalView 1 A normal view.
wdOutlineView 2 An outline view.
wdPrintPreview 4 A print preview view.
wdPrintView 3 A print view.
wdReadingView 7 A reading view.
wdWebView 6 A Web view.
So the option you want to select is 1. Try the following code and see if this works:
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(documentPath,,True)
objWord.ActiveWindow.ActivePane.View.Type = 1

compile error: method or data member not found in vb6

Hi all I am a php developer but since working in an organisation I got a work on a vb6 project.
The software is quite old let say atleast 10 year and I don't know vb6 at all. But still I manage to solve some errors but now I stuck on and I didn't get any solution. I have got this error when compiling the project, highlighting this code.
with .Panels(6) = selected.
Public Sub StatusBarDateTime()
'' FrmMain.Stb1.Panels(5) = Time
FrmMain.Stb1.Panels(6) = Format(Date, "dd-mmm-yyyy")
End Sub
and when I delete this line on code it show another error that
Compile error:
Sub or Function not defined
highlighting this line of codes
Private Sub MDIForm_Load()
StatusBarDateTime
End Sub
I assumed that it is declaring the function. so I delete this function also.
Now after deleting this when I compiled againg I got this error saying that
Run time error'481'
Invalid picture
and when I click on debug it shows this line of code
Private Sub Form_Load()
FrmMain.Show
Dim strUser As String
Call Center_Align(FrmLogin)
OpenConnection
strUser = "select * from TMUser order by login_name"
rsUser.Open strUser, conpgdhm, adOpenKeyset, adLockOptimistic
Set CmbUserID = rsUser
CmbUserID = "login_name"
CmbUserID = "login_id"
End Sub
highlihting Set CmbUserID = rsUser line. and now I got nothing.
I don't know how many error may I get after resolving this but that is the next part.
First I have to solve this. I have no idea how to resolve this.
I am banging my head around for two days now, If someone can help me please.
Thanks in advance.
Those were helpful....
The reason it's stopping there is because you are attempting to assign a datareader (or whatever object type rsUser is) as the value to a string or int type (CmbUserID)
You are trying to fit a whole bag of rectangles into a round whole. This is in reference to your latest error only. Based on what I see here, you lack the experience in VB6 to continue without some assistance. I suggest a consultant.
Hope this helps.

Need Assistance with VBSCRIPT to capture screenshots of user's desktop

I am a novice when it comes to object oriented program. That said, I have been trying to construct a vbscript that will capture a screenshot of the desktop and immediately save it to a folder I specify. Here is the code I have so far:
' START
Dim screenSize
screenSize = New screenSize.Size(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y)
Dim screenGrab
screenGrab = New screenGrab.Bitmap(My.Computer.Screen.Bounds.Width, my.Computer.Screen.Bounds.Height)
Dim g
g = g.System.Drawing.Graphics.FromImage(screenGrab)
dim copyS
copyS = Graphics.CopyPixels4.PaintEventArgs
dim copyS2
copyS2 = copyS.Graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation)
dim saveTo
saveTo = screenGrab.Save("C:\temp\screenGrab.bmp")
' END
I prefer to keep this in VBSCRIPT as this script will be incorporated into an existing vbscript I created. I currently get an error at line 3 stating "class not defined 'screensize". I am also concerned that even if I fix the error at line 3 I may run into other syntax issues afterward. The overall intent of the script is to 1) get the screen dimensons ; 2) perform the screenshot ; 3) and save the file to a destination. I am open to any suggestions to make this work.
I appreciate any help I can get at this point. Thank you.
It seems like you have messed VB.NET with VBScript.
screenSize, screenGrab, System.Drawing.Graphics - there are no such classes in VBScript by default.
What I'd suggest is to use some screen capture ActiveX (google it).
Or create your own ActiveX with VB6 by using code like this. Create new ActiveX project in VB6, add that module and compile.
And remember to run regsvr32.exe youractivex.ocx before using it in your script.

VB6 ADODB Record Set Update

So I'm pretty new to Visual Basic and inherited this VB6 code that i need to work on now. Right now, I'm trying to update a SQL database using an ADODB.RecordSet. I have a Select SQL statement that pulls the right data from the database into the ADODB.RecordSet, but I'm having problems updating all the rows. What I am trying to do is to update the same column for each row with the same value. Right now, its updating a few of the records, but I'm getting an error pop up. The error I get is:
Run Time error 3021: Either BOF or EOF
is True or the current record has been
deleted. Requested operation requires
a current record.
When I click to debug, it takes me to rsUpdate.fields(TargetFieldName) = value
The project itself is huge and too large to post, but the part of the code that I'm working on now is this:
If rsUpdate.State = adStateOpen Then
If rsUpdate.EOF Then
rsUpdate.Close
Exit Function
End If
rsUpdate.MoveFirst
Dim i as Integer
For i = 0 To rsUpdate.recordCount
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
Next i
On Error GoTo canupdaterecord
rsUpdate.Update
On Error GoTo 0
rsUpdate.Close
End If
Exit function
So any help you guys can give me would be greatly appreciated. Like I said, I'm pretty new to VB and am kind of learning this all as I go.
I would guess the problem is an off-by-one error:
For i = 0 To rsUpdate.recordCount
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
Next i
If recordcount returns 5, this loop will make 6 runs: 0,1,2,3,4,5.
I'd write it like this:
while not rsUpdate.EOF do
rsUpdate.fields(TargetFieldName) = value
rsUpdate.MoveNext
wend
Try this also:
If reUpdate.EOF Then
Exit Sub
End If

Resources