MS Access VBA Dynamically Show Pics From URL - vba

I found this code from here:
Show Pictures Directly From URLs in Access Forms and Reports
I have this code on my form:
Public Function PeopleImage()
'FUNCTION TO SET THE IMGPEOPLEPIC WITH THE CURRENT PERSON'S PHOTO, IF THE PHOTO CAN BE FOUND. OTHERWISE A STOCK IMAGE SAYING NO PIC FOUND WILL SHOW
Dim PeoplePic As String
Dim NoPeoplePic As String
Dim ImgDwnld As String
PeoplePic = "https://TheWebAddress.com/People%20Photos/" & Nz(Me.PersonID, 0) & ".jpg"
ImgDwnld = "\\AppServer\AppDir\Storage\Images\" & Nz(Me.PersonID, 0) & ".jpg"
DownloadFile PeoplePic, ImgDwnld, False
NoPeoplePic = "\\AppServer\AppDir\Storage\NoPeoplePic.jpg"
If FileExists(ImgDwnld) Then
Me.ImgPeoplePic.Picture = ImgDwnld
Else
Me.ImgPeoplePic.Picture = NoPeoplePic
End If
Me.ImgPeoplePic.Requery
End Function
When I added the image control ImgPeoplePic I set it to the NoPeoplePic, so that a picture would be set. Now, when I load the form and navigate, it looks like the photo is reloading (it blinks), but it just keeps showing the stock NoPeoplePic.
Anyone know what I'm missing? I feel like I'm so close. I just don't understand what it's not putting in the image that it downloads. I verified that the image downloads to the directory, and that it is there. I debug the path and image and it pulls up with no problem.
Any help is appreciated!

Related

Slow speed of VBA command (Application.FollowHyperlink) in a local network

I am using a MS Access application in local network, this application have form for display data, and one of the features in the form is opening picture files regarding the data in the form. My issue is opening the pictures are very slow for the Front End users (1 to 5 seconds). This is my function for the opening photos:
Public Sub OpenPicture(PictureName As Variant)
If PictureName <> "" Then
DoCmd.SetWarnings False
Dim iPath , filePath As String
iPath = "C:\photo\"
filePath = iPath & PictureName
Application.FollowHyperlink filePath
DoCmd.Requery
DoCmd.SetWarnings True
End If
End Sub
In the above code, PictureName is the name of the image in the DataForm. I should mention there are Image controls for showing pictures in the DataForm, but these controls are small. My purpose is to crop or rotate these pictures in case of need in other programs.
Also I have a lot of image files (more than 200000) in the image source folder.
Please help me for improving the speed of this function.
Thanks in advance.

Weird behavior of powercfg.exe when I execute it programatically

To programtically set display brightness I had two options :
Use PowerWriteACValueIndex and PowerWriteDCValueIndex API
Use PowerCfg.exe
Now, I tried both, and both gave me the same (weird) result. Here's the code I'm using :
With psiInfo
.FileName = "powercfg"
.UseShellExecute = True
.WindowStyle = ProcessWindowStyle.Hidden
.Arguments = "-setacvalueindex " & guidCurScheme.ToString() & " " & SUBGROUP_GUID.GUID_VIDEO_SUBGROUP & " " & SETTING_GUID.GUID_DISPBRIGHTNESS & " " & psValue.ValueAC
End With
pProc = Process.Start(psiInfo)
Where :
Public Const GUID_VIDEO_SUBGROUP As String = "7516b95f-f776-4464-8c53-06167f40cc99"
Public Const GUID_DISPBRIGHTNESS As String = "aded5e82-b909-4619-9949-f5d71dac0bcb"
Public Structure POWERSETTING
Public ValueAC As String
Public ValueDC As String
End Structure
Dim psValue As POWERSETTING
And guidCurScheme is the GUID of the active power scheme, as returned by PowerGetActiveScheme API function. I do the samething for DC part, with "-setdcvalueindex".
Now the weird behavior is as follow :
If I call this code in a button click handler event, it will set these values, but not the "general" screen brightness slider (and for that matter, the display brightness). (somebody edits the pictures links inside the post please)
If I the user clicks the button a second time, it will only then apply the setting.
If i put the code in a loop for it to run twice when the user click the button, it will still behave as in (1)
If I try to run the same command but manually from command-line, it will run work just fine.
This is totally unexpected, I don't know what I'm doing wrong. It gives the exact same result when I use the PowerWriteACValueIndex and PowerWriteDCValueIndex functions from Windows API.
maybe double-check the syntax of your argument by letting the app copy the string to clipboard. Sometimes just a tiny typo ruins it for me.
Also i'd check if the application that gets called is the one from syswow or from system32 (that depends on how you compile your app)
You can also check the exitcode or look at the error-output you get.
The error-output can be captured like this:
Dim so As System.IO.StreamReader
Dim se As System.IO.StreamReader
se = myproc.StandardError
so = myproc.StandardOutput
myproc.WaitForExit()
MsgBox(so.ReadToEnd & vbcrlf & se.ReadToEnd)

How to save data to text file and retrieve

