Control Shell.Explorer.2 with google maps issue in VFP - visual-foxpro

I have a form in VFP9 that shows a map in a control Shell.Explorer.2. In previous Google API the form works fine, but now the control doesn't show the page, and an Script Error appears:
The page is a simple marker from
https://developers.google.com/maps/documentation/javascript/examples/marker-simple?hl=es
Inside of the VFP form I have a TEXT ENDTEXT block, in order to create a temporal webpage(MyHtml.htm) that is shown in the control.
The error indicate the follows lines as error:
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MY-GOOGLE-API-KEY&callback=initMap">
</script>
If I display the page in IExplorer 11, Firefox, Chrome, Edge, works fine, but with the control Shell.Explorer.2 I get an error and the control doesn't show the map. If I remove the Script, the control doesn't show the map.
Is this type of script no longer supported in shell.explorer.2?
Any documentation or help?

Unfortunately you have provided only partial code to talk upon. This sample code, which was written as an answer to a question on Foxite works well and use Shell.Explorer:
Local lcCoordinates, lat, lon, lcUrl
lcCoordinates = [14 ° 53'38.5 "N, 24 ° 30'31.0" W]
Alines(laParts, m.lcCoordinates, 1+4, '°',"'",'"' ,' ')
lat = Str((Val(laParts[1]) + Val(laParts[2])/60 + Val(laParts[3])/3600) * Iif(laParts[4] = 'N',1,-1),9,6)
lon = Str((Val(laParts[5]) + Val(laParts[6])/60 + Val(laParts[7])/3600) * Iif(laParts[8] = 'E',1,-1),9,6)
lcUrl = Textmerge("https://www.google.com/maps/#<< m.lat >>,<< m.lon >>,11z")
ShowMap(m.lcUrl)
Procedure ShowMap(tcUrl)
Public oForm
oForm = Createobject('form1')
oForm.Show()
oForm.HTMLViewer.Navigate2(m.tcUrl)
Endproc
Function GetHTML
Local myVar
TEXT to myVar noshow
ENDTEXT
Return myVar
Endfunc
Define Class HTMLViewer As OleControl
OleClass = 'Shell.Explorer'
Procedure Refresh
Nodefault
Endproc
Procedure LoadHTML(tcHTML)
With This
.Navigate2("about:blank")
.Document.Write(m.tcHTML)
Endwith
Enddefine
Define Class form1 As Form
Height = 600
Width = 800
Caption = "HTML sample"
Add Object HTMLViewer As HTMLViewer With ;
Top = 10, ;
Left = 10, ;
Height = 580, ;
Width = 780, ;
Anchor = 15,;
Visible = .T., ;
Name = "HTMLViewer"
Procedure Init
Lparameters tcHTML
If !Empty(m.tcHTML)
With Thisform.HTMLViewer
.LoadHTML(m.tcHTML)
Endwith
Endif
Endproc
Procedure HTMLViewer.NavigateError
Lparameters pdisp, url, frame, statuscode, Cancel
Set Step On
Cancel = .T.
Endproc
Procedure HTMLViewer.BeforeNavigate2
Lparameters pdisp, url, Flags, targetframename, postdata, headers, Cancel
Cancel = .T. && prevents actual navigation
Endproc
Procedure HTMLViewer.Refresh
Nodefault
Endproc
Enddefine

Related

Show multiple buttons in Data grid view

I needed to add two buttons inside a single column in data grid view in Visual Foxpro, , but only one active appears in the column.
the two buttons could be shown in each cell of that column.
Is it possible to show both buttons?
I needed to add two buttons inside a single column in data grid [...] Is it possible to show both buttons?
Yes, you can put a Container object into the Grid.Column and put two Buttons into the Container. Minimal, Reproducible Example:
LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN
DEFINE CLASS TestForm as Form
AutoCenter = .T.
PROCEDURE Load
LOCAL i
CREATE CURSOR temp (test Int)
FOR i = 1 TO 10
INSERT INTO temp VALUES (i)
ENDFOR
GO TOP
ENDPROC
ADD OBJECT Grid1 as Grid WITH ;
RecordSource = 'temp', ColumnCount = 1, RowHeight = 30
PROCEDURE Grid1.Init()
WITH This.Column1
.Width = 200
.AddObject('Container1','TestContainer')
.Container1.Visible = .T.
.CurrentControl = 'Container1'
.Sparse = .F.
ENDWITH
ENDPROC
ENDDEFINE
DEFINE CLASS TestContainer as Container
Width = 200
Height = 27
ADD OBJECT Button1 as CommandButton WITH ;
Height = 24, Caption = "Button1"
PROCEDURE Button1.Click
MESSAGEBOX(This.Caption)
ENDPROC
ADD OBJECT Button2 as CommandButton WITH ;
Height = 24, Left = 100, Caption = "Button2"
PROCEDURE Button2.Click
MESSAGEBOX(This.Caption)
ENDPROC
ENDDEFINE

Call a function in MATLAB GUIDE gui

I have a script called 'main.m' that basically takes the paths where I've saved all my images and insert them in arrays. It saves the images name in a .dat file and call a function named 'selectFolder.m'.
I posted all the script and functions under, my request is at the bottom.
%% Folders
imgFolder = './1.Dataset/';
functFolder = './2.Functions/' ;
%resFolder = './3.Results/';
%% Add path
addpath(genpath(imgFolder));
addpath(genpath(functFolder));
%% Listing Folders where my images are at
myFolder1 = '../Always'; %folder path
[..] %12 folders in total
myFolder12 = '../Random'; %folder path
%% Distinguish folder 'Always' & 'Random'
% Always Folders: subset of images for all users
mfA = {myFolder1, myFolder3, myFolder5, myFolder7, myFolder9, myFolder11};
dimA = length(mfA);
% Random Folders: subset of images randomly showed
mfR = {myFolder2, myFolder4, myFolder6, myFolder8, myFolder10, myFolder12};
dimR = length(mfR);
% check if folders are present
for i = 1:dimA
if ~isdir(mfA{i})
errorMessage = sprintf('Error: The following folder does not exist:\n%s', mfA{i});
uiwait(warndlg(errorMessage));
return;
end
end
for j = 1:dimR
if ~isdir(mfR{j})
errorMessage = sprintf('Error: The following folder does not exist:\n%s', mfR{j});
uiwait(warndlg(errorMessage));
return;
end
end
%% Take images and insert'em in Arrays
% Always
MyImgs1 = dir(fullfile(mfA{1}, '*.jpg'));
[..] %for every cell
MyImgs6 = dir(fullfile(mfA{6}, '*.jpg'));
% Random
MyImgs1r = dir(fullfile(mfR{1}, '*.jpg'));
[..] %for every cell
MyImgs6r = dir(fullfile(mfR{6}, '*.jpg'));
% create arrays with images names
Array_mfA = {MyImgs1.name, MyImgs2.name, MyImgs3.name, MyImgs4.name, MyImgs5.name, MyImgs6.name};
Array_mfR = {MyImgs1r.name, MyImgs2r.name, MyImgs3r.name, MyImgs4r.name, MyImgs5r.name, MyImgs6r.name};
%% Print content of array on file
fileIDA = fopen('2.Functions/Array_Always.dat','w');
formatSpec = '%s,';
nrows = length(Array_mfA);
for row = 1 : nrows
fprintf(fileIDA, formatSpec, Array_mfA{row});
end
fclose(fileIDA);
fileIDR = fopen('2.Functions/Array_Random.dat','w');
formatSpec = '%s,';
nrows = length(Array_mfR);
for row = 1 : nrows
fprintf(fileIDR, formatSpec, Array_mfR{row});
end
fclose(fileIDR);
%disclaimer
nrc = 1;
file = fopen('2.Functions/disclaimer.dat', 'w');
fprintf(file, '%d', nrc);
fclose(file);
%% call function
selectFolder(mfA, mfR);
This function takes two array as input, these array contains all the names of my images sorted. It does some operation and then it calls another function 'selectImage.m' that displays fullscreen the selected image.
function [] = selectFolder(mfA, mfR)
clc
%% Open Arrays from file
% Always
fileID = fopen('2.Functions/Array_Always.dat', 'rt');
Array_A = textscan(fileID,'%s', 'Delimiter', ',');
fclose(fileID);
% Random
fileID2 = fopen('2.Functions/Array_Random.dat', 'rt');
Array_R = textscan(fileID2,'%s', 'Delimiter', ',');
fclose(fileID2);
%% Show Disclaimer
file = fopen('2.Functions/disclaimer.dat', 'r');
dis = fscanf(file, '%d');
fclose(file);
if (dis == 1)
set(gcf,'Toolbar','none','Menubar','none', 'NumberTitle','off');
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
hAx = gca;
set(hAx,'Unit','normalized','Position',[0 0 1 1]);
imshow('1.Dataset/Disclaimer/DIS.jpg');
drawnow;
nrc = 0;
file = fopen('2.Functions/disclaimer.dat', 'w');
fprintf(file, '%d', nrc);
fclose(file);
return;
end
%% select random folder from 'Array_A' aka Always Array
dimA = length(mfA);
if ~isempty(Array_A{1})
rndn = randperm(dimA, 1);
A_check = Array_A;
while isequal(A_check,Array_A)
Array_A = selectImage(mfA{rndn}, Array_A);
if isequal(A_check,Array_A)
rndn = randperm(dimA, 1);
end
end
fileIDA = fopen('2.Functions/Array_Always.dat','w');
formatSpec = '%s,';
nrows = cellfun('length', Array_A);
for row = 1 : nrows
fprintf(fileIDA, formatSpec, Array_A{1}{row});
end
fclose(fileIDA);
return;
end
%% select random folder from 'Array_R' aka Random Array
if ~isempty(Array_R{1})
dimR = length(mfR);
rndnr = randperm(dimR, 1);
R_check = Array_R;
while isequal(R_check,Array_R)
Array_R = selectImage(mfR{rndnr}, Array_R);
if isequal(R_check, Array_R)
rndnr = randperm(dimR, 1);
end
end
fileIDR = fopen('2.Functions/Array_Random.dat','w');
formatSpec = '%s,';
nrows = cellfun('length', Array_R);
for row = 1 : nrows
fprintf(fileIDR, formatSpec, Array_R{1}{row});
end
fclose(fileIDR);
end
end
selectImage:
function [ Array ] = selectImage( myFolder, Array )
%% Check
MyImgs = dir(fullfile(myFolder, '*.jpg'));
dim = length(MyImgs);
n = 0;
for i = 1 : dim
MyImgs(i).name
if ~any(strcmp(Array{1}, MyImgs(i).name))
disp(MyImgs(i).name);disp('not present in ');disp(myFolder);
n = n + 1;
end
end
if (n == dim)
disp('empty folder')
return;
end
rN = randperm(dim, 1);
baseFileName = MyImgs(rN).name;
while ~any(strcmp(Array{1}, baseFileName))
fprintf(1, 'not present %s\n', baseFileName);
rN = randperm(dim, 1);
baseFileName = MyImgs(rN).name;
end
%% Dispay image
dim = cellfun('length', Array);
for i = 1 : dim
if strcmp(baseFileName, Array{1}(i))
Array{1}(i) = [];
break
end
end
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
set(gcf,'Toolbar','none','Menubar','none', 'NumberTitle','off');
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
hAx = gca;
set(hAx,'Unit','normalized','Position',[0 0 1 1]);
imshow(imageArray); % Display image.
drawnow;
end
Now I have to integrate these functions in my gui. What I want to do is call the 'main.m' script just one time with a button like 'Let's Start' and with that will show the disclaimer.
Then repeat the process calling only the 'Next' button, which calls 'selectFolder.m' and display the images with the procedure described above.
Is it possibile to do it this way? I mean, how can I pass the variable 'mfA' and 'mfR' to selectFolder? Is there a better and simpler way to do it?
The code in the gui is like:
-main:
% --- Executes on button press in Start.
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
figure
main
-selectFolder:
function Next_Callback(hObject, eventdata, handles)
% hObject handle to Next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes1);
figure %show the image in another window
selectFolder(mfA, mfR)
An easy way to share variables among the callback of a GUI is to use the
guidata function.
With respect to your specific variables mfA and mfR you can use guidata
to store them, this way: in the callback in which you generate the variables you want to share with other callback you can insert the following code:
% Get the GUI data
my_guidata=guidata(gcf);
%
% section of your code in which you create the mfA and mfR vars
%
% Store the variables to be shared among the callbacks in the guidata
my_guidata.mfA=mfA;
my_guidata.mfR=mfR;
% Save the updated GUI data
guidata(gcf,my_guidata);
In the callback in which you wnat to retreive the data, you can insert the
following code:
% Get the GUI data
my_guidata=guidata(gcf);
% Retrieve the data from the GUI data structure
mfA=my_guidata.mfA;
mfR=my_guidata.mfR;
In both the examples, the struct my_guidata holds the handles of the GUI and the additional varaibles you have defined.
With respect to the the architecture of the GUI, there are lots of possibilities.
Firt a comment: looking at the two callback you've posted at the bottom of your question, it seems that your GUI has, at least, one axes, nevertheless, you create, in both of them a new figure so it is not clear the role of that axes
Considering now your questions
What I want to do is call the 'main.m' script just one time with a button like 'Let's Start' and with that will show the disclaimer. Then repeat the process calling only the 'Next' button, which calls 'selectFolder.m' and display the images with the procedure described above
call the 'main.m' script just one time with a button like 'Let's Start' and with that will show the disclaimer
You have just to copy the relevant code of your main in the Start pushbutton callback.
Notice that the code which shows the disclaimer is actually in your selectFolder function, so you have to move it in the
Start callback.
Then repeat the process calling only the 'Next' button, which calls 'selectFolder.m' and display the images with the procedure described above
to do this, you have to remove the call to selectFolder from the main and move the body of your in the Next pushbotton callback.
Also you can copy the selectImage in the GUI .m file.
Hope this helps.
Qapla'

