I'm a Technical Writer going through our application's documentation and I came across some issues trying to get some existing Cypress Enable code snippets to work.
We have a stripped-down version of the VBA editor and compiler in our application. When I try to run a couple of programs using some of the statements, I never get the results I'm expecting, or nothing happens.
For example, when I run this script to test the Declare statement, instead of getting a dialog, nothing happens:
Declare Function GetFocus Lib "User32" () As Integer
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (Byval hwnd As Long, Byval lpstring As String, Byval lpstrlen As Long)
Sub Main
Dim hWindow%
Dim str1 As String *51
Dim str2 As String *25
hWindow% = GetFocus()
Print "GetWindowText returned: " & GetWindowText( hWindow%, str1, 51)
Print "GetWindowText2 returned: " & GetWindowText( hWindow%, str2, 25)
Print str1
Print str2
End Sub
For the first print statement (Print str1), I'm expecting a MessageBox with: Title = "Enable Scripting Language Editor" Body text = "GetWindowText returned: 50" A single OK button.
With this code to test the DlgFocus statement, no matter which of the OK/Cancel controls I click, the dialog just shuts down:
Sub Main()
Dim ListBox1$()
Begin Dialog UserDialog ,,112,74,"Untitled",.DlgProc
TextBox 12,20,88,12,.TextBox1
OKButton 12,44,40,14
CancelButton 60,44,40,14
Text 12,11,88,8,"Enter Desired Salary:",.Text1
End Dialog
Dim d As UserDialog
Dialog d
End Sub
Function DlgProc(ControlName$,Action%,SuppValue%) As Integer
If Action% = 2 and ControlName$ = "OK" Then
If IsNumeric(DlgText$("TextBox1")) Then
Msgbox "Duly Noted."
Else
Msgbox "Sorry, you must enter a number."
DlgFocus "TextBox1"
DlgProc = 1
End If
End If
End Function
In this version to test the DlgFocus statement, no matter which control I click, the value returned is always zero:
Sub Main
Begin Dialog UserDialog 200,120,"Script #9",.DialogFunc
Text 10,10,180,15,"Please push the OK button"
TextBox 10,40,180,15,.Text
OKButton 30,90,60,20
PushButton 110,90,60,20,"&Hello"
End Dialog
Dim dlg As UserDialog
Print Dialog(dlg)
MsgBox "Dialog info: " & Dialog(dlg)
End Sub
Function DialogFunc%(DlgItem$, Action%, SuppValue%)
Print "Action=";Action%
Select Case Action%
Case 1 ' Dialog box initialization
Beep
Case 2 ' Value changing Or button pressed
If DlgItem$ = "Hello" Then
MsgBox "Hello"
DialogFunc% = True 'Do Not Exit the Dialog
End If
Case 4 ' Focus changed
Print "DlgFocus=""";DlgFocus();""""
MsgBox "DlgFocus info: " & DlgFocus() & """"
End Select
End Function
Any help is greatly appreciated.