I'm using VB.NET. I am able to load the pics from a folder into a flowlayoutpanel. And then load the clicked picture into a separate picturebox and display the picture's filepath in a label.
Now I want to be able to add rating and description to each of the image in the flowlayoutpanel and save it to a text file in the folder from which the pictures have been loaded. The app should load be able to load the rating and description on the next launch or when the selected image is changed. How do I accomplish this?
You should probably look at accessing the metadata of the pic. This way the info you want is carried with the pic. This is contained in the PropertyItems Class, which is a property of the Image class
Here's a link to an answered question about adding a comment to a jpg. Hope this helps.
Here's an untested conversion of that code in VB.net. You'll probably have to add a reference or 2 and import a couple of namespaces, but syntactically this is correct as near as I can tell.
Public Function SetImageComment(input As Image, comment As String) As Image
Using memStream As New IO.MemoryStream()
input.Save(memStream, Imaging.ImageFormat.Jpeg)
memStream.Position = 0
Dim decoder As New JpegBitmapDecoder(memStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad)
Dim metadata As BitmapMetadata
If decoder.Metadata Is Nothing Then
metadata = New BitmapMetadata("jpg")
Else
metadata = decoder.Metadata
End If
metadata.Comment = comment
Dim bitmapFrame = decoder.Frames(0)
Dim encoder As BitmapEncoder = New JpegBitmapEncoder()
encoder.Frames.Add(bitmapFrame.Create(bitmapFrame, bitmapFrame.Thumbnail, metadata, bitmapFrame.ColorContexts))
Dim imageStream As New IO.MemoryStream
encoder.Save(imageStream)
imageStream.Position = 0
input.Dispose()
input = Nothing
Return Image.FromStream(imageStream)
End Using
End Function

How do I search through a string for a particular hyperlink in Visualbasic.net?

I have a written a program which downloads a webpage's source but now I want to search the source for a particular link I know the link is written like this:
<b>Geographical Survey Work</b>
Is there anyway of using "Geographical Survey Work" as criteria to retrieve the link? The code I am using to download the source to a string is this:
Dim sourcecode As String = ((New Net.WebClient).DownloadString("http://examplesite.com"))
So just to clarify I want to type into an input box "Geographical Survey Work" for instance and "/internet/A2" to popup in a messagebox? I think it can be done using a regex, but that's a bit beyond me. Any help would be great.
With HTMLAgilityPack:
Dim vsPageHTML As String = "<html>... your webpage HTML code ...</html>"
Dim voHTMLDoc.LoadHtml(vsPageHTML) : vsPageHTML = ""
Dim vsURI As String = ""
Dim voNodes As HtmlAgilityPack.HtmlNodeCollection = voHTMLDoc.SelectNodes("//a[#href]")
If Not IsNothing(voNodes) Then
For Each voNode As HtmlAgilityPack.HtmlNode In voNodes
If voNode.innerHTML.toLower() = "<b>geographical survey work</b>" Then
vsURI = voNode.GetAttributeValue("href", "")
Exit For
End If
Next
End If
voNodes = Nothing : voHTMLDoc = Nothing
Do whatever you want with vsURI.
You might need to tweak the code a bit as I'm writing free-hand.

How do you load an image from resource file in vb 2010 expresss?

First of all Im new to vb 2010 and so far have enjoyed what I have been able to do with it. That being said I have run into an issue with my current project.
Basically I have created a timer and all works well on that part. My issue lies in that my timer loads a .png for each minute/second and I was linking the images like so:
Picturebox1.Image = Image.Fromfile("C:\timer\images\" & minutes.text & ".png")
Picturebox2.Image = Image.Fromfile("C:\timer\images\" & seconds.text & ".png")
So running this on another pc rendered that bit of code useless as that computer did not have those files locally and the program would end in an error as it could not find the .png files.
I did a bit of searching online and found a few sites and video tutorials how to read from the resource file. But in doing so I have been unable to make it function properly.
So this is what I found here:
Picturebox1.image = My.Resources.minutes.text
Picturebox2.image = My.Resources.seconds.text
I know this bit of code is wrong as I'm now getting 2 errors in vb 2010. The only way I have managed to make this work is to specify the file name. But what I'm wanting to do is use whats in "minutes.text" and "seconds.text" to specify the file name.
Is there a way around this? or do I have to use a bunch of if statements to do this?
example:
If minutes.text = 1 Then
picturebox1 = My.Resource._1
End If
If seconds.text = 12 Then
Picturebox2 = My.Resource._12
End If
I would hate having to do a bunch of if statements if there is a simple fix. So I've come here for help.
i think you are looking for this:
Dim currentMin as string = "_" & minutes.text ' it would look something like this: _1
picturebox1.Image = CType(My.Resources.ResourceManager.GetObject(currentMin), Image)
Dim currentSec as string = "_" & seconds.text
picturebox2.Image = CType(My.Resources.ResourceManager.GetObject(currentSec), Image)
I have tried this form, and it is functional
Picturebox1.Image = Image.FromHbitmap(My.Resources.imagename.GetHbitmap())