Different color for sorting in SSRS

I have a customer who would like some color formatting in an SSRS report. I cannot utilize grouping due to the customer requirements. I have the report sorting by Main Tank and would like the sorts to alternate in color. So it would have several rows of Tank A all be grey then several rows of Tank B all be white. I'm using this currently but it only works on the first row of each sort
=iif(
Fields!Tank.Value=previous(Fields!Tank.Value),
"Transparent",
"Red"
)
Any help would be great.
You can use custom code to get the required logic. Using a custom function in your code that returns the color based on the the Tank value.
Go to Report menu, Report Properties / Code tab and in the text area put this code:
Dim prevColor As String = "Transparent"
Public Function GetColor(ByVal flag As Integer) As String
If flag = 1 Then
If prevColor = "Transparent" Then
prevColor = "Gray"
Else
prevColor = "Transparent"
End If
End If
Return prevColor
End Function
Now in the cell background-color property use this expression:
=Code.GetColor(iif(Fields!Tank.Value=previous(Fields!Tank.Value),0,1))
It will color the background as below:
UPDATE: The above logic colors correctly only the first, third, fifth columns and so on. It is caused by multiple calls to the GetColor function and overwritting of the global variable prevColor.
I managed to solve that issue by passing the row number to the function. This is the updated function:
Dim prevColor As String = "Transparent"
Dim rowNum As Integer = 0
Public Function GetColor(ByVal flag As Integer, ByVal nRow As Integer) As String
If flag = 1 And rowNum <> nRow Then
If prevColor = "Transparent" Then
prevColor = "Gray"
Else
prevColor = "Transparent"
End If
End If
rowNum = nRow
Return prevColor
End Function
Note the function receives a new argument so the expression for calling has changed:
=Code.GetColor(iif(Fields!Tank.Value=previous(Fields!Tank.Value),0,1),
RowNumber("DataSet3"))
Replace "DataSet3" by the actual name of your dataset.
It should generate the following tablix:
Let me know if this helps.
I would handle this in your query by adding a column that returns a 0 or 1 to define the color - idea sketch: use rank to get numbers that correlate to the sort order and then use MOD 2 to get a 0 or 1. If you post a sample query, we can help figure out the specifics.

Event Handlers for Dynamic Table Layout Panel in Visual Basic

I am making a risk-type game for school that dynamically creates a 4x4 grid of buttons inside a table layout panel in visual basic. I have successfully created the panel and buttons with names that correspond to the row and column of the button. There are also two parallel arrays - one for button owner and the other for button number - that correspond to the owner of the button and the number of "armies" in the button. My issue is that when the user clicks a certain button, I need to reference the button name/value to know how many "armies" the button has to control the "attack" portion of the player's turn.
The following code creates the table layout panel and the buttons with names.
'Create table Dynamically
Dim ColCount As Integer = 4
Dim RowCount As Integer = 4
Dim f As New System.Drawing.Font("Arial", 15)
riskTable.AutoScroll = True
riskTable.Dock = DockStyle.Fill
riskTable.ColumnCount = ColCount
riskTable.RowCount = RowCount
For rowNo As Integer = 0 To riskTable.RowCount - 1
For columnNo As Integer = 0 To riskTable.ColumnCount - 1
Dim buttonname As String
buttonname = "B" & rowNo & columnNo
Dim button As Control = New Button
button.Size = New Size(179, 100)
button.Name = buttonname
button.Text = "1"
button.ForeColor = Color.White
button.Font = f
AddHandler button.Click, AddressOf buttonname_Click
riskTable.Controls.Add(button, columnNo, rowNo)
Next
Next
Me.Controls.Add(riskTable)
This is the dynamic event handler that I created. I tried using 'Me.Click' to get the name of the button, but it only returns the name of the form. I need to have code in here that references the name of the currently clicked button to then in turn reference the box owner and box number arrays.
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
MessageBox.Show(Me.Name)
End Sub
Any help would be greatly appreciated! I think that once I get this working, the rest of the game will be pretty simple to figure out.
Thanks!
Put the name in 'button.Tag' instead/also:
button.Tag = buttonname
Then it is easy to get the name with:
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim result As String = CType(CType(sender, System.Windows.Forms.Button).Tag, String)
End Sub
(Check the System.Windows.Forms.Button though, might need some tweak to match your buttons inside the table. riskTable.Controls.button ?)

View Datagridview in Print Preview Window

I am creating an application in vb.net. I have a datagridview control in my VB form. I need to view it on printpreview window with the contents in it. I have other control like labels and textboxes in the form and I can view all in printpreview. In the case of Datagridview control, I have a working printpreview code which I got from net. My problem is, I need to change the x and y positions of datagridview control. With the following code, the datagridview control is displaying over the other controls. I dont know how to do it in this code. Please help me.
I need to change the x and y positions of DataGridView like given in the below code(50 and 225).
e.Graphics.DrawString(Label7.Text, Label7.Font, Brushes.Black, 50, 225)
The code I used to display gridview is given below.
Code :
Dim ColumnCount As Integer = DataGridView1.ColumnCount
Dim RowCount As Integer = DataGridView1.RowCount
Dim CellTopPos As Integer = PrintDocument1.PrinterSettings.DefaultPageSettings.Margins.Top
For Row = 0 To RowCount - 2
Dim CellLeftPos As Integer = PrintDocument1.PrinterSettings.DefaultPageSettings.Margins.Left
For Cell = 0 To ColumnCount - 1
Dim CellValue As String = DataGridView1.Rows(Row).Cells(Cell).Value.ToString()
Dim CellWidth = DataGridView1.Rows(Row).Cells(Cell).Size.Width + 10
Dim CellHeight = DataGridView1.Rows(Row).Cells(Cell).Size.Height
Dim Brush As New SolidBrush(Color.Black)
e.Graphics.DrawString(CellValue, New Font("arial", 9), Brush, CellLeftPos, CellTopPos)
e.Graphics.DrawRectangle(Pens.Black, CellLeftPos, CellTopPos, CellWidth, CellHeight)
CellLeftPos += CellWidth
Next
CellTopPos += DataGridView1.Rows(Row).Cells(0).Size.Height
Next
Use this class .. unfortunately there is characters limit so i can not able to post code
http://www.codeproject.com/Articles/18042/Another-DataGridView-Printer

Resources